Buildroot-ts Startup Scripts: Difference between revisions

From embeddedTS Manuals
m (Kris moved page Buildroot-2018.02 Startup Scripts to Buildroot-ts Startup Scripts: No longer tied to 2018 release)
(Cleanup)
Line 1: Line 1:
From Buildroot the most straightforward way to add an application to startup is to create a startup script. This is an example simple startup script that will toggle the red led on during startup, and off during shutdown. In this case the file is named customstartup, but you can replace this with any application name as well.
The most straightforward way to add an application to startup is to create a startup script. This example startup script that will toggle the red LED on during startup, and off during shutdown. In this case the script is named <source inline>customstartup</source> which can be changed as needed.


Edit the file /etc/init.d/S99customstartup to contain the following. Be sure to set the script as executable!
Create the file <source inline>/etc/init.d/S99customstartup</source> with the following contents. Be sure to set the script as executable!
<source lang=bash>
<source lang=bash>
#! /bin/sh
#! /bin/sh
Line 28: Line 28:
{{Note|The $PATH variable is not set up by default in init scripts so this will either need to be done manually or the full path to your application must be included.}}
{{Note|The $PATH variable is not set up by default in init scripts so this will either need to be done manually or the full path to your application must be included.}}


To manually start and stop the script:
Buildroot provides numerous mechanisms to create this file in the target filesystem at build time. See the [https://buildroot.org/downloads/manual/manual.html Buildroot manual] for more information on this.
 
This script will be automatically called at startup and shutdown thanks to the file location and naming. However, it can also be manually started or stopped:
<source lang=bash>
<source lang=bash>
/etc/init.d/S99customstartup start
/etc/init.d/S99customstartup start
/etc/init.d/S99customstartup stop
/etc/init.d/S99customstartup stop
</source>
</source>

Revision as of 18:07, 3 April 2023

The most straightforward way to add an application to startup is to create a startup script. This example startup script that will toggle the red LED on during startup, and off during shutdown. In this case the script is named customstartup which can be changed as needed.

Create the file /etc/init.d/S99customstartup with the following contents. Be sure to set the script as executable!

#! /bin/sh
# /etc/init.d/customstartup

case "$1" in
  start)
    echo 1 > /sys/class/leds/red-led/brightness
    ## If you are launching a daemon or other long running processes
    ## this should be started with
    # nohup /usr/local/bin/yourdaemon &
    ;;
  stop)
    # if you have anything that needs to run on shutdown
    echo 0 > /sys/class/leds/red-led/brightness
    ;;
  *)
    echo "Usage: customstartup start|stop" >&2
    exit 3
    ;;
esac
  
exit 0
Note: The $PATH variable is not set up by default in init scripts so this will either need to be done manually or the full path to your application must be included.

Buildroot provides numerous mechanisms to create this file in the target filesystem at build time. See the Buildroot manual for more information on this.

This script will be automatically called at startup and shutdown thanks to the file location and naming. However, it can also be manually started or stopped:

/etc/init.d/S99customstartup start
/etc/init.d/S99customstartup stop