未找到 CentOS 启动脚本命令

未找到 CentOS 启动脚本命令

尝试在 CentOS 6 上启动 bitcoind,但只收到命令未找到错误。

#!/bin/bash
#
#  bitcoind The bitcoin core server.
#
#
# chkconfig: 345 80 20
# description: bitcoind
# processname: bitcoind
#

# Source function library.
. /etc/init.d/functions

prog=bitcoind
lockfile=/var/lock/subsys/bitcoind

start() {
    echo -n $"Starting $prog: "
    daemon --user bitcoind LD_LIBRARY_PATH=/home/bitcoind/bitcoind/deps/lib /home/bitcoind/bitcoind/downloads/bitcoin-0.9.4/src/bitcoind
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch $lockfile
    return $RETVAL
}

stop() {
    echo -n $"Stopping $prog: "
    killproc $prog
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f $lockfile
    return $RETVAL
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
        status $prog
        ;;
    restart)
        stop
        start
        ;;
    *)
        echo "Usage: service $prog {start|stop|status|restart}"
        exit 1
        ;;
esac

但是当我尝试运行它时:

root@server1 [/etc/init.d]# service bitcoind start
Starting bitcoind: /etc/init.d/bitcoind: line 19:  : command not found
/etc/init.d/bitcoind: line 20:  : command not found

/etc/init.d/bitcoind: line 22: [: -eq: unary operator expected
root@server1 [/etc/init.d]#

答案1

在功能来源下方,请添加:

RETVAL=0

这样这些行看起来就像:

# Source function library.
. /etc/init.d/functions
RETVAL=0

如果您查看许多 CentOS 启动脚本,您会发现其中大多数都已初始化 RETVAL=0。

% grep RETVAL=0 /etc/init.d/*
acpid:RETVAL=0
atop:RETVAL=0
auditd:RETVAL=0
autofs:     RETVAL=0
...
sshd:RETVAL=0
...
winbind:RETVAL=0
wine:RETVAL=0

相关内容