4 Replies Latest reply on Jul 8, 2016 6:26 PM by Intel Corporation

    Confused about creating scripts to run on boot

    thatboijo

      I'm writing a program, in C++ with the Eclipse IDE, that's going to eventually need to run when the Intel Edison turns on, and I've been trying to figure out how to set that up now. I've been looking through questions, and I see that I need to create a service that executes my program, and make sure that it's located in /lib/systemd/system. I don't know how to actually make the service file though. I also see a lot of questions talking about Node.js, but nothing that involves c++.

       

      #!/bin/sh

      [Unit]

      Description=My Service

       

      [Service]

      TimeoutStartSec=1

      ExecStart=/media/sdcard/myprogram

       

      [Install]

      WantedBy=multi-user.target

       

      That's what I think the service file is suppose to look like, but I'm not even sure about that. Myprogram is the file that get's created when I run the program in Eclipse. How do I make this service file and put it in the appropriate directory? I tried using the PuTTy terminal and the vi command, but didn't know what to do after running that command. 

        • 1. Re: Confused about creating scripts to run on boot
          Intel Corporation
          This message was posted on behalf of Intel Corporation

          Hi,

          Which image are you using on your board? Could you run the command uname –a on the Terminal Console and let us know the outcome? I would like to replicate your environment to test this.
          Also, are you transferring the code through a SD card? Why don’t you use the executable that the board loads from the Eclipse?
          Are you able to run the executable on the board?

          Regards,
          Charlie
           

          • 2. Re: Confused about creating scripts to run on boot
            thatboijo

            I'm using the Linux Edison 3.10.17-poky-edison image. No it's all running from eclipse, but I changed the absolute path in eclipse to that location instead of the tmp folder. I was setting it up so that I could have a script that started running the program from that location. I'm not 100% about your last question. I know it runs when I press run on eclipse but I don't know how to run it just from the board.

            • 3. Re: Confused about creating scripts to run on boot
              Intel Corporation
              This message was posted on behalf of Intel Corporation

              Hi,

               

              I was able to create a service with a C++ code from Eclipse.
              I am using the 3.5 release, you can check this by running the command uname –a on the Terminal Console, the latest image should has as output:
              Linux jarvis35 3.10.98-poky-edison+ #1 SMP PREEMPT Mon Jun 6 14:32:08 PDT 2016 i686 GNU/Linux, and the Eclipse Luna SR2 (4.4.2) version.
              I used the C/C++ Project  > On board LED blink C++ example and used the name code as Project Name

               

              As you know, once you connect the board and run the script, you can see the executable in /tmp. In my case I saw the file code in /tmp. What I did was to cp the file in /home/root
              Then, I created a service named code.service in /lib/systemd/system with the following content:

               [Unit]
              Description=BlinkcodeService
              After=network.target
              [Service]
              ExecStart=/home/root/code
              Restart=always
              [Install]
              WantedBy=multi-user.target
              

               

              After this, you need to run the commands:
              systemctl daemon-reload
              systemctl start code.service
              systemctl enable code.service
              reboot

               

              Try with this steps and let me know the outcome, I hope it works for you too.

               

              Kind regards,
              Charlie

              • 4. Re: Confused about creating scripts to run on boot
                Intel Corporation
                This message was posted on behalf of Intel Corporation

                Hi,

                Have you tried with the steps above? Let us know if you have been able to run a script at boot with your code.

                Regards,
                Charlie