/etc/systemd/system/djangoexample-boot.service
[Unit]
Description=Service for django.example.com
Before=nginx.service
StartLimitIntervalSec=0
[Service]
Type=simple
User=root
KillMode=process
Restart=on-failure
ExecStart=/bin/bash -c "echo 'script started' \
&& echo "Activating venv.." \
&& source /opt/django.example.com/venv/bin/activate \
&& python -V \
&& uwsgi --chdir=/opt/django.example.com/src \
--module=djangoexample.wsgi:application \
--env DJANGO_SETTINGS_MODULE=djangoexample.settings \
--master \
--pidfile=/tmp/django.example.com-master.pid \
--http=localhost:8000 \
--processes=5 \
--harakiri=20 \
--max-requests=5000 \
--vacuum \
--daemonize=/var/log/uwsgi/django.example.com.log \
&& echo 'Deactivating venv..' \
&& deactivate \
&& echo 'Terminating service..' \
&& systemctl stop djangoexample-boot.service"
[Install]
WantedBy=multi-user.target
KillMode=process
- Kill only the main process, this will prevent the child processes (uWSGI daemon process in our case) to from being killed. See https://www.freedesktop.org/software/systemd/man/systemd.kill.html#.
$ systemctl start djangoexample-boot.service
$ systemctl enable djangoexample-boot.service