Chkservice – An Easy Way to Manage Systemd Units in Terminal


Systemd is the default init system for many modern Linux distributions, including Debian, Ubuntu, and Fedora. Systemd is responsible for starting and stopping services, managing system resources, and providing a variety of other system-related functions. Systemd units are the basic building blocks of systemd and define the services, targets, and other system objects that are managed by the system.

While systemd provides a powerful and flexible way to manage system resources, it can be somewhat complex and intimidating to use. Fortunately, there are several tools available that can help you manage systemd units more easily, and one of the most popular of these tools is chkservice.

Chkservice is a command-line tool that provides an easy way to manage systemd units in Terminal. With chkservice, you can start, stop, enable, disable, and manage systemd units in a simple and intuitive way. In this article, we will take a closer look at chkservice and show you how to use it to manage systemd units in your Linux system.

Installing Chkservice

Chkservice is available in the official repositories of many Linux distributions, including Debian, Ubuntu, and Fedora. To install chkservice on your system, open a terminal window and type the following command −

sudo apt-get install chkservice

If you are using a different Linux distribution, you can download the chkservice package from the project's GitHub page and install it manually.

Using Chkservice

Once you have installed chkservice, you can start using it to manage systemd units in your system. Chkservice provides a simple and intuitive interface that makes it easy to manage systemd units. Here are some of the most useful commands you can use with chkservice.

Listing Systemd Units

To list all the systemd units installed on your system, type the following command −

sudo chkservice list

This command will display a list of all the systemd units installed on your system, along with their current status and other relevant information.

Starting and Stopping Systemd Units

To start a systemd unit, type the following command −

sudo chkservice start <unit name>

For example, to start the Apache web server, you can type −

sudo chkservice start apache2

To stop a systemd unit, type the following command −

sudo chkservice stop <unit name>

For example, to stop the Apache web server, you can type −

sudo chkservice stop apache2

Enabling and Disabling Systemd Units

To enable a systemd unit to start automatically at boot time, type the following command −

sudo chkservice enable <unit name>

For example, to enable the Apache web server to start automatically at boot time, you can type −

sudo chkservice enable apache2

To disable a systemd unit from starting automatically at boot time, type the following command −

sudo chkservice disable <unit name>

For example, to disable the Apache web server from starting automatically at boot time, you can type −

sudo chkservice disable apache2

Restarting Systemd Units

To restart a systemd unit, type the following command −

sudo chkservice restart <unit name>

For example, to restart the Apache web server, you can type −

sudo chkservice restart apache2

Reloading Systemd Units

To reload a systemd unit, type the following command −

sudo chkservice reload <unit name>

For example, to reload the Apache service, you would use −

sudo chkservice reload apache2sudo chkservice reload apache2

Managing Sysvinit Scripts

In addition to managing systemd units, chkservice can also be used to manage sysvinit scripts. Sysvinit is an older system initialization mechanism used on some Linux distributions.

To manage a sysvinit script using chkservice, you can use the same commands as you would for a systemd unit. For example, to start a sysvinit script, you would use the following command −

sudo chkservice start script-name

To stop a sysvinit script, you would use the following command −

sudo chkservice stop script-name

To check the status of a sysvinit script, you would use the following command −

sudo chkservice status script-name

You can also enable and disable sysvinit scripts with chkservice −

sudo chkservice enable script-name
sudo chkservice disable script-name

Chkservice also supports tab completion, making it easy to use. When you start typing a command, you can press the Tab key to auto-complete the command or show a list of available options.

In addition to managing systemd units and sysvinit scripts, chkservice also allows you to view the logs for a particular unit. To view the logs for a unit, you can use the following command −

sudo chkservice logs unit-name

This will show the logs for the specified unit in your terminal.

Conclusion

Chkservice is a useful tool for managing systemd units and sysvinit scripts in Linux. It provides an easy-to-use command-line interface for starting, stopping, enabling, disabling, and checking the status of units. Additionally, it supports tab completion and allows you to view the logs for a particular unit. If you're a Linux user who frequently works with systemd units or sysvinit scripts, chkservice is definitely worth exploring.

Updated on: 22-Jun-2023

76 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements