我有一个命令工作正常,如果我从命令行执行它…但是当我把它放在一个init.d脚本它不会开始(嗯..它开始,但有一个不同的行为,当它运行直)。
任何想法,为什么这不起作用的init脚本?
命令是: bluepill load /var/www/html/bluepill.conf
而init.d脚本是:
#!/bin/sh ## Based on http://www.novell.com/coolsolutions/feature/15380.html # chkconfig: 345 99 1 # processname: solr # Provides: bluepill # Default-Start: 3 4 5 # Default-Stop: 0 1 2 6 # Short-Description: bluepill daemon, providing process monitoring # Description: Bluepill # Check for missing binaries BLUEPILL_BIN=/usr/local/bin/bluepill test -x $BLUEPILL_BIN || { echo "$BLUEPILL_BIN not installed"; if [ "$1" = "stop" ]; then exit 0; else exit 5; fi; } # Check for existence of needed config file and read it BLUEPILL_CONFIG=/var/www/html/bluepill.conf test -r $BLUEPILL_CONFIG || { echo "$BLUEPILL_CONFIG not existing"; if [ "$1" = "stop" ]; then exit 0; else exit 6; fi; } case "$1" in start) echo -n "Starting bluepill " $BLUEPILL_BIN load $BLUEPILL_CONFIG ;; stop) echo -n "Shutting down bluepill " $BLUEPILL_BIN quit ;; restart) ## Stop the service and regardless of whether it was ## running or not, start it again. $0 stop $0 start ;; *) ## If no parameters are given, print which are avaiable. echo "Usage: $0 {start|stop|restart}" exit 1 ;; esac
更新(回答几个问题):
我还添加了脚本,以便在启动时执行使用:
chkconfig --add bluepill_script chkconfig --level 345 bluepill_script on
尝试添加
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
到init脚本的顶部。
运行时,我会回应卡米尔的输出。
此外,你有没有尝试过chkconfig --add bluepill和chkconfig bluepill on 。
否则,我打赌这是脚本中的某种环境variables。 尝试通过开始采购环境. /etc/profile . /etc/profile之类的。 特别是因为这看起来像是安装在/ usr / local / bin中。 它可能需要正确设置PATH或LD_LIBRARY_PATH。
我正在使用下面的init.d脚本,并且出现类似的问题,因为bluepill gem是在rvm安装下安装的。 注意必须获取rvm环境variables,但是通过采购/ etc / profile(因为它也被设置在那里)可以实现相同的目的。 我正在使用Opscode食谱配方来设置这些,所以这些path被设置为rvm食谱安装gem的地方。
#!/bin/bash # # Bluepill # # chkconfig: - 85 15 # description: start, stop, restart bluepill # RETVAL=0 if [[ -s /usr/local/rvm/scripts/rvm ]] ; then source /usr/local/rvm/scripts/rvm ; fi case "$1" in start) for i in /etc/bluepill/*.pill; do /usr/local/rvm/gems/ruby-1.9.2-p180/bin/bluepill load $i done RETVAL=$? ;; stop) /usr/local/rvm/gems/ruby-1.9.2-p180/bin/bluepill stop /usr/local/rvm/gems/ruby-1.9.2-p180/bin/bluepill quit RETVAL=$? ;; restart) /usr/local/rvm/gems/ruby-1.9.2-p180/bin/bluepill restart RETVAL=$? ;; status) /usr/local/rvm/gems/ruby-1.9.2-p180/bin/bluepill status RETVAL=$? ;; *) echo "Usage: bluepill {start|stop|restart|status}" exit 1 ;; esac exit $RETVAL
好的愚蠢的问题,但你设置脚本启动时启动? 我更熟悉debian风格的发行版,但ntsysv或chkconfig可能是你所需要的。
另一个愚蠢的问题是,脚本运行后,bluepill是否加载到内存中? ps -ef | grep bluepill
日志中没有错误没有清楚地表明init脚本正在工作。 两个简单的步骤将debugging这个。
您可能还必须在/ etc / rcX文件夹之一(取决于您的预期运行级别)链接并运行
sudo运行update-rc.d SkriptnameWithinInitDWithoutPath默认值