hubotをデーモン化するだけならsystemdだけでよかった


この前の記事で、hubotでforeverから立ち上げたんですけど、
「それsingleプロセスで立ち上げるならRestart=alwaysにするだけでいいよ」とのコメントを頂いたのでやってみました。

結論から言うと /etc/systemd/system/ に .service ファイルを作ればいいです。( .serviceファイルをユニットというみたいです)

前回の記事で書いたのと同様、上記の場所に適当に .service ファイルを作りましょう。

[Unit]
Description=Hubot 

[Service]
Type = simple
Restart=always
WorkingDirectory=/root/hubot/
ExecStart=sh bin/hubot
ExecStop=/bin/kill $MAINPID
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
systemctl start hogehoge
systemctl status hogehoge
systemctl restart hogehoge
systemctl stop hogehoge

めっちゃ簡単ですね(๑•̀ㅂ•́)و✧

書式についてはこちらが参考になりそうです。
- Systemd入門(4) - serviceタイプUnitの設定ファイル - めもめも
- Systemd メモ書き - Qiita