87

I need to identify the currently running services but I can't figure out the results of running service --status-all, I mean what does ?, - and + mean ?

$ service --status-all
 [ + ]  acpid
 [ + ]  anacron
 [ + ]  apparmor
 [ ? ]  apport
 [ ? ]  atieventsd
 [ + ]  avahi-daemon
 [ ? ]  binfmt-support
 [ + ]  bluetooth
 [ - ]  brltty
 [ + ]  console-font
 [ + ]  console-setup
 [ + ]  cron
 [ + ]  cups
 [ + ]  cups-browsed
 [ - ]  dbus
 [ ? ]  dns-clean
 [ + ]  friendly-recovery
 [ - ]  grub-common
 [ ? ]  irqbalance
 [ - ]  kerneloops
 [ ? ]  killprocs
 [ + ]  kmod
 [ ? ]  lightdm
 [ - ]  lm-sensors
 [ ? ]  mysql
 [ ? ]  networking
 [ ? ]  ondemand
 [ ? ]  pppd-dns
 [ - ]  procps
 [ - ]  pulseaudio
 [ ? ]  rc.local
 [ + ]  resolvconf
 [ + ]  rfkill-restore
 [ + ]  rfkill-store
 [ - ]  rsync
 [ + ]  rsyslog
 [ + ]  saned
 [ ? ]  sendsigs
 [ + ]  setvtrgb
 [ ? ]  speech-dispatcher
 [ - ]  sudo
 [ + ]  timidity
 [ + ]  udev
 [ ? ]  umountfs
 [ ? ]  umountnfs.sh
 [ ? ]  umountroot
 [ - ]  unattended-upgrades
 [ - ]  urandom
 [ + ]  virtualbox
 [ - ]  x11-common

And would running this command with sudo make any difference ? I tried it and in my case it didn't make any difference, but may it differ in other setups ?

97

The output of service --status-all lists the state of services controlled by System V.

The + indicates the service is running, - indicates a stopped service. You can see this by running service SERVICENAME status for a + and - service.

Some services are managed by Upstart. You can check the status of all Upstart services with sudo initctl list. Any service managed by Upstart will also show in the list provided by service --status-all but will be marked with a ?.

Reference: man service

  • 2
    May be of interest: output for services marked - & + will go to stdout, output for services marked ? will go to stderr. – dave1010 Apr 28 '15 at 9:39
  • 1
    "Any service managed by Upstart will also show in the list provided by service --status-all but will be marked with a ?." This is not strictly true. Just tried both commands on a server. service --status-all gives me 43 services. initctl list gives me 93. Only a handful of those 93 are duplicates. – Andrew Ensley Jan 19 '16 at 14:44
  • My Ubuntu machine does not list "Upstart services" as "?" by service --status-all – hfrmobile Dec 6 '16 at 10:18
  • @hfrmobile unless you are still on 14.04 or specify at boot time to use Upstart you are using 'systemd' now. I also no longer see "?" on my 16.04 system. – Sean Dec 14 '16 at 22:08
  • running 16.10 ... – hfrmobile Dec 15 '16 at 11:16
29

It's not documented in the manpage, but a quick look at the source confirms the first guess:

  • +: the service is running
  • -: the service is not running
  • ?: the service state cannot be determined (for some reason).

The actual code:

 if ! is_ignored_file "${SERVICE}" \
 && [ -x "${SERVICEDIR}/${SERVICE}" ]; then
         if ! grep -qs "\(^\|\W\)status)" "$SERVICE"; then
           #printf " %s %-60s %s\n" "[?]" "$SERVICE:" "unknown" 1>&2
           echo " [ ? ]  $SERVICE" 1>&2
           continue
         else
           out=$(env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" status 2>&1)
           if [ "$?" = "0" -a -n "$out" ]; then
             #printf " %s %-60s %s\n" "[+]" "$SERVICE:" "running"
             echo " [ + ]  $SERVICE"
             continue
           else
             #printf " %s %-60s %s\n" "[-]" "$SERVICE:" "NOT running"
             echo " [ - ]  $SERVICE"
             continue
           fi
         fi
   #env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" status
 fi

The conditions are:

  • if the init script doesn't support a status command, the state is ?.
  • if the init script (with the status argument) exit status is zero and output is not empty, the state is +.
  • otherwise the state is -.
1

I believe that + means the service is active/running, - means it is inactive/stopped, and ? means that the command cannot conclusively determine whether it is active or not, as the service does not have a status command in the service script. The service --status-all command actually runs service <service-name> status for every available service.

0

I find that running with/without sudo makes a difference.

Some services in /var/run/ have read access only to root user. Those services show status [-] without sudo, and [+] with sudo.

  • 1
    Are you sure? some service statuses change dynamically; maybe you are just seeing variation – Zanna Mar 10 '17 at 6:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.