我有以下 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
由于某种原因,仅执行第一个。如果我评论第一个,则执行第二个(因此语法正确,路径存在等)。
如果重要的话,操作系统是 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 &