How to manage custom Linux daemon
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 the
start-stop-daemon. Of course, you can find some examples of using 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
Running ahead, I can tell you that we'll need only two config-files. These files should be named the same as your
service (or project). First one
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
Put your executable daemon (in my case it is
chatter) into the
Set permissions for the files
755. It will allow to execute the files
The last one thing you have to do is enabling your daemon by executing a command in the terminal:
Make sure that you have permissions for all operations above. Sometimes people make only one mistake with permissions and then looking for issues 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.