Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Portable Init Script?

How to write a portable init Script which works with

  • upstart (Ubuntu)
  • systemd
  • optional init.d

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

like image 625
guettli Avatar asked Jun 04 '26 23:06

guettli


1 Answers

Both systemd and upstart support sysinit style scripts. RHEL 6 uses upstart but most scripts are normal init.d bash scripts. RHEL 7 and Fedora 19 (and earlier) use systemd, but they happily run old init scripts.

You can use normal old style daemon that forks with init script. If the application does not fork on its own you can use something like supervisord to do the forking for you and directly integrate with separate systemd script. I do not know details about upstart except it uses it's own format, but supporting it (if you do not have to support old/current linux systems) seems reasonable only for non-linux distributions. systemd is currently Linux specific, though I've seen work being done to port it to BSD.

You may be interested in how they integrated CUPS. Last time I checked the systemd "script" starts the daemon with -f option (foreground) - ExecStart=/usr/sbin/cupsd -f. The init.d script does not add that flag.

In short - for now use old style System V init.d script if you want one solution that works everywhere. Add systemd support if you have some spare resources and if you have enough, you can certainly support the three systems separately (greatest benefit for the users, but a lot of work).

I'd personally create init.d + systemd scripts and would not care about upstart. Chances are systemd will soon replace upstart (also look here) and init.d scripts will remain usable on the rest of the UNIX-es.

like image 61
Doncho Gunchev Avatar answered Jun 07 '26 22:06

Doncho Gunchev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!