init.d 脚本不起作用...但如果我在控制台中执行该命令,它就会起作用

init.d 脚本不起作用...但如果我在控制台中执行该命令,它就会起作用

我有一个命令,如果我从命令行执行它,它可以正常工作...但是当我将它放在 init.d 脚本中时,它不会启动(嗯..它可以启动,但行为与直接运行时不同)。

知道为什么这在初始化脚本上不起作用吗?

命令是: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  

答案1

尝试添加

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin

到初始化脚本的顶部。

答案2

我将在运行时响应卡米尔 (Kamil) 的输出调用。

此外,您是否尝试过chkconfig --add bluepillchkconfig bluepill on

否则,我敢打赌它是脚本中的某种环境变量。尝试在开始时通过. /etc/profile或类似方式获取环境。特别是因为它看起来像是安装在 /usr/local/bin 中。它可能需要正确设置 PATH 或 LD_LIBRARY_PATH。

答案3

我正在使用以下 init.d 脚本,并且遇到了类似的问题,因为 bluepill gem 安装在 rvm 安装下。请注意,必须获取 rvm 环境变量,但也可以获取 /etc/profile(因为它也在那里设置)来实现相同的目的。我正在使用 Opscode cookbook 配方来设置这些,因此这些路径被设置为变量,具体取决于 rvm cookbook 安装其 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

答案4

还有一个愚蠢的问题,脚本运行后 bluepill 是否会加载到内存中?ps -ef | grep bluepill

相关内容