/etc/systemd/system/
に〇〇.service
ファイルを作成する。※〇〇はなんでもいい(アプリの名前)。
[Unit] Description=Mudazero App #アプリの説明 After=network.target #ネットワークの準備ができた後 [Service] Type=simple User=debian #自分のパソコンのuser WorkingDirectory=/home/debian/mudamuda/ #アプリのダイレクトリー(pwdで調べる) Environment=RAILS_ENV=production #本番環境で動く設定 ExecStart=/bin/bash -lc 'rails s' #bashはbashrc.のバッシュの設定(pathとはrbenv)を使用するため。サーバー起動のコマンド Restart=on-failure #エラーあったらどうすれば良いかの設定 [Install] WantedBy=multi-user.target #パソコンの起動が終わった後動かす。
$ systemctl status mudazero.service
で今の状態を確認
$ systemctl status mudazero.service ○ mudazero.service - Mudazero App Loaded: loaded (/etc/systemd/system/mudazero.service; disabled; preset: enabled) Active: inactive (dead) #enable(有効)になってないという意味。
$ sudo systemctl enable mudazero.service
でenable(有効)する。
$ systemctl status mudazero.service
でもう一度確認する。
$ systemctl status mudazero.service ○ mudazero.service - Mudazero App Loaded: loaded (/etc/systemd/system/mudazero.service; enabled; preset: enabled) Active: inactive (dead)
service; enabled;
になったがまだActive: inactive (dead)
。
$ systemctl start mudazero.service
でスタート。
($ systemctl restart mudazero.service
でリスタート(設定を変更した後など))
'$ systemctl status mudazero.service'でlogや情報確認。
$ sudo journalctl -u mudazero.service
でlogのみ確認できる。
$ sudo journalctl -u mudazero.service -f
だと新しい情報のみなのでこっちの方が使いやすい。
これで完了。