Sample Header Ad - 728x90

Detect init system using the shell

110 votes
23 answers
77754 views
This may have more to do with detecting operating systems, but I specifically need the init system currently in use on the system. Fedora 15 and Ubuntu now use systemd, Ubuntu used to use Upstart (long time default until 15.04), while others use variations of System V. I have an application that I am writing to be a cross-platform daemon. The init scripts are being dynamically generated based on parameters that can be passed in on configure. What I'd like to do is only generate the script for the particular init system that they are using. This way the install script can be run reasonably without parameters as root and the daemon can be "installed" automagically. This is what I've come up with: * Search for systemd, upstart, etc in /bin * Compare /proc/1/comm to the systemd, upstart, etc * Ask the user **What would be the best cross/platform way of doing this?** Kind of related, **Can I depend on bash to be on the majority of *nix or is it distribution/OS dependent?** Target platforms: * Mac OS * Linux (all distributions) * BSD (all versions) * Solaris, Minix, and other *nix
Asked by beatgammit (7843 rep)
Aug 6, 2011, 11:29 PM
Last activity: Mar 31, 2025, 02:48 PM