virtualenv service in systemd

Create a unit file:

sudo vim /etc/systemd/system/rapidsms.service

With this content (you may need change it):

[Unit]
Description=RapidSMS Virtualenv service
After=network.target

[Service]
User=emonge
Group=emonge
Environment=VIRTUAL_ENV=/home/emonge/smsbot-venv
Environment=PATH=$VIRTUAL_ENV/bin:$PATH
ExecStart=/bin/bash -c "cd /home/emonge/smsbot; $VIRTUAL_ENV/bin/python manage.py runserver 192.168.1.12:8000"
Restart=always

[Install]
WantedBy=multi-user.target

Make it executable:

sudo chmod 644 /lib/systemd/system/rapidsms.service

Reload systemd service:

sudo systemctl daemon-reload

Enable service to start during boot secuence:

sudo systemctl enable rapidsms.service

Log file

Modify the line starting with ExecStart in file /lib/systemd/system/rapidsms.service to:

ExecStart=/bin/bash -c "cd /home/emonge/smsbot; $VIRTUAL_ENV/bin/python manage.py runserver 192.168.1.12:8000 > /home/emonge/smsbot/smsbot.log 2>&1"

References

virtualenv_systemd.txt · Last modified: 2017/03/13 13:55
Public Domain Except where otherwise noted, content on this wiki is licensed under the following license: Public Domain