6 Replies Latest reply on Aug 10, 2015 4:57 PM by CMata_Intel

    systemd works for python script but not nodejs script

    rudythecanadian

      Hello,

      I've spent a fair amount of time reading threads on using systemd to auto run programs or scripts on the Edison. The one thing I cannot seem to find an answer for is why a python script works just fine but I get errors attempting to run a javascript file through node.

       

      • Is this a specific tweak to the unit configuration file?
      • Does the js script need to reside in the node_app_slot directory?
      • Is there documentation on the node_app_slot directory?

       

      Thanks,
      Chris.

        • 1. Re: systemd works for python script but not nodejs script
          CMata_Intel

          Hi Chris,

           

          What are the errors you are getting when you try to start a script that includes NodeJS?

          What does the Node script? Does the Python and Node script have the same function?

          Could you attach the service you are running and also the output of running systemctl status yourservice.service?

           

          Regards,

          Charlie

          • 2. Re: systemd works for python script but not nodejs script
            joshuajnoble

            I'm trying to do the same thing and haven't had any luck with it. I can start the nodejs server after logging in and starting the service with "systemctl service myservice.service" but there's seemingly no way to get it to start up correctly when the board starts up. If I can figure out a way to hack something together I'll post it here.

            • 3. Re: systemd works for python script but not nodejs script
              CMata_Intel

              Hi guys,

               

              I did the following and it worked.

              First I created a blinktest.js in /node_app_slot with this code: mraa/Blink-IO.js at master


              Then, I went to /lib/systemd/system and created the blinktest.service:

              [Unit]
              Description=Blink with JS
              After=network.target
              
              [Service]
              ExecStart=/usr/bin/node /node_app_slot/blinktest.js
              Restart=always
              Environment=NODE_PATH=/usr/lib/node_modules
              
              [Install]
              WantedBy=multi-user.target
              

               

              Then I ran:

              root@edison:/lib/systemd/system# systemctl daemon-reload
              root@edison:/lib/systemd/system# systemctl start blinktest.service
              root@edison:/lib/systemd/system# systemctl enable blinktest.service
              

               

              This worked, checked if you have set the Environment correctly in the service and if the service is enable and running with systemctl status blinktest.service.

               

               

              Regards,

              Charlie

              • 4. Re: systemd works for python script but not nodejs script
                rudythecanadian

                Here is my service file:

                 

                [Unit]

                Description=Bloom services

                After=network.target

                [Service]

                ExecStart=/usr/bin/node /node_app_slot/bloom.js

                Restart=always

                Environment=NODE_PATH=/usr/lib/node_modules

                [Install]

                WantedBy=multi-user.target

                 

                and the results:

                 

                root@bloom1:/lib/systemd/bloom# systemctl daemon-reload

                root@bloom1:/lib/systemd/bloom# systemctl start systemd-bloomnode.service

                root@bloom1:/lib/systemd/bloom# systemctl status systemd-bloomnode.service

                systemd-bloomnode.service - Bloom services

                  Loaded: loaded (/lib/systemd/bloom/systemd-bloomnode.service; enabled)

                  Active: failed (Result: start-limit) since Thu 2015-08-06 19:05:10 UTC; 2s ago

                  Process: 559 ExecStart=/usr/bin/node /node_app_slot/bloom.js (code=exited, status=8)

                Main PID: 559 (code=exited, status=8)

                 

                Aug 06 19:05:10 bloom1 node[559]: at Function.Module._load (module.js:312:12)

                Aug 06 19:05:10 bloom1 node[559]: at Function.Module.runMain (module.js:497:10)

                Aug 06 19:05:10 bloom1 systemd[1]: systemd-bloomnode.service: main process .../a

                Aug 06 19:05:10 bloom1 systemd[1]: Unit systemd-bloomnode.service entered f...e.

                Aug 06 19:05:10 bloom1 systemd[1]: systemd-bloomnode.service holdoff time o...t.

                Aug 06 19:05:10 bloom1 systemd[1]: Stopping Bloom services...

                Aug 06 19:05:10 bloom1 systemd[1]: Starting Bloom services...

                Aug 06 19:05:10 bloom1 systemd[1]: systemd-bloomnode.service start request ...t.

                Aug 06 19:05:10 bloom1 systemd[1]: Failed to start Bloom services.

                Aug 06 19:05:10 bloom1 systemd[1]: Unit systemd-bloomnode.service entered f...e.

                 

                Same error as before. Thoughts?

                • 5. Re: systemd works for python script but not nodejs script
                  Frederick Blais

                  Thoughts?

                   

                  I had some problems with systemd too depending if the process was exiting after running or calling another process. I'm really not sure if it is going to solve your issue but maybe you have to tell some more stuff to systemd

                   

                  Try adding this to your service file, between [service] and ExecStart:

                   

                  Type=oneshot

                  RemainAfterExit=yes

                   

                  Maybe it's one of these commands. There are also other types, like simple, forking...

                  http://www.freedesktop.org/software/systemd/man/systemd.service.html

                  • 6. Re: systemd works for python script but not nodejs script
                    CMata_Intel

                    Hi Chris,

                     

                    Did you try with Frederick's suggestions?

                    There is also another thread related with a service with NodeJS [Start a nodejs server on boot of edison], try also with these lines under [Service]:

                    Environment="NODE_PATH=/usr/lib/node_modules"

                    Environment="NODE_ENV=production"

                    Environment="AVAHI_COMPAT_NOWARN=1"

                    Environment="HOME=/home/root"

                    Regards,

                    Charlie