1.8 KiB
Systemd Services
What is a service
A service is a program or script that runs in the background and is managed by the system. Services are started at boot time and run until the system is shut down. Services can be started, stopped, and restarted by the system administrator.
How to manage services on systemD
Starting a service
To start a service, use the systemctl start
command followed by the service name. For example, to start the apache2
service, use the following command:
sudo systemctl start apache2
Stopping a service
To stop a service, use the systemctl stop
command followed by the service name. For example, to stop the apache2
service, use the following command:
sudo systemctl stop apache2
Restarting a service
To restart a service, use the systemctl restart
command followed by the service name. For example, to restart the apache2
service, use the following command:
sudo systemctl restart apache2
Enabling a service
To enable a service to start at boot time, use the systemctl enable
command followed by the service name. For example, to enable the apache2
service, use the following command:
sudo systemctl enable apache2
Creating a new service
To create a new service, you need to create a new service file in the /etc/systemd/system/
directory. The service file should have a .service
extension and contain the following sections:
Example service file:
[Unit]
Description=FlaskApp #description of the service
After=network.target #start the service after the network is up
[Service]
User=ishak #start the service as a specific user
WorkingDirectory=/home/ishak/rooziinuubii79/src/Python/flask/web/ #working directory of the service
ExecStart=/usr/bin/gunicorn -w 3 -b 127.0.0.1:5000 app:app #command to start the service