Systemd custom service doesn't read PATH

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I am trying to run a Node.js app as a service in Debian 9. So, following some tutorials, I've made a service like that.



[Unit]
Description=bumer API Http Server
[Service]
PIDFile=/tmp/bumer-service.pid
User=root
Group=root
Restart=always
KillSignal=SIGQUIT
WorkingDirectory=/root/bumer/
SyslogIdentifier=bumer
ExecStart=/root/bumer/app.js
[Install]
WantedBy=multi-user.target


My app has #!/usr/bin/env node as its first line and it runs pretty well if I run the command /root/bumer/app.js.
The problem is that when I start the service I was getting the following error:



main process exited, code=exited, status=127/n/a


So, I tried to change the first line of the app.js file to the node's path instead of the word "node" #!/usr/bin/env /usr/local/lib/nodejs/node-v8.11.4/bin/node and now it's running fine.
I guess the service is not reading the PATH variable and I need some help to realize why it doesn't.



(my PATH is right and when I run "type node" the result is OK).



root@bumer:~# type node
node is /usr/local/lib/nodejs/node-v8.11.4/bin/node


(I am logging the variable PORT which I set on ~/.bashrc on the app.js but it cannot read as well, it logs undefined).










share|improve this question

























    up vote
    0
    down vote

    favorite












    I am trying to run a Node.js app as a service in Debian 9. So, following some tutorials, I've made a service like that.



    [Unit]
    Description=bumer API Http Server
    [Service]
    PIDFile=/tmp/bumer-service.pid
    User=root
    Group=root
    Restart=always
    KillSignal=SIGQUIT
    WorkingDirectory=/root/bumer/
    SyslogIdentifier=bumer
    ExecStart=/root/bumer/app.js
    [Install]
    WantedBy=multi-user.target


    My app has #!/usr/bin/env node as its first line and it runs pretty well if I run the command /root/bumer/app.js.
    The problem is that when I start the service I was getting the following error:



    main process exited, code=exited, status=127/n/a


    So, I tried to change the first line of the app.js file to the node's path instead of the word "node" #!/usr/bin/env /usr/local/lib/nodejs/node-v8.11.4/bin/node and now it's running fine.
    I guess the service is not reading the PATH variable and I need some help to realize why it doesn't.



    (my PATH is right and when I run "type node" the result is OK).



    root@bumer:~# type node
    node is /usr/local/lib/nodejs/node-v8.11.4/bin/node


    (I am logging the variable PORT which I set on ~/.bashrc on the app.js but it cannot read as well, it logs undefined).










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am trying to run a Node.js app as a service in Debian 9. So, following some tutorials, I've made a service like that.



      [Unit]
      Description=bumer API Http Server
      [Service]
      PIDFile=/tmp/bumer-service.pid
      User=root
      Group=root
      Restart=always
      KillSignal=SIGQUIT
      WorkingDirectory=/root/bumer/
      SyslogIdentifier=bumer
      ExecStart=/root/bumer/app.js
      [Install]
      WantedBy=multi-user.target


      My app has #!/usr/bin/env node as its first line and it runs pretty well if I run the command /root/bumer/app.js.
      The problem is that when I start the service I was getting the following error:



      main process exited, code=exited, status=127/n/a


      So, I tried to change the first line of the app.js file to the node's path instead of the word "node" #!/usr/bin/env /usr/local/lib/nodejs/node-v8.11.4/bin/node and now it's running fine.
      I guess the service is not reading the PATH variable and I need some help to realize why it doesn't.



      (my PATH is right and when I run "type node" the result is OK).



      root@bumer:~# type node
      node is /usr/local/lib/nodejs/node-v8.11.4/bin/node


      (I am logging the variable PORT which I set on ~/.bashrc on the app.js but it cannot read as well, it logs undefined).










      share|improve this question













      I am trying to run a Node.js app as a service in Debian 9. So, following some tutorials, I've made a service like that.



      [Unit]
      Description=bumer API Http Server
      [Service]
      PIDFile=/tmp/bumer-service.pid
      User=root
      Group=root
      Restart=always
      KillSignal=SIGQUIT
      WorkingDirectory=/root/bumer/
      SyslogIdentifier=bumer
      ExecStart=/root/bumer/app.js
      [Install]
      WantedBy=multi-user.target


      My app has #!/usr/bin/env node as its first line and it runs pretty well if I run the command /root/bumer/app.js.
      The problem is that when I start the service I was getting the following error:



      main process exited, code=exited, status=127/n/a


      So, I tried to change the first line of the app.js file to the node's path instead of the word "node" #!/usr/bin/env /usr/local/lib/nodejs/node-v8.11.4/bin/node and now it's running fine.
      I guess the service is not reading the PATH variable and I need some help to realize why it doesn't.



      (my PATH is right and when I run "type node" the result is OK).



      root@bumer:~# type node
      node is /usr/local/lib/nodejs/node-v8.11.4/bin/node


      (I am logging the variable PORT which I set on ~/.bashrc on the app.js but it cannot read as well, it logs undefined).







      systemd path services node.js






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Sep 25 at 15:16









      Lionzinho

      1




      1




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote













          Services do not run in login session contexts.



          Your PATH is not right, and the value of PATH in a shell in a login session is completely irrelevant, as are your shell's startup scripts.



          One of the features of service management systems (in general, not limited to systemd) is that they start all services based upon a single uniform environment, as modified only by elements of the service definition (whatever that is). It is nothing to do with how login shells set up user environments for login sessions. (Not, it is not root's login session environment either.)



          In systemd's case, your service definition is the service unit file, and unless you modify PATH in that unit it will be whatever default value that all services are started with. In systemd's case, this is documented; and /usr/local/lib/nodejs/node-v8.11.4/bin/ is not on the list.



          If you want PATH to be something other than the all-serviecs default, you need to modify your service unit with Environment= settings to change it.



          Further reading



          • Lennart Poettering et al. (2017). "Environment variables in spawned processes". systemd.exec. systemd manual pages. Freedesktop.org.





          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',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            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%2f471359%2fsystemd-custom-service-doesnt-read-path%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote













            Services do not run in login session contexts.



            Your PATH is not right, and the value of PATH in a shell in a login session is completely irrelevant, as are your shell's startup scripts.



            One of the features of service management systems (in general, not limited to systemd) is that they start all services based upon a single uniform environment, as modified only by elements of the service definition (whatever that is). It is nothing to do with how login shells set up user environments for login sessions. (Not, it is not root's login session environment either.)



            In systemd's case, your service definition is the service unit file, and unless you modify PATH in that unit it will be whatever default value that all services are started with. In systemd's case, this is documented; and /usr/local/lib/nodejs/node-v8.11.4/bin/ is not on the list.



            If you want PATH to be something other than the all-serviecs default, you need to modify your service unit with Environment= settings to change it.



            Further reading



            • Lennart Poettering et al. (2017). "Environment variables in spawned processes". systemd.exec. systemd manual pages. Freedesktop.org.





            share|improve this answer
























              up vote
              2
              down vote













              Services do not run in login session contexts.



              Your PATH is not right, and the value of PATH in a shell in a login session is completely irrelevant, as are your shell's startup scripts.



              One of the features of service management systems (in general, not limited to systemd) is that they start all services based upon a single uniform environment, as modified only by elements of the service definition (whatever that is). It is nothing to do with how login shells set up user environments for login sessions. (Not, it is not root's login session environment either.)



              In systemd's case, your service definition is the service unit file, and unless you modify PATH in that unit it will be whatever default value that all services are started with. In systemd's case, this is documented; and /usr/local/lib/nodejs/node-v8.11.4/bin/ is not on the list.



              If you want PATH to be something other than the all-serviecs default, you need to modify your service unit with Environment= settings to change it.



              Further reading



              • Lennart Poettering et al. (2017). "Environment variables in spawned processes". systemd.exec. systemd manual pages. Freedesktop.org.





              share|improve this answer






















                up vote
                2
                down vote










                up vote
                2
                down vote









                Services do not run in login session contexts.



                Your PATH is not right, and the value of PATH in a shell in a login session is completely irrelevant, as are your shell's startup scripts.



                One of the features of service management systems (in general, not limited to systemd) is that they start all services based upon a single uniform environment, as modified only by elements of the service definition (whatever that is). It is nothing to do with how login shells set up user environments for login sessions. (Not, it is not root's login session environment either.)



                In systemd's case, your service definition is the service unit file, and unless you modify PATH in that unit it will be whatever default value that all services are started with. In systemd's case, this is documented; and /usr/local/lib/nodejs/node-v8.11.4/bin/ is not on the list.



                If you want PATH to be something other than the all-serviecs default, you need to modify your service unit with Environment= settings to change it.



                Further reading



                • Lennart Poettering et al. (2017). "Environment variables in spawned processes". systemd.exec. systemd manual pages. Freedesktop.org.





                share|improve this answer












                Services do not run in login session contexts.



                Your PATH is not right, and the value of PATH in a shell in a login session is completely irrelevant, as are your shell's startup scripts.



                One of the features of service management systems (in general, not limited to systemd) is that they start all services based upon a single uniform environment, as modified only by elements of the service definition (whatever that is). It is nothing to do with how login shells set up user environments for login sessions. (Not, it is not root's login session environment either.)



                In systemd's case, your service definition is the service unit file, and unless you modify PATH in that unit it will be whatever default value that all services are started with. In systemd's case, this is documented; and /usr/local/lib/nodejs/node-v8.11.4/bin/ is not on the list.



                If you want PATH to be something other than the all-serviecs default, you need to modify your service unit with Environment= settings to change it.



                Further reading



                • Lennart Poettering et al. (2017). "Environment variables in spawned processes". systemd.exec. systemd manual pages. Freedesktop.org.






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Sep 25 at 16:30









                JdeBP

                30k462137




                30k462137



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f471359%2fsystemd-custom-service-doesnt-read-path%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay