3

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.

6

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 &

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.