在 init.d 脚本中执行多个命令

Dee*_*ace 3 shell-script 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  
Run Code Online (Sandbox Code Playgroud)

我知道目前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  
Run Code Online (Sandbox Code Playgroud)

出于某种原因,只有第一个被执行。如果我评论第一个,则执行第二个(因此语法正确,路径存在等)。

如果重要的话,操作系统是 Raspbian。

Ste*_*ris 6

manage.py runserver命令不会作为守护进程分叉,因此 init 脚本就在那里等待完成。您可以&在两行的末尾放置 a以使它们都成为背景。

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 &
Run Code Online (Sandbox Code Playgroud)