10
  • Command systemctl get-default returns user-defined.target.
  • Then I use systemctl isolate multi-user.target to switch to multi-user.target.
  • I can see that a bunch of services that shouldn't be running on user-defined.taret and should be running on multi-user are running, this implies I am on multi-user.target.
  • But, systemctl get-default always returns user-defined.target.

Question is, without looking and sorting through the services, how do I know that I am running on multi-user.target after using isolate ?

3
  • 1
    There isn't a single target systemctl list-units --type target
    – user9517
    Feb 28 '17 at 22:17
  • Not entirely sure what you mean. I know there isn't a single target, but then why the default and isolate? What do they represent ?
    – iamauser
    Feb 28 '17 at 22:35
  • 1
    @iamauser. isolate means change to the specified target. That does not survive a reboot unless you persist the specified target using set-default
    – fpmurphy
    Mar 1 '17 at 1:12
10

In systemd, there may be more than one active target at a time.

To inspect the list of all currently active targets:

systemctl list-units --type target --state active

To quickly find out whether a specific target (e.g. user-defined.target) is active or not:

systemctl is-active user-defined.target
3

There is no systemd command to query the running target or the last target used with isolate.

systemd does ship with a command called runlevel for compatibility for older systems. This will prevent the current "runlevel". The concept is obsolete, but as seen as man runlevel, particular run levels map to particular systemd targets. This command might be helpful as long as standard targets are used. It would not be useful if a custom target was used which did not map to a legacy runlevel.

More discussion about workarounds is on a [https://www.centos.org/forums/viewtopic.php?t=54347](CentOS forum).

2
  • 2
    This answer helps, but man that's just yuck...
    – iamauser
    Mar 1 '17 at 15:35
  • I updated my answer to mention the runlevel command which might be helpful to you. Mar 1 '17 at 16:08
1

Here is the best way I could come with to find out the current target mode you are.

emergency - after running the command systemctl list-units --type target emergency target

rescue - after running the command systemctl list-units --type target rescue target

multi-user - after running the command systemctl list-units --type target multi user target

1

Similarly to the answer previously mentioned you can use:

systemctl list-units --type target | egrep "eme|res|gra|mul" | head -1

What you get as a result is your current target.

If you have installed unit that has in its name one of these four strings above, you could add the ^ character in front of them - egrep "^eme|^res|^gra|^mul"

0

Unfortunately none of these answers indicate which runlevel is currently active. They all show in my case that both multi-user.target and graphical.target are loaded/active. So far only the runlevel command indicates the current runlevel.

runlevel | awk '{print $2}'

2
  • systemd is, in fact, stateless. There is no current "runlevel", as you can start and stop units all the time. This is why these units are called "targets" and the command is called "isolate".
    – Bachsau
    Jun 28 '20 at 10:55
  • systemd doesn't have the concept of runlevels and doesn't come with a runlevel command. Your runlevel command is part of another init system left on your computer and probably won't reflect the current state of your computer.
    – Starfish
    Aug 30 '20 at 21:43
0

I think the best command to find out the current target is

# who -r

If its runlevel 3 ==> multi-user.target, runlevel 5 ==> graphical.target

But I'm not sure RH will remove this cmd, as this is very legacy method to check boot process.

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.