Skip to main content

How to manage services and processes in Linux

Websites, databases, dashboards, and game servers typically run as services or processes. Knowing how to check status and logs helps you fix failures without restarting the entire VPS.

What is a service?

On distributions with systemd, a service can start automatically, restart after failure, and log to the Journal.

Common examples include nginx, apache2, mysql, docker, and ssh.

1. Check status

sudo systemctl status NOME_DO_SERVICO

Example:

sudo systemctl status nginx

Press q to exit.

2. Start or stop

Start:

sudo systemctl start NOME_DO_SERVICO

Stop:

sudo systemctl stop NOME_DO_SERVICO

Stopping a service stops the application. Evaluate logged in users and ongoing tasks.

3. Restart or Reload

Restart:

sudo systemctl restart NOME_DO_SERVICO

Reload configuration without restarting the process, when supported:

sudo systemctl reload NOME_DO_SERVICO

Not all services support reloading. Consult the application documentation.

4. Configure startup

Activate on boot:

sudo systemctl enable NOME_DO_SERVICO

Activate and start now:

sudo systemctl enable --now NOME_DO_SERVICO

Disable on boot:

sudo systemctl disable NOME_DO_SERVICO

This does not automatically stop a service that is already running.

5. List services

Running:

systemctl list-units --type=service --state=running

Failed:

systemctl --failed

Installed files:

systemctl list-unit-files --type=service

6. Consult the logs

Last lines:

sudo journalctl -u NOME_DO_SERVICO -n 100 --no-pager

From today:

sudo journalctl -u NOME_DO_SERVICO --since today

Monitor in real time:

sudo journalctl -u NOME_DO_SERVICO -f

Use Ctrl + C to exit.

7. List processes

ps aux --sort=-%cpu | head
ps aux --sort=-%mem | head

Search by name:

pgrep -a NOME_DO_PROCESSO

You can also use htop to monitor resources.

8. End a stuck process

First request graceful termination:

sudo kill -15 PID

Wait and check. Only as a last resort:

sudo kill -9 PID

Signal 9 does not allow the process to save data or terminate tasks. For applications managed by systemd, prefer systemctl stop or restart.

Service restarts and fails again

Check it out:

  1. Journal logs;
  2. configuration syntax;
  3. busy ports;
  4. file permissions;
  5. disk space;
  6. available memory;
  7. dependencies and environment variables.

Do not repeat restarts without analyzing the cause.

Frequently asked questions

What is the difference between service and process?

Process is a running instance. Service is a managed unit, which can start and supervise one or more processes.

Are restart and reload the same?

No. Restart stops and starts again. Reload asks the service to re-read the configuration without a full restart, when supported.

Do I need to restart the VPS to apply a configuration?

Generally not. Validate the configuration and restart or reload only the related service.


If you need help, open a ticket with Nice Hosting support.