Managing Services with systemctl
In this lesson, you will learn how to manage system services in Linux using systemctl, a command-line utility for controlling the systemd system and service manager. Our focus will be on managing NGINX, a popular web server and reverse proxy service, using systemd.
Objectives
By the end of this lesson, you will understand how to:
- Start, stop, and restart the NGINX service.
- Enable and disable NGINX to start on boot.
- Check the status of NGINX.
- Reload NGINX configurations.
Starting, Stopping, and Restarting NGINX
Starting NGINX
To start the NGINX service immediately:
sudo systemctl start nginx
Stopping NGINX
To stop the NGINX service:
sudo systemctl stop nginx
Restarting NGINX
To restart the NGINX service (useful for reloading it with the latest configuration):
sudo systemctl restart nginx
Enabling and Disabling NGINX
Enabling NGINX
To enable NGINX to start automatically at boot:
sudo systemctl enable nginx
Disabling NGINX
To prevent NGINX from starting automatically at boot:
sudo systemctl disable nginx
Checking the Status of NGINX
To check the status of NGINX, including whether it is active, enabled, and its recent logs:
sudo systemctl status nginx
Reloading NGINX Configurations
If you've made configuration changes to NGINX and you don't want to restart the service completely, you can reload the configuration:
sudo systemctl reload nginx
Managing All Services
To list all services that systemd knows about, whether active or not:
sudo systemctl list-unit-files --type=service
Best Practices
- Always check the status of NGINX after starting, stopping, or restarting to ensure it's in the desired state.
- When enabling or disabling services like NGINX, consider the impact on the system's pe…
No comments yet. Add the first comment to start the discussion.