coding-memo/memo/systemctl-enable.md
2025-03-10 17:09:50 +09:00

660 B

Create a Systemd Service File

  1. Create a Service File:
  • Create a new service file to manage page_host.py:
sudo nano /etc/systemd/system/page_host.service
  1. 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
  1. Enable the service to start at boot:
sudo systemctl enable page_host

Start the service:

sudo systemctl start page_host