Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Executing multiple commands in init.d script without wasting too much if your time.
The question is published on by Tutorial Guruji team.
The question is published on by Tutorial Guruji team.
I have the following init.d script:
#! /bin/sh ### BEGIN INIT INFO # Provides: Django-Server # Required-Start: $all # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Django Server ### END INIT INFO PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin . /lib/init/vars.sh . /lib/lsb/init-functions # If you need to source some other scripts, do it here case "$1" in start) log_begin_msg "Starting Django Server" python3 "/home/pi/Python Projects/episode_tracker/manage.py" runserver 0.0.0.0:12345 --insecure python3 "/home/pi/Python Projects/shifts_server/manage.py" runserver 0.0.0.0:23456 --insecure log_end_msg $? exit 0 ;; stop) log_begin_msg "Stopping Django Server" # do something to kill the service or cleanup or nothing log_end_msg $? exit 0 ;; *) echo "Usage: /etc/init.d/django_server {start|stop}" exit 1 ;; esac
I’m aware that stop
doesn’t do anything useful at the moment.
My problem is with the lines:
python3 "/home/pi/Python Projects/episode_tracker/manage.py" runserver 0.0.0.0:12345 --insecure python3 "/home/pi/Python Projects/shifts_server/manage.py" runserver 0.0.0.0:23456 --insecure
For some reason, only the first one is executed. If I comment the first one, then the second is executed (so the syntax is correct, the path exists etc).
If it matters, the OS is Raspbian.
Answer
The manage.py runserver
command isn’t forking off as a daemon and so the init script is sitting there waiting to finish. You can put a &
at the end of the two lines to make them both be backgrounded.
python3 "/home/pi/Python Projects/episode_tracker/manage.py" runserver 0.0.0.0:12345 --insecure & python3 "/home/pi/Python Projects/shifts_server/manage.py" runserver 0.0.0.0:23456 --insecure &
We are here to answer your question about Executing multiple commands in init.d script - If you find the proper solution, please don't forgot to share this with your team members.