coding-memo/memo/make-systemd.md
2025-03-14 16:37:13 +09:00

791 B

  1. Open new service file:
sudo nano /etc/systemd/system/<name>.service
  1. Content
[Unit]
Description=Page Host Service
After=network.target

[Service]
User=your_username
WorkingDirectory=/home/your_username/repo/asobi
Environment=PYENV_ROOT=/home/your_username/.pyenv
ExecStart=/bin/bash -c "source $PYENV_ROOT/bin/pyenv && pyenv activate pyenv && python page_host.py"
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target
  1. Reload systemd, enable service:
sudo systemctl daemon-reload
sudo systemctl enable <name>.service
sudo systemctl start <name>.service
  1. Check status:
sudo systemctl status <name>.service
journalctl -u <name>.service
  1. Test reboot:
sudo reboot

Check status

sudo systemctl status page_host.service