Can systemd handle double-fork daemons ?
I previously used init.d/ script to manage daemons I wrote which have worked flawless for years. Now I find myself needing to provide a systemd/ script for and I cannot get that to work with the way I do daemon setup code.
When I setup a daemon I fork twice to loose controlling terminal and avoid being session leader.
The problem with this is that I have confirmed that when you do that systemd/ looses track and kills the daemon. I have also confirmed that skipping the second fork makes it work again with systemd/.
My basic (slightly simplified for the purpose of this discussion) systemd/ script is
[Unit] Description=GM7 Service Daemon [Service] Type=forking ExecStart=/usr/bin/g7ctrl [Install] WantedBy=multi-user.target
So I guess my question is : Do I need to change the way I have done daemon setup code in C/C++ for the last decade or is there is options to get systemd/ to track a double-fork ?
I haven't quite read-up on the inner workings if systemd itself spawns processes for each daemon it starts in which case my double-fork would indeed be obsolete
I admit that the way I have done it (double fork) is partially for historic reasons but at the time I did some quite intensive read-up on best-practice and this is what I then came up with (a decade or so ago)