[Novalug] where to put executables that must run on boot
plarsen at famlarsen.homelinux.com
Wed Oct 13 00:07:35 EDT 2010
On Tue, 2010-10-12 at 21:39 -0400, Nino Pereira wrote:
> I know the commands (ifconfig, and two calls to 'route'), and the script
> that contains them works. After reboot I execute this by hand.
No need. At least from the fedora perspective all of this is automatic.
I doubt very much ubuntu is any different. But be careful;
NetworkManager may be playing tricks with you :)
> But, in which file or in which directory do I put this script? I've
> seen all kinds of places, such as /etc/init.d, and rc.d and rcS and many
> more, which (on Ubuntu 10.10) seem to point to each other in an inpenetrable
There's a point to the madness. Again, I can really only speak from a
RH/Fedora/Centos perspective but the idea is the same on quite a few
On Fedora, you'll see all startup scripts being controlled from a
central point. You create ONE script - place it in /etc/init.d - and use
system admin tools to configure the system to load the script correctly.
With fedora that tool is called "chkconfig". The script in /etc/init.d
is a simple bash script. But to work with chkconfig you need to add a
little bit in the header of the file:
# chkconfig: 345 95 5
(there's a few more things you can add to the header to make it friendly
- read more about that in /usr/share/doc/chkconfig*).
The line tells 3 things: first which runlevels should the script be
activated at - in this case runlevels 3, 4 and 5. The two last numbers
are the sequence numbers that determines when the script is to be
started (first number) and stopped (second number). You may want to
check the other scripts out to see where your script fits in the number
Once you've added these numbers, all you need to do is "add" the script
to the startup configuration: chkconfig --add <scriptname>
The scriptname is JUST the file name. Not the full path. This will
create several symlinks in the proper directories to make your script be
called on startup and shutdown.
So that leaves you to realize you need to build your script to take at
least two parameters: start and stop. Most also implements a restart
that first calls stop and then start. The system startup sequence will
call your script with start/stop automatically.
In /etc/rc#.d you'll find links to your script (two actually). # is the
runlevel. You'll find the link to the script starts with a S or K (Start
or Kill) and then a number - which is the sequence number you gave in
the chkconfig configuration line. So basically all the startup script
does is go through the file list sorted - it either executes all the S
scripts or all the K scripts depending on startup/shutdown state. All of
this is maintained and managed by chkconfig.
You can manually test your services by using "service <name>
> On the assumption that the system is well-designed, there must be one
> and only one best place to put such a script.
There is. There's also a fallback which should be avoided if possible,
but /etc/rc.local is meant for you to add configuration commands you
want to run as the VERY last thing in the boot sequence. The
disadvantage is that nothing is run during shutdown and you can really
test it without running the full script. So using /etc/init.d is a lot
Wise words of the day:
- DDD no longer requires the librx library. Consequently, librx
errors can no more cause DDD to crash.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 198 bytes
Desc: This is a digitally signed message part
Url : http://calypso.tux.org/pipermail/novalug/attachments/20101013/457ed1de/attachment.bin
More information about the Novalug