我正在尝试/run/gunicorn为一些 Gunicorn 套接字/PID 文件创建一个运行时文件夹,这些文件用于 Django 应用程序。如果我手动创建目录,我可以让一切正常。但是,我正在尝试使其成为一个健壮的设置,并最终使用 Ansible 来自动化一切。
我想我有 2 个选项,基于这个问题。
选项 1 - 运行时目录
我认为第一个选项是RuntimeDirectory=在我的 systemd 服务文件中使用,但我无法使用它来创建文件夹。服务文件包含:
#/etc/systemd/system/gunicorn_django_test.service
[Unit]
Description=gunicorn_django daemon
After=network.target
[Service]
User=gunicorn
Group=www-data
RuntimeDirectory=gunicorn #This line is supposed to create a directory
RuntimeDirectoryMode=755
PIDFile=/run/gunicorn/django_test_pid
WorkingDirectory=/vagrant/webapps/django_venv/django_test
ExecStart=/vagrant/webapps/django_venv/bin/gunicorn --pid /run/gunicorn/django_test_pid --workers 3 --bind unix:/run/gunicorn/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
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
当我运行时systemctl start gunicorn_django_test.service,服务无法启动。当我剪掉 exec 行并手动运行它时,我得到Error: /run/gunicorn doesn't exist. Can't create pidfile.如果我 …