How to automatically create a runtime folder with a systemd service or tmpfiles.d?systemd: permission issue...

Polygons crash kernel?

Gödel's paradox: Why is "a proof that some universal statement is unprovable" not a valid proof that this statement is true?

Why does the friction act on the inward direction when a car makes a turn on a level road?

How to handle many times series?

What is Albrecht Dürer's Perspective Machine drawing style?

In a KP-K endgame, if the enemy king is in front of the pawn, is it always a draw?

Does WSL2 runs Linux in a virtual machine or alongside windows Kernel?

A wiild aanimal, a cardinal direction, or a place by the water

Different answers of calculations in LuaLaTeX on local computer, lua compiler and on overleaf

Meaning of ギャップ in the following sentence

Is Norway in the Single Market?

Can't understand an ACT practice problem: Triangle appears to be isosceles, why isn't the answer 7.3~ here?

Reasons for using monsters as bioweapons

What printing process is this?

Generate random number in Unity without class ambiguity

Why did the United States not resort to nuclear weapons in Vietnam?

Why do my fried eggs start browning very fast?

Have you been refused entry into the Federal Republic of Germany?

Approximating an expression for a potential

On the expression "sun-down"

What exactly is Rhumb-line control in the context of a launch trajectory?

Astable 555 circuit not oscillating

What does Argus Filch specifically do?

Pronouns when writing from the point of view of a robot



How to automatically create a runtime folder with a systemd service or tmpfiles.d?


systemd: permission issue with mkdir & ExecStartPreWhat's the best way to have uwsgi create a '/run/uwsgi' folder on reboot?How do I start service in systemd right after cryptsetup?Self-restarting service does not restart with systemdMake systemd reload only single openvpn process and not the whole groupsystemd and OpenVPN woes after an Ubuntu upgradeHow to restart systemd service after files update under Gunicorn server?On-demand SSH Socks proxy through systemd user units with socket-activation doesn't restart as wishedWhy is systemd stopping service immediately after it is started?Confusing systemd behaviour with OnFailure= and Restart=Stopping systemd unit together with another. Starting worksSetting up Apache Superset as a Systemd Service






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







6















I'm trying to create a runtime folder at /run/gunicorn for some Gunicorn socket / PID files, which are for a Django application. I can get everything working if I manually create directories. However, I'm trying to make this a robust setup, and eventually use Ansible to automate everything.



I think I have 2 options, based on this question.



Option 1 - RuntimeDirectory



I think the first option is to use RuntimeDirectory= within my systemd service file, but I can't get it to create the folder. The service files contains:



#/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


When I run systemctl start gunicorn_django_test.service, the service fails to start. When I snip out the exec line, and run it manually, I get Error: /run/gunicorn doesn't exist. Can't create pidfile. If I create the /run/gunicorn folder manually, I can get things to work.



Option 2 - tmpfiles.d



The second option is to use tmpfiles.d to have a folder created on boot, ready for the pid / socket files. I've tried this file:



#/etc/tmpfiles.d/gunicorn.conf
d /run/gunicorn 0755 gunicorn www-data -


This creates a directory, but it is quicklydeleted somehow, and by the time I start the service, the folder isn't available.



I can manually add some PreExec mkdir commands into the service file, but I'd like to get to the bottom of why RuntimeDirectory / tmpfiles.d aren't working. Thanks.



Versions / Info:
Ubuntu 16.04 Server / systemd 229 / Gunicorn 19.7.1 / runtime dir = /run










share|improve this question






















  • 1





    It's something to do with group permissions in the /run/ folder. I can create a 0755 folder with the group as www-data, but I need the folder to be group writeable, so both the Nginx user and the Gunicorn user can access the socket file. In order to do that, I need sudo-level permissions. For some reason, sudo systemctl... etc isn't passing the sudo permissions to the service.

    – geonaut
    Mar 29 '17 at 15:47






  • 2





    i'll bet it's trying to create the directory with the uid from User= and failing. try adding PermissionsStartOnly=true. see unix.stackexchange.com/a/207493/222377

    – quixotic
    Mar 29 '17 at 17:07











  • hmm. actually i'll bet it's failing because the runtime directory is made but isn't /run/gunicorn. it's probably $XDG_RUNTIME_DIR/gunicorn which might resolve to /run/user/$UID/gunicorn for the gunicorn user UID. (same question, next answer.)

    – quixotic
    Mar 29 '17 at 17:16











  • Are you trying to use the same directory for multiple Gunicorn instances? You could be running into this related issue>

    – Mark Stosberg
    Mar 29 '17 at 17:22











  • Your Option 2 would have worked. However, the tmpfiles.d and RuntimeDirectory=... definitions are not compatible. You should not have both turned on at the same time.

    – Alexis Wilke
    Oct 26 '18 at 8:02


















6















I'm trying to create a runtime folder at /run/gunicorn for some Gunicorn socket / PID files, which are for a Django application. I can get everything working if I manually create directories. However, I'm trying to make this a robust setup, and eventually use Ansible to automate everything.



I think I have 2 options, based on this question.



Option 1 - RuntimeDirectory



I think the first option is to use RuntimeDirectory= within my systemd service file, but I can't get it to create the folder. The service files contains:



#/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


When I run systemctl start gunicorn_django_test.service, the service fails to start. When I snip out the exec line, and run it manually, I get Error: /run/gunicorn doesn't exist. Can't create pidfile. If I create the /run/gunicorn folder manually, I can get things to work.



Option 2 - tmpfiles.d



The second option is to use tmpfiles.d to have a folder created on boot, ready for the pid / socket files. I've tried this file:



#/etc/tmpfiles.d/gunicorn.conf
d /run/gunicorn 0755 gunicorn www-data -


This creates a directory, but it is quicklydeleted somehow, and by the time I start the service, the folder isn't available.



I can manually add some PreExec mkdir commands into the service file, but I'd like to get to the bottom of why RuntimeDirectory / tmpfiles.d aren't working. Thanks.



Versions / Info:
Ubuntu 16.04 Server / systemd 229 / Gunicorn 19.7.1 / runtime dir = /run










share|improve this question






















  • 1





    It's something to do with group permissions in the /run/ folder. I can create a 0755 folder with the group as www-data, but I need the folder to be group writeable, so both the Nginx user and the Gunicorn user can access the socket file. In order to do that, I need sudo-level permissions. For some reason, sudo systemctl... etc isn't passing the sudo permissions to the service.

    – geonaut
    Mar 29 '17 at 15:47






  • 2





    i'll bet it's trying to create the directory with the uid from User= and failing. try adding PermissionsStartOnly=true. see unix.stackexchange.com/a/207493/222377

    – quixotic
    Mar 29 '17 at 17:07











  • hmm. actually i'll bet it's failing because the runtime directory is made but isn't /run/gunicorn. it's probably $XDG_RUNTIME_DIR/gunicorn which might resolve to /run/user/$UID/gunicorn for the gunicorn user UID. (same question, next answer.)

    – quixotic
    Mar 29 '17 at 17:16











  • Are you trying to use the same directory for multiple Gunicorn instances? You could be running into this related issue>

    – Mark Stosberg
    Mar 29 '17 at 17:22











  • Your Option 2 would have worked. However, the tmpfiles.d and RuntimeDirectory=... definitions are not compatible. You should not have both turned on at the same time.

    – Alexis Wilke
    Oct 26 '18 at 8:02














6












6








6


4






I'm trying to create a runtime folder at /run/gunicorn for some Gunicorn socket / PID files, which are for a Django application. I can get everything working if I manually create directories. However, I'm trying to make this a robust setup, and eventually use Ansible to automate everything.



I think I have 2 options, based on this question.



Option 1 - RuntimeDirectory



I think the first option is to use RuntimeDirectory= within my systemd service file, but I can't get it to create the folder. The service files contains:



#/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


When I run systemctl start gunicorn_django_test.service, the service fails to start. When I snip out the exec line, and run it manually, I get Error: /run/gunicorn doesn't exist. Can't create pidfile. If I create the /run/gunicorn folder manually, I can get things to work.



Option 2 - tmpfiles.d



The second option is to use tmpfiles.d to have a folder created on boot, ready for the pid / socket files. I've tried this file:



#/etc/tmpfiles.d/gunicorn.conf
d /run/gunicorn 0755 gunicorn www-data -


This creates a directory, but it is quicklydeleted somehow, and by the time I start the service, the folder isn't available.



I can manually add some PreExec mkdir commands into the service file, but I'd like to get to the bottom of why RuntimeDirectory / tmpfiles.d aren't working. Thanks.



Versions / Info:
Ubuntu 16.04 Server / systemd 229 / Gunicorn 19.7.1 / runtime dir = /run










share|improve this question
















I'm trying to create a runtime folder at /run/gunicorn for some Gunicorn socket / PID files, which are for a Django application. I can get everything working if I manually create directories. However, I'm trying to make this a robust setup, and eventually use Ansible to automate everything.



I think I have 2 options, based on this question.



Option 1 - RuntimeDirectory



I think the first option is to use RuntimeDirectory= within my systemd service file, but I can't get it to create the folder. The service files contains:



#/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


When I run systemctl start gunicorn_django_test.service, the service fails to start. When I snip out the exec line, and run it manually, I get Error: /run/gunicorn doesn't exist. Can't create pidfile. If I create the /run/gunicorn folder manually, I can get things to work.



Option 2 - tmpfiles.d



The second option is to use tmpfiles.d to have a folder created on boot, ready for the pid / socket files. I've tried this file:



#/etc/tmpfiles.d/gunicorn.conf
d /run/gunicorn 0755 gunicorn www-data -


This creates a directory, but it is quicklydeleted somehow, and by the time I start the service, the folder isn't available.



I can manually add some PreExec mkdir commands into the service file, but I'd like to get to the bottom of why RuntimeDirectory / tmpfiles.d aren't working. Thanks.



Versions / Info:
Ubuntu 16.04 Server / systemd 229 / Gunicorn 19.7.1 / runtime dir = /run







ubuntu systemd python socket






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 29 '17 at 15:44







geonaut

















asked Mar 29 '17 at 13:38









geonautgeonaut

1011 silver badge7 bronze badges




1011 silver badge7 bronze badges











  • 1





    It's something to do with group permissions in the /run/ folder. I can create a 0755 folder with the group as www-data, but I need the folder to be group writeable, so both the Nginx user and the Gunicorn user can access the socket file. In order to do that, I need sudo-level permissions. For some reason, sudo systemctl... etc isn't passing the sudo permissions to the service.

    – geonaut
    Mar 29 '17 at 15:47






  • 2





    i'll bet it's trying to create the directory with the uid from User= and failing. try adding PermissionsStartOnly=true. see unix.stackexchange.com/a/207493/222377

    – quixotic
    Mar 29 '17 at 17:07











  • hmm. actually i'll bet it's failing because the runtime directory is made but isn't /run/gunicorn. it's probably $XDG_RUNTIME_DIR/gunicorn which might resolve to /run/user/$UID/gunicorn for the gunicorn user UID. (same question, next answer.)

    – quixotic
    Mar 29 '17 at 17:16











  • Are you trying to use the same directory for multiple Gunicorn instances? You could be running into this related issue>

    – Mark Stosberg
    Mar 29 '17 at 17:22











  • Your Option 2 would have worked. However, the tmpfiles.d and RuntimeDirectory=... definitions are not compatible. You should not have both turned on at the same time.

    – Alexis Wilke
    Oct 26 '18 at 8:02














  • 1





    It's something to do with group permissions in the /run/ folder. I can create a 0755 folder with the group as www-data, but I need the folder to be group writeable, so both the Nginx user and the Gunicorn user can access the socket file. In order to do that, I need sudo-level permissions. For some reason, sudo systemctl... etc isn't passing the sudo permissions to the service.

    – geonaut
    Mar 29 '17 at 15:47






  • 2





    i'll bet it's trying to create the directory with the uid from User= and failing. try adding PermissionsStartOnly=true. see unix.stackexchange.com/a/207493/222377

    – quixotic
    Mar 29 '17 at 17:07











  • hmm. actually i'll bet it's failing because the runtime directory is made but isn't /run/gunicorn. it's probably $XDG_RUNTIME_DIR/gunicorn which might resolve to /run/user/$UID/gunicorn for the gunicorn user UID. (same question, next answer.)

    – quixotic
    Mar 29 '17 at 17:16











  • Are you trying to use the same directory for multiple Gunicorn instances? You could be running into this related issue>

    – Mark Stosberg
    Mar 29 '17 at 17:22











  • Your Option 2 would have worked. However, the tmpfiles.d and RuntimeDirectory=... definitions are not compatible. You should not have both turned on at the same time.

    – Alexis Wilke
    Oct 26 '18 at 8:02








1




1





It's something to do with group permissions in the /run/ folder. I can create a 0755 folder with the group as www-data, but I need the folder to be group writeable, so both the Nginx user and the Gunicorn user can access the socket file. In order to do that, I need sudo-level permissions. For some reason, sudo systemctl... etc isn't passing the sudo permissions to the service.

– geonaut
Mar 29 '17 at 15:47





It's something to do with group permissions in the /run/ folder. I can create a 0755 folder with the group as www-data, but I need the folder to be group writeable, so both the Nginx user and the Gunicorn user can access the socket file. In order to do that, I need sudo-level permissions. For some reason, sudo systemctl... etc isn't passing the sudo permissions to the service.

– geonaut
Mar 29 '17 at 15:47




2




2





i'll bet it's trying to create the directory with the uid from User= and failing. try adding PermissionsStartOnly=true. see unix.stackexchange.com/a/207493/222377

– quixotic
Mar 29 '17 at 17:07





i'll bet it's trying to create the directory with the uid from User= and failing. try adding PermissionsStartOnly=true. see unix.stackexchange.com/a/207493/222377

– quixotic
Mar 29 '17 at 17:07













hmm. actually i'll bet it's failing because the runtime directory is made but isn't /run/gunicorn. it's probably $XDG_RUNTIME_DIR/gunicorn which might resolve to /run/user/$UID/gunicorn for the gunicorn user UID. (same question, next answer.)

– quixotic
Mar 29 '17 at 17:16





hmm. actually i'll bet it's failing because the runtime directory is made but isn't /run/gunicorn. it's probably $XDG_RUNTIME_DIR/gunicorn which might resolve to /run/user/$UID/gunicorn for the gunicorn user UID. (same question, next answer.)

– quixotic
Mar 29 '17 at 17:16













Are you trying to use the same directory for multiple Gunicorn instances? You could be running into this related issue>

– Mark Stosberg
Mar 29 '17 at 17:22





Are you trying to use the same directory for multiple Gunicorn instances? You could be running into this related issue>

– Mark Stosberg
Mar 29 '17 at 17:22













Your Option 2 would have worked. However, the tmpfiles.d and RuntimeDirectory=... definitions are not compatible. You should not have both turned on at the same time.

– Alexis Wilke
Oct 26 '18 at 8:02





Your Option 2 would have worked. However, the tmpfiles.d and RuntimeDirectory=... definitions are not compatible. You should not have both turned on at the same time.

– Alexis Wilke
Oct 26 '18 at 8:02










2 Answers
2






active

oldest

votes


















7














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






share|improve this answer



































    0














    My problem was that I had two services using same RuntimeDirectory (isc-dhcp-server and isc-dhcp-server6), but I configured only one to work. So when the second one died, its runtime directory got removed, making it a problem for the first service.






    share|improve this answer




























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "106"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f354583%2fhow-to-automatically-create-a-runtime-folder-with-a-systemd-service-or-tmpfiles%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      7














      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






      share|improve this answer
































        7














        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






        share|improve this answer






























          7












          7








          7







          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






          share|improve this answer















          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







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 30 '17 at 9:54

























          answered Mar 30 '17 at 7:16









          geonautgeonaut

          1011 silver badge7 bronze badges




          1011 silver badge7 bronze badges




























              0














              My problem was that I had two services using same RuntimeDirectory (isc-dhcp-server and isc-dhcp-server6), but I configured only one to work. So when the second one died, its runtime directory got removed, making it a problem for the first service.






              share|improve this answer






























                0














                My problem was that I had two services using same RuntimeDirectory (isc-dhcp-server and isc-dhcp-server6), but I configured only one to work. So when the second one died, its runtime directory got removed, making it a problem for the first service.






                share|improve this answer




























                  0












                  0








                  0







                  My problem was that I had two services using same RuntimeDirectory (isc-dhcp-server and isc-dhcp-server6), but I configured only one to work. So when the second one died, its runtime directory got removed, making it a problem for the first service.






                  share|improve this answer













                  My problem was that I had two services using same RuntimeDirectory (isc-dhcp-server and isc-dhcp-server6), but I configured only one to work. So when the second one died, its runtime directory got removed, making it a problem for the first service.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 45 mins ago









                  MitarMitar

                  2482 silver badges6 bronze badges




                  2482 silver badges6 bronze badges

































                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f354583%2fhow-to-automatically-create-a-runtime-folder-with-a-systemd-service-or-tmpfiles%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                      Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                      Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...