Debian服务脚本返回状态错误2

时间:2017-03-23 17:32:05

标签: linux service debian startup

我正在尝试在Debian上启动特定的脚本加载 我试图将脚本放在/etc/rc.local上,但没有成功 现在我已经制作了一个运行我特定脚本的服务脚本。服务脚本的代码是:

#!/bin/sh
### BEGIN INIT INFO
# Provides:          script
# Required-Start:    $local_fs $network $named $time $syslog
# Required-Stop:     $local_fs $network $named $time $syslog
# Default-Start:     5
# Default-Stop:      0 1 6
# Short-Description: Start script at boot time
# Description:       Enable service .
### END INIT INFO

case "$1" in
  start)
    echo "Starting script"
    /usr/local/bin/script1
    ;;
  stop)
    echo "Stopping script"
    ;;
  *)
    echo "Usage: /etc/init.d/script {start|stop}"
    exit 1
    ;;
esac

exit 0

现在,我可以使用sudo service <script> start

测试我的脚本是否作为服务运行

我的/usr/local/bin/script1代码是:

#!/bin/sh

exec 5> >(logger -t $0)
BASH_XTRACEFD="5"
PS4='$LINENO: '
set -x

FILE=/share/_ngrok
NAO_ESTA_ESCRITO=0

touch $FILE
/usr/local/bin/ngrok tcp 22 --region eu > /dev/null &
sleep 5
URL=`/usr/local/bin/ngrok_url`
grep -q -F "$URL" $FILE || NAO_ESTA_ESCRITO=1
if [ $NAO_ESTA_ESCRITO -eq 1 ]; then
  /usr/local/bin/ngrok_url > $FILE
  /usr/bin/drive push -no-prompt -quiet $FILE
fi
exit 0

当我从bash运行/usr/local/bin/script1时,它运行成功,但是当我运行sudo service servicescript start时,它无法成功运行。但是当我sudo service servicescript otherarg运行成功时,服务脚本配置得很好。只有start对服务无效 当我sudo service servicescript start时,我收到此错误:

  

script.service的作业失败。有关详细信息,请参阅“systemctl status script.service”和“journalctl -xn”。

当我systemsctl status script.service时,我收到此消息:

  

●script.service - 信息
     已加载:已加载(/etc/systemd/system/script.service;已启用)
     活动:失败(结果:退出代码)自Qui 2017-03-23 17:19:25 WET; 2分35秒前     处理:7710 ExecStop = / usr / local / bin / killscript(code = exited,status = 0 / SUCCESS)
    处理:11689 ExecStart = / usr / local / bin / script1(code = exited,status = 2)
   主PID:11689(代码=退出,状态= 2)

0 个答案:

没有答案