3 Replies Latest reply on Apr 24, 2015 11:20 AM by Intel_Peter

    Running Node.js as system service, problem with Cylon.js

    X_Y

      I've made a node.js script to run a robot. The script itself runs fine, but if I want to use it as a service, then it always fails. The following code starts the problem:

       

      index.js

      var app = require('express')();

      var http = require('http').Server(app);

      var io = require('socket.io')(http);

       

      var Cylon = require('cylon');

       

      //The following part kills the servive

      var rbt=Cylon.robot({

        connections: {

          edison:{adaptor: 'intel-iot'}

        },

       

        devices: {

          servoL: { driver: 'servo', pin: 20 },

          servoR: { driver: 'servo', pin: 14 },

          button: { driver: 'button', pin: 15 },

        },

      });

       

      /etc/systemd/system/robotserver.service

      [Unit]

      Description=robotserver startup

      After=mdns.service

       

       

      [Service]

      ExecStart=/bin/sh -c "/usr/bin/node /home/root/robotServer/index.js"

      Restart=always

      RestartSec=10s

      Environment=NODE_ENV=production

      [Install]

      #WantedBy=default.target

       

      And I've executed the following commands:

      systemctl daemon-reload

      systemctl start robotserver.service

       

      If I run "systemctl status robotserver.service", the following message will show up:

      ● robotserver.service - robotserver startup

        Loaded: loaded (/etc/systemd/system/robotserver.service; static)

        Active: activating (auto-restart) (Result: exit-code) since Thu 2015-03-12 13:48:57 UTC; 7s ago

        Process: 2846 ExecStart=/bin/sh -c /usr/bin/node /home/root/robotServer/index.js (code=exited, status=143)

      Main PID: 2846 (code=exited, status=143)

       

      Anybody knows what's wrong with my code?