init.dスクリプトで複数のコマンドを実行する

init.dスクリプトで複数のコマンドを実行する

次のinit.dスクリプトがあります。

#! /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  

stop現時点では有用な作業が行われていないことがわかります。

私の問題は次の行にあります。

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  

何らかの理由で最初の項目のみが実行されます。最初の項目にコメントを付けると、2番目の項目が実行されます(したがって構文が正しいこと、パスが存在するなど)。

重要な場合、オペレーティングシステムはRaspbianです。

ベストアンサー1

このmanage.py runserverコマンドはデーモンに分岐しないので、initスクリプトが完了するのを待っています。&両方の行の末尾に追加して両方の背景を作成できます。

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 &

おすすめ記事