I am using supervisor to run my web application on system boot, and one of the application is using redis, so that requires redis start first.
supervisor doesn't have a good way to support start dependency, but systemd support this.
Steps
0, Create your redis start config file, e.g. 6379.conf
, and make sure the daemonize
is set to no
1, Create redis systemd file redis.service
:
[Unit]
Description=Redis
After=network.target
[Service]
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-server /home/redis/6379.conf
ExecStop=kill -s HUP $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
2, Copy this file to path:
cp redis.service /lib/systemd/system/
3, Start redis with systemd:
systemctl start redis
4, Set start redis on system boot:
systemctl enable redis
If you changed the service file content, you need to reload it:
systemctl daemon-reload
5, Go to folder /etc/systemd/system/multi-user.target.wants
, and find supervisor.service
, under the [Unit]
section, add line:
Requires=redis.service
All done. Now on the system reboot, redis will start before supervisor, so if you applications are booted by supervisor, now they can safely connect to redis.
Discussion (0)