What is the right way to write/configure application under Linux, that runs all the time and serves external requests (TCP, database, filesystem, any kind of them).
I specifically do not call this daemon, because it may mean something I do not want it to in Linux environment.
I already read multiple topics, including:
best way to write a linux daemon
Best practice to run Linux service as a different user
but none of them gives full comparison about which approach to use.
I see following options:
- writing application which forks, calls setpid, umask, etc. but this requires application to perform many steps by itself; (with autostart by init.d?)
- use daemon() init.d function which performs most of those steps for you (but is it portable to all/many linux distributions)
- running application with & and trust it to run in background
But which of them is the way to go. Or if they all can be used, what constitutes daemon in Linux?
I am looking for an equivalent of running application as a service under windows (and any .exe can be automatically made for runs as a service with use of sc).
My requirements are as following:
- start after boot (automatically)
- runs as specific user (not root)
- has access to entire filesystem (/) but creates/modifies files as user under which the application is run
- can be controlled through service start, service stop
- possibly automatically restart after crash or kill
- can write to syslog
- run under RHEL7
I am the author of the application, but would prefer not to alter it to handle daemonization.
My guess would be to write custom init.d script which in turn would call daemon() function from /etc/init.d/functions. Am I right?