Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Services

To start a service: service httpd start


Newer method to do the same: systemctl start httpd
To stop service: systemctl stop httpd
Check status of service: systemctl status httpd
To configure service to start at startup: systemctl enable httpd
To configure service not to start at startup: systemctl disable httpd

To configure a program as a service, we must create a file inside /etc/systemd/system called like this: my_app.service .
Inside it, we can write something like this:

[Unit]
Description=My python web application

[Service]
ExecStart=/usr/bin/python3 /opt/code/my_app.py
# Executed before ExecStart
ExecStartPre=/opt/code/configure_db,sh
# Executed after ExecStart
ExecStartPost=/opt/code/email_status.sh
Restart=always

# This allows the program to be executed on boot up


# so we can run systemctl enable my_app
[Install]
WantedBy=multi-user.target

Now we can say to systemctl that there is a new service: systemctl daemon-reload . Finally, we can start the service like this:
systemctl start my_app .

You might also like