LoginSignup
3
3

More than 5 years have passed since last update.

自分でインストールしたアプリケーションを/etc/init.d/ に登録して service 起動する

Last updated at Posted at 2016-07-14

自分でインストールしたアプリケーションを/etc/init.d/ に登録して service 起動する

常時起動のアプリケーションをHTTPDやMYSQLみたいに起動するスクリプトがつくれるガイドライン

  • service.sh を参考に起動するプログラムの場所やログファイルを書き込む
  • start() stop() などの関数部分が service start|stop で呼ばれるところなので、適宜変更可能

  • アプリケーション起動するシェルとして設置(上記のservice.sh をリネーム)

/etc/init.d/<サービス名>

  • 実行権限を与えておく(chmod +x)

指定した場所にPIDファイル作って、常駐して指定した場所にログを出力し、終了時にPIDみてkillしてくれるというサービスアプリケーションとして動かせるってワケ。
serviceやchkconfig のシステムコマンドで扱えるようになる

もしくは次の手順で"new-service.sh"にやってもらう(OSによっては動かないことも)

wget 'https://raw.github.com/gist/4275302/new-service.sh'

sudo bash new-service.sh

サービス名を聞いてくれるのでいくつかの質問に応える

<NAME> = $YOUR_SERVICE_NAME

  • service 登録したい名前 httpd みたいなもの

<DESCRIPTION> = Describe your service here (be concise)

  • 配慮深き説明

<COMMAND> = Command to start your server (for example /home/myuser/.dropbox-dist/dropboxd)

  • アプリケーションを起動するコマンド

<USER> = Login of the system user the script should be run as (for example myuser)

  • mysql みたいな実行するユーザー名 そのアプリケーションが出力したりするところにちゃんと権限があること

実行したら /etc/init.d に service.sh を設定したファイルを置いてくれる

これでserviceコマンドで起動、停止できる

service $YOUR_SERVICE_NAME start
service $YOUR_SERVICE_NAME stop

bootのときに自動起動登録(それぞれのOSの環境もあると思うので適宜)

update-rc.d $YOUR_SERVICE_NAME defaults

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3