If you were to distribute commercially, then you’d want to make a systemd
file to load as a service. The simpler way is to use the “/etc/rc.local
” file and just run the content there. On older releases this file would always “just be there”, but on newer systems this file is optional. See first if you have file “/etc/rc.local
”. My guess is that unless you are using an older release, then the file won’t be there.
This command will tell you the status of the use of that file, which is most likely not running:
systemctl status rc-local.service
Because this won’t be running (unless something has told it to) you would enable the service like this:
sudo systemctl enable rc-local.service
Then you would create the missing file in “/etc
” with name “rc.local
”. The permissions should be “-rwxr-xr-x 1 root root
” (use “ls -l /etc/rc.local
” once the file is created to see permissions). Here is the content you can copy and paste to create the skeleton of the file (use “sudo
” with your favorite editor since only root should be able to write there):
#!/bin/sh -e
#
# rc.local
#
# 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.
# Place your custom content here...
exit 0
When the system boots it will now run content in this file as boot completes. What command name does your program use? I will pretend the command is “hello
” (no such command, just illustration), and it is located at “/usr/local/bin/hello
”. Normally full paths are used in this file for good reason, so use the full path. If this is a shell script, then some edits might be needed, so state what kind of program this is, e.g., compiled versus interpreted (such as Python)…this changes how you will want to launch the program. Also state if the program is to be run as root or some other user.
An example of finding out more about the program would be to run the command which examines it:
file /usr/local/bin/hello
(post what it says about the file type)
Also, state if your program, when run on command line, ever has output (e.g., error messages or other messages) to the command line. If it does, then be sure to mention the nature of that text (this can have an effect on logging and something with a lot of output could fill up the log files if not careful, but error messages might be good to log).
Once this is known it should be easy to add a single line to rc.local
to launch your program.