How to Get Run Level in FreeBSD

1

At Linux we can get run level as like:

if [ "$(runlevel | sed 's/.* //')" = 6 ]; then
  echo "A reboot is in progress"
fi

and run level 0 is for shutdown. How can I do the same for Free BSD?

kamaci

Posted 2012-08-03T08:15:49.120

Reputation: 111

Answers

2

Runlevel is a concept specific to sysvinit (SystemV-style init). Other flavours of init used in Linux (for example, systemd) don't have concept of runlevel either.

The concept of runlevel also does not exist in BSD-style init, hence no runlevels in FreeBSD.

Mikhail Kupchik

Posted 2012-08-03T08:15:49.120

Reputation: 2 381

0

Testing the presence of

/var/run/nologin

file gives same information.

kamaci

Posted 2012-08-03T08:15:49.120

Reputation: 111

0

Mikhail is correct in that there are no Linux/SysV style run levels, however there is single and multi-user mode. This is roundabout but the best way I've discovered to tell if you're in single or multi-user programmatically:

When FreeBSD is in single user mode "adjkerntz" hasn't been started yet (and it is killed if you drop back down, too), so you can test for that:

if ! ps -auxww | grep -v "grep" | grep "adjkerntz" > /dev/null; then
   echo "Single user";
else
   echo "Multi-user";
fi

I have verified this works under 9.x and 10.x and likely all other versions of FreeBSD.

Adam Strohl

Posted 2012-08-03T08:15:49.120

Reputation: 141