0

I was using the following command to check whether system uses systemd
if [[ 1 == pidof systemd ]]; then

But this fails in chroot since proc is not mounted.

sh-4.2# pidof systemd sh-4.2# ps Error, do this: mount -t proc proc /proc

What alternative method can be used to check whether system uses systemd or sysv?

nithinj
  • 21
  • 3

1 Answers1

0

You can check if /sbin/init is a symlink to systemd. This isn't as good as the ps method because it's possible (but unlikely) that something besides /sbin/init is pid 1.

if [[ `file /sbin/init | grep -q systemd && echo 1` = 1 ]]
Mark Stosberg
  • 624
  • 3
  • 7
  • But this is in a chroot (see the title/tags)? The init binary doesn't need to be in the chroot. Or you could have an init binary, that isn't the same as the system init. – Zoredache Dec 08 '16 at 19:01
  • It works in my chroot environment. But not sure there are any caveats like @Zoredache said. – nithinj Dec 09 '16 at 04:31