LoginSignup
31
29

More than 5 years have passed since last update.

upstartでデーモン化してみる

Last updated at Posted at 2013-12-29

デーモン化するのにdeamontoolsを使っていたが、設定が簡単そうなupstartを使ってみる

特徴

  • タスクとサービスはイベントによって起動・停止される
  • イベントは、タスクやサービスを起動・停止する時に生成される
  • イベントは、システム上の他のプロセスから受ける
  • サービスは、予期せずプロセスが死んだ時に再起動される
  • 親プロセスと別の監視と再起動デーモン
  • D-Busを超えてinit deamonで通信
  • ユーザがプロセスを起動・停止できる

対応環境

  • Ubuntu 6.10 以降
  • Red Hat Enterprise Linux 6 以降
  • Fedora 9 ~ 14
  • Debian 6.0(Squeeze) 以降
  • Maemo
  • WebOS
  • Chromium OS
  • Chrome OS

設定

/etc/init/upstart-sample.conf
# nginx

description "nginx http daemon"
author “my@localhost.com”

start on runlevel [2345]
stop  on runlevel [!2345]

env DAEMON=/opt/nginx-x.x.x/sbin/nginx
env PID=/var/run/nginx.pid
env CONFIG=/etc/nginx/nginx.conf

respawn

pre-start script
  ${DAEMON} -t
  if [ $? -ne 0 ]; then
    exit $?
  fi
end script

console output

exec ${DAEMON} -c "${CONFIG}"

コマンド

起動

# sudo initctl start nginx

確認

# sudo initctl list|grep nginx
or
# sudo ps auxwwf|grep nginx

停止

# sudo initctl stop nginx

再起動

# sudo initctl restart nginx

まとめ

deamontoolsよりもディレクトリを作ったり設定ファイルが少なくて導入が楽かも

31
29
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
31
29