I'm trying to make a specific script load on start on Debian.
I have tried to put the script on /etc/rc.local but no success.
Now I have made a service script that runs my specific script. The code of the service script is:
#!/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
Now I can test if my script is run as a service using sudo service <script> start
My code of /usr/local/bin/script1
is:
#!/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
When I run /usr/local/bin/script1
from bash it runs successfully but when I run sudo service servicescript start
it doesn't run successfully. But when I do sudo service servicescript otherarg
it runs successfully, so the service script is well configured. It is just the start
that doesn't work on the service.
When I do sudo service servicescript start
I get this error:
Job for script.service failed. See 'systemctl status script.service' and 'journalctl -xn' for details.
When I do systemsctl status script.service
I get this message:
● script.service - Info
Loaded: loaded (/etc/systemd/system/script.service; enabled)
Active: failed (Result: exit-code) since Qui 2017-03-23 17:19:25 WET; 2min 35s ago
Process: 7710 ExecStop=/usr/local/bin/killscript (code=exited, status=0/SUCCESS)
Process: 11689 ExecStart=/usr/local/bin/script1 (code=exited, status=2)
Main PID: 11689 (code=exited, status=2)
systemsctl status script.service
as root after the failed start attempt, it prints the logged error messages as well. They should help you diagnose the problem.