這邊先貼幾個基本的,在etherpad及wisemapping建置的時候使用的conf來看一下
/etc/init/etherpad.conf
description "etherpad"
#start on started networking
start on started mysql
stop on runlevel [!2345]
env EPHOME=/home/etherpad/etherpad-lite
env EPLOGS=/var/log/etherpad-lite
env EPUSER=etherpad
respawn
pre-start script
cd $EPHOME
mkdir $EPLOGS ||true
chown $EPUSER:admin $EPLOGS ||true
chmod 0755 $EPLOGS ||true
chown -R $EPUSER:admin $EPHOME/var ||true
$EPHOME/bin/installDeps.sh >> $EPLOGS/error.log || { stop; exit 1; }
end script
script
cd $EPHOME/
exec su -s /bin/sh -c 'exec "$0" "$@"' $EPUSER -- node node_modules/ep_etherpad-lite/node/server.js
>> $EPLOGS/access.log
2>> $EPLOGS/error.log
end script
/etc/init/wisemapping.conf
description "Wisemapping Service"
author "cowman"
start on started mysql
stop on runlevel [!2345]
env WHOME=/wisemapping
env WLOGS=/var/log/wisemapping
expect fork
pre-start script
chdir $WHOME
mkdir $WLOGS ||true
end script
respawn
script
chdir $WHOME
java -Xms512m -Xmx1024m -Dorg.apache.jasper.compiler.disablejsr199=true -jar $WHOME/start.jar
>> $WLOGS/wisemapping.log
2>> $WLOGS/error.log
emit wisemapping_running
end script
當conf檔案放入/etc/init後便可以透過以下指令進行
start {service name}
stop {service name}
restart {service name}
status {service name}
以下大概作個說明
description "描述說明"
author "作者名稱"
start on [程序]
# start on started mysql <= 等 mysql 啟動完畢在啟動
# start on runlevel [345] <= 伴隨系統runlevel設定一起啟動
# 說明請見 http://upstart.ubuntu.com/cookbook/#runlevels
stop on [程序]
env 環境變數
expect fork #保護程序
pre-sstart script # 啟動預備程序
<內容>
chdir 目錄 # 切換目錄
end script
respawn # 當程序崩潰時重新啟動
script # 主程序
內容
end script
更詳細的說明可以參考 http://blog.fens.me/linux-upstart/