Linux

How to Start, Stop and Restart Service in Ubuntu 22.04 / 20.04

Managing services on an Ubuntu system is a crucial task for system administrators and power users. Whether we need to start, stop, or restart a service, understanding the basics of service management is essential. In this guide, we will explore various ways to accomplish these tasks with clear examples to help you navigate Ubuntu’s service ecosystem.

Suppose we have a nginx service running on the server, and we need check the service status using systemctl and service

So, let’s play with the nginx service, we can use same commands for any other service as well by just replacing nginx with the <service_name>

Start, Stop, Restart and check Status of services in Linux using Systemctl

Syntax: systemctl status <service_name>

Status of a service

sudo systemctl status nginx

Start a service

sudo systemctl start nginx

Restart a service

sudo systemctl restart nginx

Stop a service

sudo systemctl stop nginx

Start, Stop, Restart and check Status of services in Linux using Service

Syntax: service <service_name> status

sudo service nginx status
sudo service nginx start
sudo service nginx restart
sudo service nginx stop

How to list all services in Ubuntu

Execute the below command to list all the available services, regardless of whether they are running or stopped.

service --status-all

Conclusion

Managing services on Ubuntu is a fundamental skill for any system administrator or Ubuntu user. Knowing how to start, stop, and restart services can help maintain a stable and secure system. By using commands like systemctl or service, you can easily control services to ensure your Ubuntu server or desktop operates smoothly.

Remember that the specific commands may vary depending on the version of Ubuntu you are using. In modern Ubuntu versions, systemctl is the primary tool for managing services, while older versions might rely on service. Always check the documentation and manuals specific to your system for the most accurate instructions.

With these simple but essential commands, you’ll be better equipped to manage services on your Ubuntu system efficiently.