I'm looking for a way to get a list of all the services (/etc/init.d or upstart or systemd), which are supposed to be starting (or having been started at) boot.
How do you get a list of all starting services? — I know that question, and it suggests to use service --status-all
.
But that doesn't show me, which services are SUPPOSED TO BE RUNNING. It calls all the init scripts with "status
" argument. This is a list of all the services that could be running.
But I would like to know, if a service, that had been started at boot is still running.
Example…
I have webfs installed. But I do not want it to be running at boot. Thus I disabled it: sudo update-rc.d webfs disable
. And I also have samba installed and it should be running at boot. But it is stopped (for whatever reason). sudo service --status-all
doesn't help me here:
$ sudo service --status-all 2>/dev/null | grep -E 'samba$|webfs'
[ - ] samba
[ - ] webfs
Both are off but I get no clue, that one (samba) is supposed to be on.
So…
How could I get a list of all services which are starting at boot? And, as an extension, is there an easy way to get the "status" of these services (if not, I'll simply loop over this list and run "service $service status", or something like this).
Thanks, Alexander
Edit 2015-05-04: I'm on Ubuntu 14.04.
The main focus of this question is the following:
But I would like to know, if a service, that had been started at boot is still running.
Because of this, initctl list
doesn't help much. It doesn't really take into consideration the services started by /etc/init.d
scripts (compared to upstart scripts in /etc/init
).
Also a listing of /etc/rc?.d/S*
doesn't help. It would generate a list of services, which might have been started in a given runlevel. It doesn't show me, if a service, that should've been started, is still running.
Basically, I'm looking for something like svcs -x
from Solaris for Ubuntu. With svcs -x
, I'd have output if a service, which was started, isn't running anymore. This, I'd need for Ubuntu as well.
Reason: I'd like to have a (more or less...) generic check for our Icinga/Nagios monitoring system, which would alert me, if a service isn't running anymore, which should be running. As we've got many different servers for many different customers, it doesn't really scale to define a list of "important" services.
All services start on startup:
List of all services which exist in system:
List all services and respective runlevel status - chkconfig style:
Interactive text based edit of all listed:
Might have to install it if not there:
Here's my oneliner
grep -i 'runlevel' /etc/init/* | awk '!/#/ && /start on/ && /2/ {gsub("/"," "); print $0 }' | cut -d ' ' -f4-
A bit cleaner output can be achieved with
grep -i 'runlevel' /etc/init/* | awk '/start on/ && /2/ {gsub("/"," "); gsub(":", " ");gsub(".conf"," "); print $3 }'
Now lets get into details. Upstart jobs are all stored in
/etc/init/
, right ? The jobs there all have a lines stating at which runlevel they start. Runlevel 2 is a normal boot, default runlevel. So if we grep all the lines that sayrunlevel
and clean output of grep with awk to match only lines withstart on
and runlevel #2, we get the list of upstart jobs. The rest is just for formating needs, replace / in file names to space, and cut away the path to those files, leaving filenames themselves.The
!/#/
part is to address possibly commented out start directives, which I had personally added manually.Among other things,there is
/etc/rc2.d
where (if I understand correctly ) you have lesser priority scripts.Crude one-liner for that is:
ls /etc/rc2.d/* | grep S | awk '{sub("S"," "); print $2}
Scripts that in that folder that actually run on runlevel 2 are named starting with S and followed by priority number. Now, basically, we get all files starting with S, and just list them with only priority name (still have to figure out how to clean that up).
As muru properly pointed out in the comments, there is also
/etc/init/*.override
files, which may " . . .modify how a job will run without having to modify its configuration file directly" (init manpage)At current moment, since I've not much experience with these files, I can only suggest looking through those .override files by using 'grep 'manual' /etc/init/*.override' to list services that are told to be started manually with
initctl
orservices
commands.