This can be used to daemonize anything that would normally run in the foreground; I picked Redis. Put this in /etc/systemd/system/redis.service
:
[Unit]
Description=Redis
After=syslog.target
[Service]
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
RestartSec=5s
Restart=on-success
[Install]
WantedBy=multi-user.target
Make sure that redis.conf
has demonize no
(the default; systemd will take care of 'daemonizing'). The Restart=on-success
in the service file means that the daemon will be auto-restarted only when it exited cleanly (so that 'bad' problems are not masked; see doc). Then run:
sudo systemctl enable /etc/systemd/system/redis.service
sudo systemctl start redis.service
Links:
I was so glad I found this "redis.service" script as the official documentation is still giving instructions to start redis with "init.d"
But after I kept on getting errors when I started the service (status=203/EXEC).
When I started redis-server manually with the command it worked...
Now the problem was the given path in the startup command in the script above:
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStart=/usr/sbin/redis-server /etc/redis/redis.conf