I created the following script in /etc/init.d/bootscript.sh
The script has these permissions:
-rwxr-xr-x 1 root root 855 Aug 1 22:44 bootscript.sh
# /etc/init.d/bootscript.sh
### BEGIN INIT INFO
# Provides: bootscript.sh
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable bot named holt-bot
### END INIT INFO
# Run my custom discord bot on boot.
case "$1" in
start)
echo "Starting holt-bot"
nohup python3 /home/nick/code/python/holt-bot/holt-bot.py 2> /home/nick/python.log &
;;
stop)
echo "Stopping holt-bot"
pkill -f holt-bot.py
;;
restart)
echo "Stopping holt-bot"
pkill -f holt-bot.py
echo "Starting holt-bot"
nohup python3 /home/nick/code/python/holt-bot/holt-bot.py 2> /home/nick/python.log &
;;
*)
echo "Usage: /etc/init.d/bootscript.sh {start|stop}"
echo "$1" >> /home/nick/python.log
exit 1
;;
esac
exit 0
When I run /etc/init.d/bootscript.sh
followed by start
, stop
or restart
it does what it is supposed to do.
However, when I reboot, or when I run sudo service bootscript.sh start
, it fails to launch. I found this in sudo systemctl status bootscript.service
:
Aug 02 10:05:45 raspberrypi systemd[1]: Starting LSB: Start daemon at boot time...
Aug 02 10:05:45 raspberrypi systemd[1]: bootscript.service: Control process exited, code=exited status=203
Aug 02 10:05:45 raspberrypi systemd[1]: Failed to start LSB: Start daemon at boot time.
Aug 02 10:05:45 raspberrypi systemd[1]: bootscript.service: Unit entered failed state.
Aug 02 10:05:45 raspberrypi systemd[1]: bootscript.service: Failed with result 'exit-code'.
I think this means that the script is called without any of the defined arguments? Should I fix that somehow, or should I make the script work without arguments? Or is the problem something else entirely?