If your daemon is of Type=forking then failure to initialize should be indicated by the initial process (the one launched by systemd) outputting an error message and then failing.
Only once the grandchild (not the child, you must double-fork in order to start up correctly) has indicated to the initial process that it is ready to provide the service, should the initial process exit, cleanly, thereby notifying systemd that startup was successful.
See daemon(7) for the full details.
If the program exits with a special status to indicate non-restartable failure, you could, in principle, recognize that in the process manager and handle it differently, by not restarting. Is there any way to do this in systemd, or in any other process manager?
Re:You don't need to daemonize
by icebraining on Sunday June 28, 2015 @06:43PM
(#9795411)
Yes, systemd has "RestartPreventExitStatus" to configure a list of exit codes which prevent the automatic restart.
Was there not a recent blog/article that mused about the likelihood of systemd spawning all manner of special case entries?
And now i ponder likening systemd with CISC...
Re:You don't need to daemonize
by icebraining on Sunday June 28, 2015 @04:15PM
(#9794898)
Usually these daemon managers detect when the process is dying right after starting up and indicate that with a message like "[process] is respawning too fast". Besides, there are always logs.
But that's not a way to detect service failure. That's a way to detect potential service failure. The only unambiguous failure notification is the return code.
Re:You don't need to daemonize
by icebraining on Sunday June 28, 2015 @06:41PM
(#9795402)
Yes, which systemd will also display, and you can configure it to handle it differently (e.g. don't auto-restart on certain exit codes).
With manual daemonization, the process can delay forking until it has ensured that its configuration is sound and it has the resources it needs. This way the parent process can indicate with its exit status whether the service was successfully launched.