Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
578 views
in Technique[技术] by (71.8m points)

debian - Executing a script on startup using BeagleBone Black

I have an a.out which I want to run when my BeagleBone boots up. It is actually a socket server which I want to start as soon as the BeagleBone powers up. I tried to put this in /etc/init.d, but it didn't help. I wrote a shell script to run this executable but even that did not help.

What can I do to make a script run as soon as it boots up?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It took me quite some time to figure this out, but with lots of research, I finally found what I was looking for.

  1. Compile the required code.

  2. Create a bash script that will launch the code at boot/ startup

    cd /usr/bin/
    

    Type nano scriptname.sh

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

    Save and grant execute permission

    chmod u+x /usr/bin/scriptname.sh
    
  3. Create the service

    nano /lib/systemd/scriptname.service
    
  4. Edit the above file as necessary to invoke the different functionalities like network. Enable these only if the code needs that particular service. Disable unwanted ones to decrease 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
    
  5. Create a symbolic link to let the device know the location of the service.

    cd /etc/systemd/system/
    ln /lib/systemd/scriptname.service scriptname.service
    
  6. Make systemd reload the configuration file, start the service immediately (helps to see if the service is functioning properly) and enable the unit files specified in the command line.

    systemctl daemon-reload
    systemctl start scriptname.service
    systemctl enable scriptname.service
    
  7. Restart BBB immediately to see if it runs as intended.

    reboot
    

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...