===== 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 ==== * http://www.raspberrypi-spy.co.uk/2015/10/how-to-autorun-a-python-script-on-boot-using-systemd/ * https://blog.philippklaus.de/2013/03/start-a-python-tool-or-web-app-that-uses-virtualenv-on-system-startup-using-systemd/ * https://gist.github.com/danechitoaie/f2bb03fd0c2d6b803878