デーモン化
root実行
ターミナル
sudo nano /etc/systemd/system/サービス名.service
エディタ
[Unit]
Description=<サービスの説明>
[Service]
Type=simple
ExecStart=<実行するコマンド>
Restart=always
[Install]
WantedBy=multi-user.target
ターミナル
sudo systemctl daemon-reload
sudo systemctl enable サービス名.service # 自動起動有効化
sudo systemctl restart サービス名.service # 起動
sudo systemctl status サービス名.service # 状態確認
sudo systemctl stop サービス名.service # 停止
sudo systemctl disable サービス名.service # 自動起動無効化
ユーザ実行
ターミナル
mkdir -p ~/.config/systemd/user/
nano ~/.config/systemd/user/サービス名.service
エディタ
[Unit]
Description=<サービスの説明>
[Service]
Type=simple
ExecStart=<実行するコマンド>
Restart=always
[Install]
WantedBy=default.target
ターミナル
systemctl --user daemon-reload
systemctl --user enable サービス名.service # 自動起動有効化
systemctl --user restart サービス名.service # 起動
systemctl --user status サービス名.service # 状態確認
systemctl --user stop サービス名.service # 停止
systemctl --user disable サービス名.service # 自動起動無効化