本文地址:http://blog.csdn.net/spch2008/article/details/9471209
sysvinit时,启动一个程序通过执行该脚本即可,如/etc/init.d/spch2008 start
upstart环境下,配置文档写在/etc/init下,所以/etc/init.d/spch2008 start命令将失效。为了兼容,采用如下方式:
root@nova-controller:/etc/init.d# ln -s /lib/init/upstart-job spch2008
spch2008.conf内容如下:
start on runlevel [2345] stop on runlevel [016] script mkdir -p /home/spch2008 chown root:root /home/spch2008 end script
这样,就可以通过sysvini的方式启动程序啦。
root@nova-controller:/home# /etc/init.d/spch2008 start Rather than invoking init scripts through /etc/init.d, use the service(8) utility, e.g. service spch2008 start Since the script you are attempting to invoke has been converted to an Upstart job, you may also use the start(8) utility, e.g. start spch2008 spch2008 start/running, process 23276
/lib/init/upstart-job脚本:
#!/bin/sh -e INITSCRIPT="$(basename "$0")" JOB="${INITSCRIPT%.sh}" COMMAND="$1" case $COMMAND in status) $COMMAND "$JOB" ;; start|stop) $COMMAND "$JOB" ;; restart) if status "$JOB" 2>/dev/null | grep -q ' start/'; then RUNNING=1 fi if [ -n "$RUNNING" ] ; then stop "$JOB" fi start "$JOB" ;; esac
只看一些关键点:INITSCRIPT为获取的文件名,如果输入的是spch2008.sh,则JOB去除.sh即为spch2008。
/etc/init.d/spch2008.sh status ==》 INITSCRIPT:spch2008.sh JOB:spch2008
/etc/init.d/spch2008 status ==》 INITSCRIPT:spch2008 JOB:spch2008
COMMAND记录命令,如start,status,stop。
根据COMMAND转到相应的分支中去,如status,则实际转换成了status spch2008