coding-memo/memo/systemctl-enable.md
2025-07-01 23:54:05 +09:00

35 lines
842 B
Markdown

# Create a Systemd Service File
1. Create a Service File:
- Create a new service file to manage page_host.py:
```bash
sudo nano /etc/systemd/system/page_host.service
```
2. Add the following configuration to manage the script:
```bash
[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
```
3. Enable the service to start at boot:
```bash
sudo systemctl enable page_host
```
Start the service:
```bash
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