Skip to content

Autostart on Boot Configuration

Set Up an Autostart Service

Create a Startup Script

Using any text editor, create a new startup script in the /etc/init.d directory, assume it is named your_script_name. The following is the reference content of an example script:

#!/bin/bash

### BEGIN INIT INFO
# Provides:          your_service_name
# Required-Start:    $all
# Required-Stop:     
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start your_service_name at boot time
# Description:       Enable service provided by your_service_name
### END INIT INFO

/path/to/your/program &

exit 0

Make the Startup Script Executable

sudo chmod +x /etc/init.d/your_script_name

Use the update-rc.d Command to Add the Script to the System's Startup Items

sudo update-rc.d your_script_name defaults

Use the systemctl Command to Enable Autostart

sudo systemctl enable your_script_name

Restart the Development Board to Verify That the Autostart Service Program Runs Properly

root@ubuntu:~# systemctl status your_script_name.service 
● your_script_name.service - LSB: Start your_service_name at boot time
    Loaded: loaded (/etc/init.d/your_script_name; generated)
    Active: active (exited) since Wed 2023-04-19 15:01:12 CST; 57s ago
    Docs: man:systemd-sysv-generator(8)
    Process: 2768 ExecStart=/etc/init.d/your_script_name start (code=exited, status=0/SUCCESS)

Add to the rc.local Service

rc.local is a system service used to automatically execute some scripts or commands when the system boots. This service is called automatically when the system starts, and after the system has finished booting it executes user-specified scripts or commands so that custom configuration or operations can be performed at startup.

In early Linux distributions, rc.local was the last service run by default during the system boot process. With the spread of systemd, rc.local is regarded as a legacy system service.

This is achieved by adding the startup command to the end of the /etc/rc.local file with sudo vim /etc/rc.local, for example:

#!/bin/bash -e
#
# rc.local
#re
# 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.

# Insert what you need

exit 0

Image 1