Portable Init Script?

How to write a portable init Script that works with

  • upstart (Ubuntu)
  • Systemd
  • additional init.d

Other platforms (Windows, Android, OS-X) are not important in my context.

+3


source to share


2 answers


Both systemd and style scripting upstart

support sysinit

. RHEL 6 uses upstart, but most scripts are normal init.d

bash scripts . RHEL 7 and Fedora 19 (and earlier) use systemd

, but happily run old init scripts.

You can use a regular old style daemon that forks with the init script. If the app doesn't work on its own, you can use something like supervisord to do the forking for you and integrate directly with a separate systemd script. I don't know the details about upstart

other than that it uses a proprietary format, but its support (unless you need support for old / current Linux systems) seems reasonable only for non-linux distributions. systemd

is currently Linux specific, although I've seen work being done to port it to BSD.

You might be wondering how they integrated CUPS. The last time I checked the systemd

"script" starts the daemon with the -f

(foreground) option - ExecStart=/usr/sbin/cupsd -f

. init.d

The script doesn't add this flag.



In short - use the old style System V

init.d

script if you want one solution to work all over the place. Add support systemd

if you have spare resources, and if you have enough, you can of course support the three systems separately (most benefit to users, but most of the work).

I personally created init.d

systemd scripts and would not want to raise the plan. Most likely, systemd

it will soon replace the upstart ( and look here ) and the init.d

scripts will remain usable on the rest of the UNIX servers.

+2


source


It systemd

allows scripts to run as far as I know, init.d

so you can make a script that is transported with upstart

and init.d

.
Another thing is that they all ( systemd

, init.d

, upstart

) use their own syntax. The only solution I can see is to create three different scripts, which some applications call the most common service interface - the forking application. This way, all managers will know how to handle your service. And provide your application with all three types of scripts. The installer will then have to choose that the script should be installed with your service application.



+1


source







All Articles