nginx.service: Can't open PID file /run/nginx












0















I am on Ubuntu 18.10, running under vmware and unable to start the nginx service - I get the error "nginx.service: Can't open PID file /run/nginx".



I have compiled nginx from source using passenger. It went ok on one machine, but trying it in my vm I cannot start the nginx service. It gives the above error as it cannot open the PID file (or create it?). I have done systemctl enable & start and it hangs.



I have used the /etc/sytemd/system/nginx.service script as follows:



[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/opt/nginx/sbin/nginx -t
ExecStart=/opt/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target


I have tried substituting /var/run for /run and it gives the same error.



There is no reference to the PID in the nginx.conf (and I don't think there needs to be?).



Could anyone give me any pointers on how to troubleshoot or fix this please?










share|improve this question



























    0















    I am on Ubuntu 18.10, running under vmware and unable to start the nginx service - I get the error "nginx.service: Can't open PID file /run/nginx".



    I have compiled nginx from source using passenger. It went ok on one machine, but trying it in my vm I cannot start the nginx service. It gives the above error as it cannot open the PID file (or create it?). I have done systemctl enable & start and it hangs.



    I have used the /etc/sytemd/system/nginx.service script as follows:



    [Unit]
    Description=The NGINX HTTP and reverse proxy server
    After=syslog.target network.target remote-fs.target nss-lookup.target

    [Service]
    Type=forking
    PIDFile=/run/nginx.pid
    ExecStartPre=/opt/nginx/sbin/nginx -t
    ExecStart=/opt/nginx/sbin/nginx
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStop=/bin/kill -s QUIT $MAINPID
    PrivateTmp=true

    [Install]
    WantedBy=multi-user.target


    I have tried substituting /var/run for /run and it gives the same error.



    There is no reference to the PID in the nginx.conf (and I don't think there needs to be?).



    Could anyone give me any pointers on how to troubleshoot or fix this please?










    share|improve this question

























      0












      0








      0


      1






      I am on Ubuntu 18.10, running under vmware and unable to start the nginx service - I get the error "nginx.service: Can't open PID file /run/nginx".



      I have compiled nginx from source using passenger. It went ok on one machine, but trying it in my vm I cannot start the nginx service. It gives the above error as it cannot open the PID file (or create it?). I have done systemctl enable & start and it hangs.



      I have used the /etc/sytemd/system/nginx.service script as follows:



      [Unit]
      Description=The NGINX HTTP and reverse proxy server
      After=syslog.target network.target remote-fs.target nss-lookup.target

      [Service]
      Type=forking
      PIDFile=/run/nginx.pid
      ExecStartPre=/opt/nginx/sbin/nginx -t
      ExecStart=/opt/nginx/sbin/nginx
      ExecReload=/bin/kill -s HUP $MAINPID
      ExecStop=/bin/kill -s QUIT $MAINPID
      PrivateTmp=true

      [Install]
      WantedBy=multi-user.target


      I have tried substituting /var/run for /run and it gives the same error.



      There is no reference to the PID in the nginx.conf (and I don't think there needs to be?).



      Could anyone give me any pointers on how to troubleshoot or fix this please?










      share|improve this question














      I am on Ubuntu 18.10, running under vmware and unable to start the nginx service - I get the error "nginx.service: Can't open PID file /run/nginx".



      I have compiled nginx from source using passenger. It went ok on one machine, but trying it in my vm I cannot start the nginx service. It gives the above error as it cannot open the PID file (or create it?). I have done systemctl enable & start and it hangs.



      I have used the /etc/sytemd/system/nginx.service script as follows:



      [Unit]
      Description=The NGINX HTTP and reverse proxy server
      After=syslog.target network.target remote-fs.target nss-lookup.target

      [Service]
      Type=forking
      PIDFile=/run/nginx.pid
      ExecStartPre=/opt/nginx/sbin/nginx -t
      ExecStart=/opt/nginx/sbin/nginx
      ExecReload=/bin/kill -s HUP $MAINPID
      ExecStop=/bin/kill -s QUIT $MAINPID
      PrivateTmp=true

      [Install]
      WantedBy=multi-user.target


      I have tried substituting /var/run for /run and it gives the same error.



      There is no reference to the PID in the nginx.conf (and I don't think there needs to be?).



      Could anyone give me any pointers on how to troubleshoot or fix this please?







      server nginx






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 days ago









      tentimestentimes

      1012




      1012






















          2 Answers
          2






          active

          oldest

          votes


















          0














          Is /run available? Can you cd into /run and touch a file?



          cd /run && touch hello.txt && ls -lash


          If not that probably means that you want nginx to put the PID file in a location that is not available. You can do 2 things;




          1. Figure out why /run is not available (probably tmpfs configuration)

          2. Put the PID file somewhere else, for example /tmp






          share|improve this answer
























          • I can do this with sudo, yes, and I see "hello.txt". When try use the PID line "PIDFile=/tmp/nginx.pid" I get the same error: "Can't open PID file /tmp/nginx.pid (yet?) after start: No such file or directory".

            – tentimes
            2 days ago











          • Interestingly, in a VPS version of this server I have been creating everything went ok. But going back to that setup I can find no nginx.service file in /etc/systemd/system or /lib/systemd/system. I am able to control the service though using systmctl. So maybe in the VPS server (also Ubuntu 18.10) I got the service working using some different method to my vm that I am currently on? It says .etc.init.d/nginx somewhere in the message for the working version, so is there a way to get this service running with init.d scripts?

            – tentimes
            2 days ago





















          0














          I have an answer in the sense of how to fix this, but I will leave it open for a bit so someone may comment on WHY this is so.



          I changed the PID line so the PID file was written to the log folder of the installed nginx folder (/opt/nginx/logs). Anwhere else and it would REFUSE to write the PID file!!!



          [Unit]
          Description=The NGINX HTTP and reverse proxy server
          After=syslog.target network.target remote-fs.target nss-lookup.target

          [Service]
          Type=forking
          PIDFile=/opt/nginx/logs/nginx.pid
          ExecStartPre=/opt/nginx/sbin/nginx -t
          ExecStart=/opt/nginx/sbin/nginx
          ExecReload=/bin/kill -s HUP $MAINPID
          ExecStop=/bin/kill -s QUIT $MAINPID
          PrivateTmp=true

          [Install]
          WantedBy=multi-user.target


          I have no idea what the reason for this behaviour is and it would be great if some Ubuntu Linux expert could tell me why it wouldn't write the PID anywhere else, including the normal run location /run and /var/run (or even tmp) for example, as is normal in all quoted startup scripts for the program. I think this only happens when it is created from source.






          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "89"
            };
            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: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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%2faskubuntu.com%2fquestions%2f1113319%2fnginx-service-cant-open-pid-file-run-nginx%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









            0














            Is /run available? Can you cd into /run and touch a file?



            cd /run && touch hello.txt && ls -lash


            If not that probably means that you want nginx to put the PID file in a location that is not available. You can do 2 things;




            1. Figure out why /run is not available (probably tmpfs configuration)

            2. Put the PID file somewhere else, for example /tmp






            share|improve this answer
























            • I can do this with sudo, yes, and I see "hello.txt". When try use the PID line "PIDFile=/tmp/nginx.pid" I get the same error: "Can't open PID file /tmp/nginx.pid (yet?) after start: No such file or directory".

              – tentimes
              2 days ago











            • Interestingly, in a VPS version of this server I have been creating everything went ok. But going back to that setup I can find no nginx.service file in /etc/systemd/system or /lib/systemd/system. I am able to control the service though using systmctl. So maybe in the VPS server (also Ubuntu 18.10) I got the service working using some different method to my vm that I am currently on? It says .etc.init.d/nginx somewhere in the message for the working version, so is there a way to get this service running with init.d scripts?

              – tentimes
              2 days ago


















            0














            Is /run available? Can you cd into /run and touch a file?



            cd /run && touch hello.txt && ls -lash


            If not that probably means that you want nginx to put the PID file in a location that is not available. You can do 2 things;




            1. Figure out why /run is not available (probably tmpfs configuration)

            2. Put the PID file somewhere else, for example /tmp






            share|improve this answer
























            • I can do this with sudo, yes, and I see "hello.txt". When try use the PID line "PIDFile=/tmp/nginx.pid" I get the same error: "Can't open PID file /tmp/nginx.pid (yet?) after start: No such file or directory".

              – tentimes
              2 days ago











            • Interestingly, in a VPS version of this server I have been creating everything went ok. But going back to that setup I can find no nginx.service file in /etc/systemd/system or /lib/systemd/system. I am able to control the service though using systmctl. So maybe in the VPS server (also Ubuntu 18.10) I got the service working using some different method to my vm that I am currently on? It says .etc.init.d/nginx somewhere in the message for the working version, so is there a way to get this service running with init.d scripts?

              – tentimes
              2 days ago
















            0












            0








            0







            Is /run available? Can you cd into /run and touch a file?



            cd /run && touch hello.txt && ls -lash


            If not that probably means that you want nginx to put the PID file in a location that is not available. You can do 2 things;




            1. Figure out why /run is not available (probably tmpfs configuration)

            2. Put the PID file somewhere else, for example /tmp






            share|improve this answer













            Is /run available? Can you cd into /run and touch a file?



            cd /run && touch hello.txt && ls -lash


            If not that probably means that you want nginx to put the PID file in a location that is not available. You can do 2 things;




            1. Figure out why /run is not available (probably tmpfs configuration)

            2. Put the PID file somewhere else, for example /tmp







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 2 days ago









            Aike de JongsteAike de Jongste

            111




            111













            • I can do this with sudo, yes, and I see "hello.txt". When try use the PID line "PIDFile=/tmp/nginx.pid" I get the same error: "Can't open PID file /tmp/nginx.pid (yet?) after start: No such file or directory".

              – tentimes
              2 days ago











            • Interestingly, in a VPS version of this server I have been creating everything went ok. But going back to that setup I can find no nginx.service file in /etc/systemd/system or /lib/systemd/system. I am able to control the service though using systmctl. So maybe in the VPS server (also Ubuntu 18.10) I got the service working using some different method to my vm that I am currently on? It says .etc.init.d/nginx somewhere in the message for the working version, so is there a way to get this service running with init.d scripts?

              – tentimes
              2 days ago





















            • I can do this with sudo, yes, and I see "hello.txt". When try use the PID line "PIDFile=/tmp/nginx.pid" I get the same error: "Can't open PID file /tmp/nginx.pid (yet?) after start: No such file or directory".

              – tentimes
              2 days ago











            • Interestingly, in a VPS version of this server I have been creating everything went ok. But going back to that setup I can find no nginx.service file in /etc/systemd/system or /lib/systemd/system. I am able to control the service though using systmctl. So maybe in the VPS server (also Ubuntu 18.10) I got the service working using some different method to my vm that I am currently on? It says .etc.init.d/nginx somewhere in the message for the working version, so is there a way to get this service running with init.d scripts?

              – tentimes
              2 days ago



















            I can do this with sudo, yes, and I see "hello.txt". When try use the PID line "PIDFile=/tmp/nginx.pid" I get the same error: "Can't open PID file /tmp/nginx.pid (yet?) after start: No such file or directory".

            – tentimes
            2 days ago





            I can do this with sudo, yes, and I see "hello.txt". When try use the PID line "PIDFile=/tmp/nginx.pid" I get the same error: "Can't open PID file /tmp/nginx.pid (yet?) after start: No such file or directory".

            – tentimes
            2 days ago













            Interestingly, in a VPS version of this server I have been creating everything went ok. But going back to that setup I can find no nginx.service file in /etc/systemd/system or /lib/systemd/system. I am able to control the service though using systmctl. So maybe in the VPS server (also Ubuntu 18.10) I got the service working using some different method to my vm that I am currently on? It says .etc.init.d/nginx somewhere in the message for the working version, so is there a way to get this service running with init.d scripts?

            – tentimes
            2 days ago







            Interestingly, in a VPS version of this server I have been creating everything went ok. But going back to that setup I can find no nginx.service file in /etc/systemd/system or /lib/systemd/system. I am able to control the service though using systmctl. So maybe in the VPS server (also Ubuntu 18.10) I got the service working using some different method to my vm that I am currently on? It says .etc.init.d/nginx somewhere in the message for the working version, so is there a way to get this service running with init.d scripts?

            – tentimes
            2 days ago















            0














            I have an answer in the sense of how to fix this, but I will leave it open for a bit so someone may comment on WHY this is so.



            I changed the PID line so the PID file was written to the log folder of the installed nginx folder (/opt/nginx/logs). Anwhere else and it would REFUSE to write the PID file!!!



            [Unit]
            Description=The NGINX HTTP and reverse proxy server
            After=syslog.target network.target remote-fs.target nss-lookup.target

            [Service]
            Type=forking
            PIDFile=/opt/nginx/logs/nginx.pid
            ExecStartPre=/opt/nginx/sbin/nginx -t
            ExecStart=/opt/nginx/sbin/nginx
            ExecReload=/bin/kill -s HUP $MAINPID
            ExecStop=/bin/kill -s QUIT $MAINPID
            PrivateTmp=true

            [Install]
            WantedBy=multi-user.target


            I have no idea what the reason for this behaviour is and it would be great if some Ubuntu Linux expert could tell me why it wouldn't write the PID anywhere else, including the normal run location /run and /var/run (or even tmp) for example, as is normal in all quoted startup scripts for the program. I think this only happens when it is created from source.






            share|improve this answer




























              0














              I have an answer in the sense of how to fix this, but I will leave it open for a bit so someone may comment on WHY this is so.



              I changed the PID line so the PID file was written to the log folder of the installed nginx folder (/opt/nginx/logs). Anwhere else and it would REFUSE to write the PID file!!!



              [Unit]
              Description=The NGINX HTTP and reverse proxy server
              After=syslog.target network.target remote-fs.target nss-lookup.target

              [Service]
              Type=forking
              PIDFile=/opt/nginx/logs/nginx.pid
              ExecStartPre=/opt/nginx/sbin/nginx -t
              ExecStart=/opt/nginx/sbin/nginx
              ExecReload=/bin/kill -s HUP $MAINPID
              ExecStop=/bin/kill -s QUIT $MAINPID
              PrivateTmp=true

              [Install]
              WantedBy=multi-user.target


              I have no idea what the reason for this behaviour is and it would be great if some Ubuntu Linux expert could tell me why it wouldn't write the PID anywhere else, including the normal run location /run and /var/run (or even tmp) for example, as is normal in all quoted startup scripts for the program. I think this only happens when it is created from source.






              share|improve this answer


























                0












                0








                0







                I have an answer in the sense of how to fix this, but I will leave it open for a bit so someone may comment on WHY this is so.



                I changed the PID line so the PID file was written to the log folder of the installed nginx folder (/opt/nginx/logs). Anwhere else and it would REFUSE to write the PID file!!!



                [Unit]
                Description=The NGINX HTTP and reverse proxy server
                After=syslog.target network.target remote-fs.target nss-lookup.target

                [Service]
                Type=forking
                PIDFile=/opt/nginx/logs/nginx.pid
                ExecStartPre=/opt/nginx/sbin/nginx -t
                ExecStart=/opt/nginx/sbin/nginx
                ExecReload=/bin/kill -s HUP $MAINPID
                ExecStop=/bin/kill -s QUIT $MAINPID
                PrivateTmp=true

                [Install]
                WantedBy=multi-user.target


                I have no idea what the reason for this behaviour is and it would be great if some Ubuntu Linux expert could tell me why it wouldn't write the PID anywhere else, including the normal run location /run and /var/run (or even tmp) for example, as is normal in all quoted startup scripts for the program. I think this only happens when it is created from source.






                share|improve this answer













                I have an answer in the sense of how to fix this, but I will leave it open for a bit so someone may comment on WHY this is so.



                I changed the PID line so the PID file was written to the log folder of the installed nginx folder (/opt/nginx/logs). Anwhere else and it would REFUSE to write the PID file!!!



                [Unit]
                Description=The NGINX HTTP and reverse proxy server
                After=syslog.target network.target remote-fs.target nss-lookup.target

                [Service]
                Type=forking
                PIDFile=/opt/nginx/logs/nginx.pid
                ExecStartPre=/opt/nginx/sbin/nginx -t
                ExecStart=/opt/nginx/sbin/nginx
                ExecReload=/bin/kill -s HUP $MAINPID
                ExecStop=/bin/kill -s QUIT $MAINPID
                PrivateTmp=true

                [Install]
                WantedBy=multi-user.target


                I have no idea what the reason for this behaviour is and it would be great if some Ubuntu Linux expert could tell me why it wouldn't write the PID anywhere else, including the normal run location /run and /var/run (or even tmp) for example, as is normal in all quoted startup scripts for the program. I think this only happens when it is created from source.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered yesterday









                tentimestentimes

                1012




                1012






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Ask Ubuntu!


                    • 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%2faskubuntu.com%2fquestions%2f1113319%2fnginx-service-cant-open-pid-file-run-nginx%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

                    迪纳利

                    How did Captain America manage to do this?

                    南乌拉尔铁路局