1 Reply Latest reply on Apr 3, 2017 6:23 AM by Electrumpet

    startup script won't run while application does

    Electrumpet

      Dear list,

       

      Reaching out again.

      My last step toward a running application and of course I run into problems again...

       

      I have a program that runs without any problems when I run it with eclipse from my computer (MacOsX 10.9.5).

      When I copy the compiled version to the Edison I can run that program also on the Edison and it works again flawlessly:

      ./mergeGesticUDP

       

      Then when I try to make a startup service out of it it fails. It seems that everything goes as expected until I am already running the program. It seems that a certain action is not working.

      The proces goes wrong on this portion of the code:

       

          /* Initialize all variables and required resources of gestic */

          gestic_initialize(&gestic);

       

          /* Try to open a connection to the device */

       

          if(gestic_open(&gestic) < 0) {

              fprintf(stderr, "Could not open connection to GestIC.\n");

              return -1;

          }

       

      When I run:

      root@ediElectrumpet:/lib/systemd/system# systemctl status mergeGesticUDP.service

      ● mergeGesticUDP.service - GestIC data in OSC to computer

         Loaded: loaded (/lib/systemd/system/mergeGesticUDP.service; enabled)

         Active: activating (auto-restart) (Result: exit-code) since Fri 2017-03-31 22:22:01 UTC; 9s ago

        Process: 621 ExecStart=/usr/bin/mergeGesticUDP (code=exited, status=255)

      Main PID: 621 (code=exited, status=255)

       

      Mar 31 22:22:01 ediElectrumpet systemd[1]: mergeGesticUDP.service: main process exited, code=exited, status=255/n/a

      Mar 31 22:22:01 ediElectrumpet systemd[1]: Unit mergeGesticUDP.service entered failed state.

      Mar 31 22:22:01 ediElectrumpet mergeGesticUDP[621]: Could not open connection to GestIC.

      Mar 31 22:22:01 ediElectrumpet mergeGesticUDP[621]: GestIC-Stream-Demo version 1.2.0

       

      It is clear that there is a problem when the program tries to make a connection to the GestIC device. This device is connected through the OTG USB connection on the Edison.

       

      Should I include something in the .service script that says that using the USB connection is ok?

       

      At the moment it looks like this (based on https://www.losant.com/blog/edison-automatic-process-startup ):

       

      [Unit]

       

      Description=GestIC data in OSC to computer

       

      Wants=network-online.target

       

      After=network-online.target

       

       

       

      [Service]

       

      ExecStart=/usr/local/mergeGesticUDP/mergeGesticUDP

       

      User=nobody

       

      Restart=on-failure

       

      RestartSec=10

       

      WorkingDirectory=/usr/local/mergeGesticUDP/

       

       

       

      [Install]

       

      WantedBy=multi-user.target

       

      At the moment I am without a clue and I can't find related issues on the internet either...

       

      Best, Hans.

        • 1. Re: startup script won't run while application does
          Electrumpet

          Dear all,

           

          Finally this turned out to be very easy. The problem was in the User. It turned out that it should not be 'nobody'. Found that here:

          Sonarr.service Error Sonarr Won't Autostart - Help & Support - sonarr :: forums

           

          root@ediElectrumpet:~# whoami; id -g -n

          root

          root

          root@ediElectrumpet:~# cd /lib/systemd/system

          root@ediElectrumpet:/lib/systemd/system# vi mergeGesticUDP.service

          root@ediElectrumpet:/lib/systemd/system# chmod 755 /lib/systemd/system/mergeGesticUDP.service

          root@ediElectrumpet:/lib/systemd/system# chown root:root /lib/systemd/system/mergeGesticUDP.service

          root@ediElectrumpet:/lib/systemd/system# systemctl daemon-reload

          root@ediElectrumpet:/lib/systemd/system# systemctl start mergeGesticUDP.service

          root@ediElectrumpet:/lib/systemd/system# systemctl status mergeGesticUDP.service

          mergeGesticUDP.service - GestIC data in OSC to computer

             Loaded: loaded (/lib/systemd/system/mergeGesticUDP.service; enabled)

             Active: active (running) since Fri 2017-03-31 22:12:27 UTC; 6s ago

          Main PID: 542 (mergeGesticUDP)

             CGroup: /system.slice/mergeGesticUDP.service

                     └─542 /usr/local/mergeGesticUDP/mergeGesticUDP

           

          Mar 31 22:12:27 ediElectrumpet systemd[1]: Started GestIC data in OSC to computer.

          Mar 31 22:12:27 ediElectrumpet libmraa[542]: libmraa version v1.0.0 initialised by user 'root' with EUID 0

          Mar 31 22:12:27 ediElectrumpet libmraa[542]: gpio214: init: Failed to write to 'export': No such device

          Mar 31 22:12:27 ediElectrumpet libmraa[542]: edison: Arduino board not detected, assuming Intel Edison Miniboard

          Mar 31 22:12:27 ediElectrumpet libmraa[542]: libmraa initialised for platform 'Intel Edison' of type 2

          root@ediElectrumpet:/lib/systemd/system#

           

          In my new service file I also used the name of the service state of my USB device (I guess that if that is present it means that it is active, apparently so since the script works)

           

          I could find the service state using this:

          root@ediElectrumpet:/lib/systemd/system# systemctl status /dev/serial/by-id/usb-Microchip_Technology_Inc._GestIC_Bridge-if00

          dev-serial-by\x2did-usb\x2dMicrochip_Technology_Inc._GestIC_Bridge\x2dif00.device - CDC RS-232 Emulation Demo

             Follow: unit currently follows state of sys-devices-pci0000:00-0000:00:11.0-dwc3\x2dhost.2-usb1-1\x2d1-1\x2d1:1.0-tty-ttyACM0.device

             Loaded: loaded

             Active: active (plugged) since Fri 2017-03-31 22:08:40 UTC; 17min ago

             Device: /sys/devices/pci0000:00/0000:00:11.0/dwc3-host.2/usb1/1-1/1-1:1.0/tty/ttyACM0

           

           

           

          So my service file now looks like this:

           

          [Unit]

          Description=GestIC data in OSC to computer

          Requires=sys-devices-pci0000:00-0000:00:11.0-dwc3\x2dhost.2-usb1-1\x2d1-1\x2d1:1.0-tty-ttyACM0.device

          After=sys-devices-pci0000:00-0000:00:11.0-dwc3\x2dhost.2-usb1-1\x2d1-1\x2d1:1.0-tty-ttyACM0.device

           

          [Service]

          ExecStart=/usr/local/mergeGesticUDP/mergeGesticUDP

          User=root

          Group=root

          Restart=on-failure

          RestartSec=5s

           

          [Install]

          WantedBy=sys-devices-pci0000:00-0000:00:11.0-dwc3\x2dhost.2-usb1-1\x2d1-1\x2d1:1.0-tty-ttyACM0.device

           

           

          Any further advice is welcome but I am happy because it works!!!!!!

          Now further making art........

           

          Best, Hans.