読者です 読者をやめる 読者になる 読者になる

DELAEMON BLOG

Live as if you were to die tomorrow. Learn as if you were to live forever.

phoenix app using systemd on fedora22(GMO Conoha)

.serviceファイルを作る

[root@host ~]# touch /usr/lib/systemd/system/phoenix.service
[root@host ~]# vim /usr/lib/systemd/system/phoenix.service
[root@host ~]# cat /usr/lib/systemd/system/phoenix.service
[Unit]
Description = hello phoenix

[Service]
EnvironmentFile=/etc/environments/phoenix
WorkingDirectory=/home/dela/www/hello/
ExecStart = /usr/local/src/elixir-1.1.1/bin/elixir -pa _build/prod/consolidated -S /usr/local/src/elixir-1.1.1/bin/mix phoenix.server
Restart = always
Type = simple
User = dela

[Install]
WantedBy = multi-user.target

環境変数もファイルへ記述

[root@host ~]# mkdir /etc/environments/
[root@host ~]# vim /etc/environments/phoenix
[root@host ~]# cat /etc/environments/phoenix
MIX_ENV=prod
PORT=4001

serviceが認識されているか確認

[root@host ~]# systemctl list-unit-files --type=service | grep phoenix
phoenix.service                             disabled

自動起動に登録

[root@host ~]# sudo systemctl enable phoenix
Created symlink from /etc/systemd/system/multi-user.target.wants/phoenix.service to /usr/lib/systemd/system/phoenix.service.
[root@host ~]# systemctl list-unit-files --type=service | grep phoenix
phoenix.service                             enabled

デーモン起動

[root@host ~]# sudo systemctl start phoenix