systemctl is the main tool for managing services on most modern Linux VPS distributions. It controls services managed by systemd, including web servers, databases, bots, game-server daemons, monitoring tools, and custom services you create yourself.

In the examples below, replace nginx with the service you are managing. Common service names include nginx, apache2, mariadb, mysql, docker, sshd, and custom names such as arkserver or discordbot.

 

Check a service

Use status before restarting a service. It shows whether the service is running, whether it is enabled on boot, and recent error output.

sudo systemctl status nginx

The screenshot below uses the SSH service as an example; the same output layout applies to other systemd services.

Ubuntu VPS terminal showing systemctl status output for the SSH service

If the output says failed, read the error lines before repeatedly restarting it.

You can also view logs with journalctl:

sudo journalctl -u nginx --since "30 minutes ago"

Follow live logs while you restart or test the service:

sudo journalctl -u nginx -f

 

Start, stop, restart, and reload

CommandWhat it does
sudo systemctl start nginxStarts a stopped service.
sudo systemctl stop nginxStops a running service.
sudo systemctl restart nginxStops and starts the service again.
sudo systemctl reload nginxReloads config without a full restart, if the service supports reloads.
sudo systemctl reload-or-restart nginxReloads if possible, otherwise restarts.

Use reload when you only changed a config file and the service supports it. Use restart when the application needs a full stop/start to pick up changes.

 

Enable or disable startup on boot

Starting a service now and enabling it on boot are different actions. If you want a service to come back after a VPS reboot, enable it.

sudo systemctl enable nginx
sudo systemctl start nginx

To enable and start it in one command:

sudo systemctl enable --now nginx

To stop it starting automatically on boot:

sudo systemctl disable nginx

 

Restart multiple services

You can pass more than one service name to many systemctl commands:

sudo systemctl restart nginx php8.2-fpm mariadb

This is useful after changing a stack where multiple services depend on each other, such as a web server, PHP-FPM, and database.

 

Using wildcards

systemctl can match service names with wildcards. This is useful, but use it carefully because it can affect more services than you intended.

For example, this shows all matching PHP-FPM services:

systemctl list-units 'php*-fpm.service'

After checking the matches, you can restart matching services:

sudo systemctl restart 'php*-fpm.service'

Always list the matches first before using a wildcard with restart, stop, or disable.

 

Create a custom service

You can create a custom systemd service for a game server, bot, or script so it starts on boot and can be managed with systemctl.

Create a unit file in /etc/systemd/system/:

sudo nano /etc/systemd/system/myserver.service

A simple service file looks like this:

[Unit]
Description=My custom server
After=network.target

[Service]
Type=simple
User=myuser
WorkingDirectory=/home/myuser/myserver
ExecStart=/home/myuser/myserver/start.sh
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target

After creating or changing a service file, reload systemd so it sees the new unit:

sudo systemctl daemon-reload

Then enable and start it:

sudo systemctl enable --now myserver

Check it with:

sudo systemctl status myserver
sudo journalctl -u myserver -f

If the service fails, check the path in ExecStart, the User, file permissions, and whether the startup script runs manually before trying to run it through systemd.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to connect to a Linux VPS with SSH

SSH is the normal way to manage a Linux VPS. It gives you a terminal on the server so you can...

How to update packages on a Linux VPS

Keeping packages updated helps patch security issues and keeps server tools compatible. Run...

How to create a sudo user on a Linux VPS

A sudo user lets you manage a Linux VPS without logging in as root for every task. This is safer...

How to secure SSH on a Linux VPS

SSH is the main way to manage a Linux VPS, so it should be secured before the server is used for...

How to check disk usage on a Linux VPS

Disk usage issues can stop updates, backups, logs, databases, and game saves from writing...