前提
| 項目 | 内容 |
|---|---|
| OS | Raspbian GNU/Linux 9.4 (stretch) |
| ホスト名 | raspberrypi.local |
| ユーザー | pi |
| nvm | 0.33.11 |
| Node.js | v10.6.0 |
Unitファイルのサンプル
/etc/systemd/system/google-home-notifier.service
[Unit]
Description=Google Home Notifier
After=syslog.target network-online.target
[Service]
Type=simple
Restart=on-failure
RestartSec=10
KillMode=control-group
Environment=NODE_VERSION=10
User=pi
WorkingDirectory=/home/pi/app/google-home-notifier
ExecStart=/home/pi/.nvm/nvm-exec node example.js
[Install]
WantedBy=multi-user.target
使用方法
有効化(enable)すると、OS起動時に起動されるようになる。
| 目的 | コマンド |
|---|---|
| 有効化 | sudo systemctl enable google-home-notifier.service |
| 無効化 | sudo systemctl disable google-home-notifier.service |
| 起動 | sudo systemctl start google-home-notifier.service |
| 停止 | sudo systemctl stop google-home-notifier.service |
| 再起動 | sudo systemctl restart google-home-notifier.service |
| ステータス確認 | sudo systemctl status google-home-notifier.service |
補足
nvm-exec
環境変数 NODE_VERSION を指定して、nvm-exec 経由で実行する。
KillMode=control-group
付属の example.js は内部で ngrok を使用している。KillMode=process だと stop したときに ngrok のプロセスが残ってしまう。
起動されているプロセスは sudo systemctl status google-home-notifier.service で確認できる。
