How to manage custom Linux daemon

Prelude

Have you ever written Linux daemons? If you don't but you want then you should know that daemons are simple programs. You can just "daemonize" them by default tools.

This tool is called start-stop-daemon. Of course you can find some example of usage this tool. Or even go to the official docs, but, unfortunately, this is not so easy as you think. Well, as for me - it was a long way to success. Therefore I'm going to simplify your research process and show ready-to-use code.

Preparing config files

Our daemon based on this project called Chatter. So you can see full code in the GitHub

Running ahead, I can tell you that we'll need only two config-files. These files should be named same as your service (or project). First one /etc/init.d/chatter

The second one /etc/init/chatter.conf. To be honest, I took it from httpd server or nginx. Just because it works :) And modified them with my requirements

Preparing files

  1. Put your executable daemon (in my case it is chatter) into the /usr/sbin/ directory

  2. Set permissions for the files /etc/init.d/chatter and /usr/sbin/chatter to 755. It will allow to execute the files

Enabling daemon

The last one thing you have to do is enabling your daemon by executing command in the terminal: systemctl enable chatter.service

Make sure that you have permissions for all operations above. Sometimes people make only one mistake with permissions and then looking for issue for weeks!

That's all. If you did all operations then you'll be able to manage your daemon with usual commands: service chatter start, service chatter stop, etc.