pipenv プロジェクトのサービス化

www.instrumedley.net

つづきです。


環境

$ cat /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core) 

$ uname -r
3.10.0-862.9.1.el7.x86_64

$ which python
/bin/python

$ python -V
Python 2.7.5


systemd サービスユニットの設定ファイル作成

# cat <<EOF >/etc/systemd/system/test.service 
[Unit]
Description=Pipenv Test
After=network.target

[Service]
Type=simple
Restart=always
WorkingDirectory=/home/testuser/blue
ExecStart=/home/testuser/.local/bin/pipenv run python server.py
User=testuser
Group=testuser

[Install]
WantedBy=multi-user.target
EOF


サービスの有効化と起動

# sysetmctl daemon-reload
# systemctl list-unit-files --type=service | grep test.service
test.service                                  disabled
# systemctl enable test
Created symlink from /etc/systemd/system/multi-user.target.wants/test.service to /etc/systemd/system/test.service.
# systemctl start test
$ curl 127.0.0.1:8000
Hello World