How do I quickly find out who controls some linux service?
I'm tired of poking around /etc to find out if initd, upstart, systemd or supervisord is controlling some service.
How do I quickly find out who controls some linux service?
I'm tired of poking around /etc to find out if initd, upstart, systemd or supervisord is controlling some service.
If you're not sure which init, you can guess from ps | grep -E "systemd|upstart"
. (Some shiny systemd may be present on legacy upstart systems, but not vice-versa I think). You can check for supervisord or so as well.
Googling initd tells me about /etc/init.d
so I assume that's what you meant... Sorry but nothing comes to mind for detecting sysV init-scripts other than looking in /etc. (If you're stuck on sysvinit I guess you additionally want to /etc/init.d/foo status
or service foo status
, to make sure your service is actually being run from sysvinit. That won't tell you if the service has unfortunately been run from both sysvinit and supervisord).
On upstart I think it's easy to find jobs because initctl list
shows pids. So if it's there, it's either an upstart job or sysV init-script running under backwards compatibility (and see above to detect the difference).
On systemd you could check for a given pid using cgroups field of ps, see below. If the cgroup says .service
it must have been started by systemd. If you don't mind looking for a (potentially ambiguous) process name instead, systemd-cgls
is easier to remember. Then I think systemctl status foo
will even give you enough information to detect sysV init-script for foo.service.
$ ps xawf -eo pid,user,cgroup,args PID USER CGROUP COMMAND 2 root - [kthreadd] 3 root - \_ [ksoftirqd/0] [...] 4281 root - \_ [flush-8:0] 1 root name=systemd:/systemd-1 /sbin/init 455 root name=systemd:/systemd-1/sysinit.service /sbin/udevd -d 28188 root name=systemd:/systemd-1/sysinit.service \_ /sbin/udevd -d 28191 root name=systemd:/systemd-1/sysinit.service \_ /sbin/udevd -d 1096 dbus name=systemd:/systemd-1/dbus.service /bin/dbus-daemon --system --address=systemd: --nofork --systemd-activation [...]
For supervisord use supervisord status
.