Controlling RHEL 7 Services

One change from RHEL/CentOS 6 to the RHEL 7 beta is how services are controlled. The old service and chkconfig commands are replaced with systemctl. These are my quick and dirty notes compiled from the Fedora Project systemd and SysVinit to Systemd Cheatsheet pages.

Basic Control

The old system command’s replacement is very similar, with services having .service appended:

[bash]
systemctl start|stop|restart|status name.service
[/bash]

For example:

[bash]
systemctl restart httpd.service
[/bash]

Service Boot time Control

To get a list of available services and their boot time status:

[bash]
systemctl list-unit-files –type=service
[/bash]

To set a service to start (or not) at boot time:

[bash]
systemctl enable|disable <em>service</em>.service
[/bash]

For example:

[bash]
systemctl enable mariadb.service
systemctl enable httpd.service
[/bash]

Run Levels

Run levels are called targets, have been simplified, and have names now. An incomplete list:

  1. poweroff.target (run level 0)
  2. rescue.target (single-user mode; run level 1)
  3. multi-user.target (normal run level 3)
  4. graphical.target (normal run level 5)

To set the default run level:

[bash]
systemctl set-default multi-user.target
[/bash]

To change the run level:

[bash]
systemctl isolate name.target
[/bash]

For example, to enter single user mode:

[bash]
systemctl isolate rescue.target
[/bash]

And the appropriate services will be stopped and started.

Additional Reading

  • A description of how systemd fits into the boot process here.
  • Another nice summary here.

Updates

2014-07-17
Updated setting the default run level per CertDepot’s suggestion. Added the “Additional Reading” section.
This entry was posted in SysAdmin and tagged , , , , , , , . Bookmark the permalink.

2 Responses to Controlling RHEL 7 Services

  1. CertDepot says:

    Just to mention that you don’t need to create a link to set the default run level, use the set-default option, for example: systemctl set-default multi-user.target
    To find more information on this topic, go to http://www.certdepot.net/rhel7-get-started-systemd/
    CertDepot

  2. Thanks for that tip. I tried it out and it’s a handy wrapper around the symlink process.

Leave a Reply