Skip to content

Instantly share code, notes, and snippets.

@tstellanova
Last active September 26, 2023 09:43
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 13 You must be signed in to fork a gist
  • Save tstellanova/7323116 to your computer and use it in GitHub Desktop.
Save tstellanova/7323116 to your computer and use it in GitHub Desktop.
How to setup a service to automatically run a python script when the BeagleBone Black (BBB) reboots. These instructions allow you to setup a python script to automatically start when the BeagleBone (running Angstrom linux with systemd) restarts.

Creating a service to startup at BeagleBone Black boot time:

  • Create a shell script such as /usr/bin/myFancyBash.sh:

      #!/bin/bash
    
      # this could be any runnable code or shell script, really
      /usr/bin/myFancyPython.py 
    

Note that the first line is critical.

  • Create a service file in /lib/systemd/myFancy.service such as:

      [Unit]
      Description=My Fancy Service
    
      [Service]
      Type=simple
      ExecStart=/usr/bin/myFancyBash.sh
    
      [Install]
      WantedBy=multi-user.target
    
  • Create a symbolic link between your script and a special location under /etc:

      ln -s /lib/systemd/myFancy.service /etc/systemd/system/myFancy.service
    
  • Make systemd aware of your new service

      systemctl daemon-reload
      systemctl enable myFancy.service
      systemctl start myFancy.service
    
  • Reboot the BeagleBone Black to see your script in action

  • If you wish to control the service at runtime, you can use systemctl commands:

      systemctl status myFancy.service
      systemctl stop myFancy.service
      systemctl start myFancy.service
      systemctl disable myFancy.service
    
@Sundbergarn
Copy link

If doing this for a bash script and executable inside a user account:
Replace:
ExecStart=/usr/bin/myFancyBash.sh
With, for example:
ExecStart=/home/debian/.../myFancyBash.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment