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
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 )
source share