Ask Your Question

In puppet, how to I determine if node is using systemd or sysvinit? [closed]

asked 2016-05-18 09:35:30 -0600

enderqa gravatar image

updated 2016-05-19 09:50:24 -0600

Firstly, we are running puppet 4.4.2.

I have a custom puppet module which installs a daemon/service: a small ruby Webrick. I have both a systemd script to start/stop the daemon, and I also have a Sysvinit script. I would like to install the appropriate script for either one.

My ideal puppet-flow would be:

  • puppet detects if systemd or sysvinit is being used
  • puppet module then installs the appropriate script
  • puppet module enables & ensures the service is running, using the appropriate script.

Is this possible?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by enderqa
close date 2016-05-20 09:44:20.727526


There is a module for this that gets you an easy fact to use:

Tarjei Huse gravatar imageTarjei Huse ( 2017-01-29 07:49:48 -0600 )edit

you can also do `facts[service_provider]`

spuder gravatar imagespuder ( 2018-09-10 13:04:06 -0600 )edit

1 Answer

Sort by » oldest newest most voted

answered 2016-05-18 16:51:19 -0600

mike.r gravatar image

updated 2016-05-18 16:52:31 -0600

The right way to do this is to create a custom Fact for your module,


and run something like this inside the custom fact ruby to determine whats the init system (remember to confine your Fact to kernel=Linux)

$init =  `stat /proc/1/exe | grep File: | awk -F'->' {'print $2'}`

this will tell you if its systemd or init

You can then pass this Facter value down to your module and let it do its logic from there

edit flag offensive delete link more



shorted version with only two commands "ls -l /proc/1/exe | awk '{n=split($NF, N, "/"); { print N[n] }}'"

c4f4t0r gravatar imagec4f4t0r ( 2016-05-19 07:49:37 -0600 )edit

Another Option: stat -c %N /proc/1/exe | sed "s/.*\/\(.*\)\’$/\1/g"

FranzCC gravatar imageFranzCC ( 2016-05-19 08:02:50 -0600 )edit

Thanks everyone for the commands to distinguish between systemd and init. Personally, c4f4t0r's command works the best for me. (I have a soft-spot for awk.)

enderqa gravatar imageenderqa ( 2016-05-19 09:57:12 -0600 )edit

Remeber, this will not work when using Ubuntu, because it uses upstart, which is event based but neither systemd nor sysvinit. It's ubuntu ;-)

FranzCC gravatar imageFranzCC ( 2016-05-20 01:10:26 -0600 )edit

@FranzCC, thanks that's good to know! mike.r's answer works. I created a custom fact that pulls the info from /proc/1/exe. It's just a question of determining what the possible outcomes are, because as FranzCC pointed it, there are multiple options, and not just systemd and init.

enderqa gravatar imageenderqa ( 2016-05-20 09:43:56 -0600 )edit

Question Tools

1 follower


Asked: 2016-05-18 09:35:30 -0600

Seen: 1,070 times

Last updated: May 19 '16