842 B
842 B
Create a Systemd Service File
- Create a Service File:
- Create a new service file to manage page_host.py:
sudo nano /etc/systemd/system/page_host.service
- Add the following configuration to manage the script:
[Unit]
Description=Python page_host Service
After=network.target
[Service]
WorkingDirectory=/home/git/deployed-repo # Directory containing page_host.py
ExecStart=/usr/bin/python3 /home/git/deployed-repo/page_host.py
Restart=always
[Install]
WantedBy=multi-user.target
- Enable the service to start at boot:
sudo systemctl enable page_host
Start the service:
sudo systemctl start page_host
$ realpath /home/ec2-user/repo/aws-test-kadai3/venv/bin/python /usr/bin/python3.7 [ec2-user@ip-172-31-14-7 aws-test-kadai3]$ sudo setcap 'cap_net_bind_service=+ep' /usr/bin/python3.7