How to reload or restart a systemd service?
How to reload or restart a systemd service?
Use the systemctl command with the 'reload' or 'restart' subcommand, followed by the service.
Systemd service units can be restarted with systemctl. There are three subcommands available to restart a service:
- reload
- restart
- reload-or-restart
- try-reload-or-restart
Reload: systemctl reload
Some services support reloading its configuration, typically without the need to fully restart. For example, a web server service like nginx does support this. In this case, a simple reload is enough.
systemctl reload nginx.service
Not sure if a reload is possible? With subcommand show we can query the relevant property ExecReload from a service.
# systemctl show --property ExecReload --value nginx.service
{ path=/bin/kill ; argv[]=/bin/kill -s HUP $MAINPID ; ignore_errors=no ; start_time=[Mon 2024-12-09 04:31:45 EST] ; stop_time=[Mon 2024-12-09 04:31:45 EST] ; pid=4050588 ; code=exited ; status=0 }
Restart: systemctl restart
If reloading is not enough, or the service does not support it, then a restart is required. This will effectively stop and start the service unit.
systemctl restart nginx.service
Reload or restart
A hybrid option is to first reload the service. If that is not supported, then the service will be instructed to do a normal restart. This is achieved using the reload-or-restart subcommand.
systemctl reload-or-restart nginx.service
Try a reload or restart
For scripting purposes, the try-reload-or-restart subcommand will attempt to take the reload and restart action. If the service is not running, then no action will be performed.
systemctl try-reload-or-restart nginx.service