友链
导航
These are the good times in your life,
so put on a smile and it'll be alright
友链
导航
Upstart is an event-based replacement for the /sbin/init daemon which handles:
Upstart 里, stanza 1) == 配置.
一个基础的 upstart 配置如下:
$ cat /etc/init/cron.conf # cron - regular background program processing daemon # # cron is a standard UNIX program that runs user-specified programs at # periodic scheduled times description "regular background program processing daemon" # 最普通的启动/关闭事件 start on runlevel [2345] stop on runlevel [!2345] # 文档后面有详述 expect fork # 异常退出后会重启 respawn # 启动的命令 exec cron ############################# EOF ############################# # ps 可看出进程在运行 $ ps aux |grep cron root 825 0.0 0.0 21328 404 ? Ss Apr01 0:05 cron # upstart 也有 status 和 initctl list 可查看 service 的状态 $ status cron cron start/running, process 825 $ initctl list | grep cron cron start/running, process 825
一些关键的配置如下.
如果要 使用不同配置开启一个服务的多个实例 (instance), 可如下操作 (例子为统一管理 node 相关的服务):
description 'node upstart script' author 'iain' start on (local-filesystems and net-device-up) stop on shutdown instance "Node - $NAME" respawn respawn limit 5 60 script . /etc/node/$NAME.conf exec sudo -u node NODE_ENV=${NODE_ENV} /usr/bin/n use ${NODE_VERSION} ${NODE_PATH} >> ${LOG_PATH} 2>&1 end script
NODE_VERSION="0.6.5" NODE_PATH="/var/application/test/app.js" LOG_PATH="/var/log/node/test.log" NODE_ENV="production"
$ sudo start node NAME=foo
description 'Start all node instances at boot' author 'iain' start on (local-filesystems and net-device-up) task script for file in `ls /etc/node/*.conf` ; do filename=`basename ${file%.*}` start node NAME=$filename done end script
/etc/node/
下有 conf, 服务器启动时就能由 task 按该 conf 启动服务