Purpose: To execute an arbituary number of files on startup of a Debian based system
-
Place all the files you want to run in the 'run' folder with 'run_all.sh' in its parent directory.
-
Edit 'run_all.sh' to include the full path to the run folder.
-
Setup the file 'run_all.sh' to run on startup. There are many ways to do this.
- The most up to date method is through systemd (detailed below).
- Placing the script in rc.local may work but is not reccomended.
- Hijacking the end of another script known to execute on startup is also plausible but is messy and not as easily extendable.
-
Additional notes
- Make sure that all files are in fact executable. This can be done in the terminal with
chmod +x filename
for each file involved. - Each execuatable should include a shebang as its first line to insure the correct interpreter is loaded.
- Make sure that all files are in fact executable. This can be done in the terminal with
-
Install systemd if you haven't done so already.
-
Modify the file 'startup.service' to include the full path to the file 'run_all.sh'.
-
Add the correct permissions to the file with
sudo chmod 644 /etc/systemd/system/startup.service
. -
Copy the file to the folder '/etc/systemd/system'.
-
Test the service with the following commands. Ensure the service did not fail. If you have trouble locating the problem, follow this guide to investigate it.
sudo systemctl start startup
sudo systemctl status startup
-
Enable the service.
sudo systemctl enable startup
- If it is necessary for your files to be executed after a network connection is established, add the line
After=network.target
following the description. This can also be replaced by any other '.service' file that must be run before execution. - More information on '.service' files can be found here.