pythonスクリプトをサービスとして実行
/etc/systemd/system/において以下のファイルを置く
code:aiueo.service
Description=web server monitor
WorkingDirectory=/aiueo
User=<user>
ExecStart=/home/<user>/heartbeat.py
Restart=always
WantedBy=multi-user.target
Userがないとmodulenotfoundになる
sudo systemctl daemon-reload
sudo systemctl start aiueo.serviceで起動
sudo systemctl enable aiueo.serviceで自動起動
確認はsudo systemctl status aiueo.service
参考