这个脚本不会在启动时执行,想法?

发行版是RHEL 5。

该脚本已被添加到chkconfig像这样:

# chkconfig --add script # chkconfig script on 

但是在拿起机器时拒绝启动,可能是什么问题?

 #!/bin/bash # # chkconfig: 2345 20 80 # description: starts script . /etc/rc.d/init.d/functions PATHB=/xxxx/opt/virtualenvs/primary/bin USER=userx function start() { /usr/bin/sudo /bin/su - $USER -c "$PATHB/script start" } function stop() { /usr/bin/sudo /bin/su - $USER -c "$PATHB/script stop" } function status() { /usr/bin/sudo /bin/su - $USER -c "$PATHB/script status" } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; status) status ;; *) echo "Usage: $0 {start|stop|restart|status}" exit 1 esac 

初始化脚本是由root运行的,所以把sudojoin混合是不必要的。 使用sudo的唯一原因是当你是一个非特权用户需要运行一些具有更高权限的东西时 – 当你已经是root的时候,这种情况从来就不是这样。

由于使用sudo可以从命令行运行,但不能从init脚本运行,所以我会放置一个小小的sudoers文件,其中包含requiretty 。 这使得sudo只能从具有tty的shell中获得,所以它不能被某个试图通过恶意的php脚本或其他东西侵入的人来运行 – 当然,它也会禁止cron和init的sudo。

你运行了脚本可执行文件吗? 即通过运行chmod + x