Linux: Starting Programs On Boot
There are many flavors of Linux today. In some scenarios it isn't possible
to know all of the features of each flavor and while knowing the basis of Linux helps,
it can be helpful and sometimes more convenient to know what each flavor of Linux offers.
In this short article we will go over how to start programs on boot weather you are running
these programs on Ubuntu, CentOS, Fedora, etc.
Whether it was an attempt at securing a sort of brand or just sheer programming bliss that
motivated each developer to write extra code into these operating systems, the result is a
more convenient way of getting programs to start when the machine comes up. The question is, "
Which startup program am I using for my operating system and how do I use it?"
Implement a startup script in the init.d directory
First copy a script that follows the LSB rules (Linux Standards Base) to the /etc/init.d directory
so the startup programs have something to reference. Then execute the startup program syntax.
Here is a list of those startup programs and some simple syntax for each to get program to start
Startup Programs on Ubuntu and Debian
Ubuntu & Debian: updated-rc.d
update-rc.d startupScriptName defaults
What happens when Update-rc.d is called
This usage calls update-rc.d, then the name of the startup script
(usually the name of the software with no extension) and then the word 'defaults.'
The defaults stands for run levels and those defaults are 2-5.
There are 7 total run levels but 0,1,6 are used when the machine shuts down and so
these are not included in the startup process.
In the background of Update-rc.d
What actually happens in the background is that the core startup procedure of Linux is
called to include the program you have just specified. Normally, Linux has entries in one
file that list all of the programs that need to start on boot including their priorities
and locations on the disk. Then links are placed into the appropriate run level directories
and called when the machine boots. These directories are named appropriately per run level
i.e rcX.d where X is between 0 and 6, inclusive.
Some other startup programs based on operating system are as follows:
Cent OS 6 And Below
CentOS 6 and below use a startup program called
. Simply create the LSB init.d script in the directory
with the file name as the service you prefer. You should use the skeleton LSB startup script that comes with most distros.
You can specify the run levels on which the program will startup at boot. You'll see that in most references on how to use
the run levels will be set to 2345 which are the defaults.
Here's a short explanation of what those run levels are:
|0|| Halt Shuts down system
|1|| Single-User Mode Does not configure network interfaces, start daemons, or allow non-root logins
|2|| Multi-User Mode Does not configure network interfaces or start daemons.
|3|| Multi-User Mode with Networking Starts the system normally.
|4|| Undefined Not used/User-definable
|5|| X11 As runlevel 3 + display manager(X)
|6|| Reboot Reboots the system
How to use
chkconfig At The Command Line
chkconfig --level 2345 startupScriptName on
When executing this command, the init.d script you created will be registered with the service and executed on boot up within the run levels specified.
systemd on Fedora, Open SUSE, CentOS 7 Flavors Of Linux
These three are a bit different and use a program called 'systemd' and require a 'unit file' in the
systemd Unit File
The file name will be named after the program and have the extension service i.e:
An example of the unit file is here:
ExecStart=/bin/sh /etc/init.d/syncrify $Action
ExecStop=/bin/sh /etc/init.d/syncrify $Action1
Using the Unit File
After this file is written, execute the following command:
systemctl enable software.service
(Where software.service is the name of the unit file you just created)
These are just some ways to start programs on boot. There are other, less high level
ways that hook into deeper Linux programs. However, if you decide to use the Linux standard
startup process you should use caution in doing so.
||Sep 17, 2013
|Last updated on:
||Sep 26, 2021
LEAVE A COMMENT
Your email address will not be published.