How to automatically create a runtime folder with a systemd service or tmpfiles.d?
I added in PermissionsStartOnly=True
and set a runtime folder per service, as suggested. I also added 0
to the start of the folder mode.
[Unit]
Description=gunicorn_django daemon
After=network.target
[Service]
PermissionsStartOnly=True
User=gunicorn
Group=www-data
RuntimeDirectory=gunicorn_django
RuntimeDirectoryMode=0775
PIDFile=/run/gunicorn_django/django_test_pid
WorkingDirectory=/vagrant/webapps/django_venv/django_test
ExecStart=/vagrant/webapps/django_venv/bin/gunicorn --pid /run/gunicorn_django/django_test_pid --workers 3 --bind unix:/run/gunicorn_django/django_test_socket django_test.wsgi --error-logfile /var/log/gunicorn/django_test_error.log
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
It's now creating a folder with the correct permissions.
drwxrwxrw- 2 gunicorn www-data 40 Mar 30 07:11 gunicorn_django/
Thanks @quixotic and @mark-stosberg