How to Start Stop Restart Services in Linux VPS

Start, Stop, Restart Services in Linux VPS – systemctl

On a Linux VPS, systemd acts as the init system, orchestrating the background processes that keep everything running.

These processes, called services, handle crucial tasks like web serving, databases, and firewalls. systemd is responsible for starting, stopping, and managing these services.

systemctl is your command-line tool for managing services on a Linux VPS to start, stop, restart, enable, and disable services for centralized control and efficient resource management.

Here is the main syntax of systemctl:

sudo systemctl [command] [service_name]

To manage Linux services, you can use the below commands to Start, Stop, and Restart services:

systemctl start [service-name]

systemctl stop [service-name]

systemctl restart [service-name]

Remember to replace [service-name] in the systemctl commands with the actual service you want to manage.

Prerequisites to Use Linux systemctl to Start, Stop, Restart Services

Provide the options below to let this tutorial work correctly and move on.

  • A Server running Linux VPS.
  • A non-root user with sudo privileges.
  • Access to the Terminal/Command line.

How to Manage Services in Linux VPS using systemctl

systemctl is the modern way to manage services on Linux VPS using systems.

It offers more features than the older service command, which is still available for compatibility with legacy systems.

Let’s start to check how to start, stop, and restart services on Linux VPS using the systemctl command.

First, you can use the command below to list all the services and view the services available on your Linux system:

systemctl list-unit-files --type service -all

This is also helpful when you do not remember the exact service name.

This command will display a list of all system services, indicating enabled (+) and disabled (-) services.

Using systemctl list-units with grep command lets you filter and see only running services on your system:

sudo systemctl | grep running

To check the status of a specific service, here is the main syntax:

systemctl status [service_name]

Start a Service on Linux VPS

Run the command below to start a service in Linux:

sudo systemctl start [service-name]

For example, you can check if the MySQL service is active and start it by running:

sudo systemctl status mysql
sudo systemctl start mysql

To enable MySQL to start when the system boots. run:

sudo systemctl enable mysql

Stop a Service on Linux VPS

Active services could be stopped by using the below command:

sudo systemctl stop [service-name]

For example, use the following command to stop MySQL:

sudo systemctl stop mysql

To prevent the service from starting on boot and keep it inactive, type:

sudo systemctl disable mysql

Restart a Service on Linux VPS

To restart the service in Linux, run the command below:

sudo systemctl restart [service-name]

For example, running the following command restarts MySQL:

sudo systemctl restart mysql

Reload a Service on Linux VPS

Reloading a service refreshes its configuration while running, unlike restarting, which completely stops and restarts it.

Use the command below to reload a service:

sudo systemctl reload [service-name]

For example, to reload MySQL, type:

sudo systemctl reload mysql

Then, you can use the below command to check if the service is active:

sudo systemctl status mysql

That’s it! Since typos can lead to unexpected behavior, always double-check the service name.

What’s the difference between restarting and reloading a service?

Restarting a service completely stops and then restarts it, while reloading a service refreshes its configuration files without stopping the service.

Use restarting for applying major changes or troubleshooting, and reloading for configuration updates while the service is running.

Why does Linux VPS Service Management matter?

Managing services on your VPS is essential for several reasons:

Maintaining Stability: A healthy system relies on services running smoothly. Restarting a malfunctioning service can often get things back on track quickly.

Troubleshooting Issues: If you encounter unexpected behavior, stopping a service can help isolate the problem.

Deployment and Updates: When deploying new applications or updates to existing services, restarting them ensures the changes take effect.

Resource Management: Stopping unused services frees up valuable system resources like memory and CPU.

Why service is Not Starting despite using systemctl start?

There could be several reasons. Check the service’s status with systemctl status to see any error messages. You can also look at the service’s logs for clues.

How to enable/disable a service to automatically start at boot?

Use sudo systemctl enable <service_name> to enable and sudo systemctl disable <service_name> to disable automatic startup.

Conclusion

The systemctl empowers you to effectively manage services on your Linux VPS.

By mastering these commands, you gain control over your system’s functionality, ensuring smooth operation, efficient resource allocation, and a streamlined troubleshooting process.

Remember, consistent practice and exploration of additional systemctl options will further solidify your VPS administration skills.

Leave a Reply

Your email address will not be published. Required fields are marked.