Script execution on startup using BeagleBone Black

I have a.out that I want to run when BeagleBone loads. This is actually a socket server that I want to start as soon as BeagleBone turns on. I tried putting this in /etc/init.d , but that didn't help. I wrote a shell script to run this executable, but even this did not help.

What to do to run the script immediately after loading?

+6
source share
2 answers

It took me a while to figure this out, but with a lot of research, I finally found what I was looking for.

  • Compile the required code.

  • Create a bash script that will run the code upon loading / starting

     cd /usr/bin/ 

    Type nano scriptname.sh

     #!/bin/bash /home/root/name_of_compiled_code 

    Save and grant execution permission

     chmod u+x /usr/bin/scriptname.sh 
  • Create a service

     nano /lib/systemd/scriptname.service 
  • Edit the above file, if necessary, to invoke various functions, such as the network. Turn them on only if the code needs this particular service. Disable unwanted ones to reduce boot time.

     [Unit] Description=description of code After=syslog.target network.target [Service] Type=simple ExecStart=/usr/bin/scriptname.sh [Install] WantedBy=multi-user.target 
  • Create a symbolic link to tell the device the location of the service.

     cd /etc/systemd/system/ ln /lib/systemd/scriptname.service scriptname.service 
  • Make systemd reload the configuration file, immediately start the service (to make sure the service is working correctly) and include the device files specified on the command line.

     systemctl daemon-reload systemctl start scriptname.service systemctl enable scriptname.service 
  • Restart the BBB immediately to see if it is working as intended.

     reboot 

(All credits refer to http://mybeagleboneblackfindings.blogspot.com/2013/10/running-script-on-beaglebone-black-boot.html )

+8
source

I followed the 7 steps to create the service, but it didn’t work for me, then I put my shell commands to run my program in /etc/rc.local and it worked.

 #!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. cd /home/my_program_directory /home/my_program_directory/my_executable exit 0 
0
source

Source: https://habr.com/ru/post/983315/


All Articles