Can systemd handle double-fork daemons?

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
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)
systemd daemon
add a comment |Â
up vote
0
down vote
favorite
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)
systemd daemon
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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)
systemd daemon
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)
systemd daemon
systemd daemon
asked 9 mins ago
Johan
595
595
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f476595%2fcan-systemd-handle-double-fork-daemons%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password