DEV Community

BC
BC

Posted on

9 3

Systemd: start supervisor after redis on reboot

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
Enter fullscreen mode Exit fullscreen mode

2, Copy this file to path:

cp redis.service /lib/systemd/system/
Enter fullscreen mode Exit fullscreen mode

3, Start redis with systemd:

systemctl start redis
Enter fullscreen mode Exit fullscreen mode

4, Set start redis on system boot:

systemctl enable redis
Enter fullscreen mode Exit fullscreen mode

If you changed the service file content, you need to reload it:

systemctl daemon-reload
Enter fullscreen mode Exit fullscreen mode

5, Go to folder /etc/systemd/system/multi-user.target.wants, and find supervisor.service, under the [Unit] section, add line:

Requires=redis.service
Enter fullscreen mode Exit fullscreen mode

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.

👋 While you are here

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (0)

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay