我制作了init.d文件来运行带有守护程序的芹菜花,它可以工作。但是,当我重新启动EC2服务器时,必须手动运行此文件。
我希望该文件在服务器重新启动后会自动重新启动。
下面的代码是我的init.d文件。我需要为此添加什么代码?
#!/bin/bash
NAME=flower
DESC="flower daemon"
# Name of the projects settings module.
export DJANGO_SETTINGS_MODULE="yourproject.settings"
# Path to virtualenv
ENV_PYTHON="/your/virtualenv/bin/python"
# Where the Django project is.
FLOWER_CHDIR="/path/to/your/project"
# How to call "manage.py celery flower" (args...)
FLOWERCTL="/your/virtualenv/bin/flower -port=5555"
DAEMON=$FLOWERCTL
set -e
case "$1" in
start)
echo -n "Starting $DESC: "
# Activate the virtual environment
. /your/virtualenv/bin/activate
start-stop-daemon --start --pidfile /var/run/$NAME.pid \
--chdir $FLOWER_CHDIR --chuid celery \
--user celery --group celery --background \
--make-pidfile \
--exec "$ENV_PYTHON" -- $FLOWERCTL
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --oknodo \
--pidfile /var/run/$NAME.pid
rm -f /var/run/$NAME.pid
echo "$NAME."
;;
esac
exit 0
已解决
我只是在初始化文件的顶部添加了此代码。
#!/bin/bash
### BEGIN INIT INFO
# Provides: flower
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: celery flower daemon
### END INIT INFO