When you boot your system, you will notice lots of text floating by. If you pay
close attention, you will notice this text is the same every time you reboot
your system. The sequence of all these actions is called the
First, your boot loader will load the kernel image you have defined in the
boot loader configuration into memory after which it tells the CPU to run the
kernel. When the kernel is loaded and run, it initializes all kernel-specific
structures and tasks and starts the
This process then makes sure that all filesystems (defined in
Finally, when all scripts are executed,
Now
First,
When all
Of course
If you remember the boot sequence we have just described, you will remember
that
si::sysinit:/sbin/rc sysinit
This line tells
Second,
rc::bootwait:/sbin/rc boot
Again the
Now
id:3:initdefault:
In this case (which the majority of Gentoo users will use), the
l0:0:wait:/sbin/rc shutdown l1:S1:wait:/sbin/rc single l2:2:wait:/sbin/rc nonetwork l3:3:wait:/sbin/rc default l4:4:wait:/sbin/rc default l5:5:wait:/sbin/rc default l6:6:wait:/sbin/rc reboot
The line that defines level 3, again, uses the
When
c1:12345:respawn:/sbin/agetty 38400 tty1 linux c2:12345:respawn:/sbin/agetty 38400 tty2 linux c3:12345:respawn:/sbin/agetty 38400 tty3 linux c4:12345:respawn:/sbin/agetty 38400 tty4 linux c5:12345:respawn:/sbin/agetty 38400 tty5 linux c6:12345:respawn:/sbin/agetty 38400 tty6 linux
You have seen that
In Gentoo, there are seven runlevels defined: three internal runlevels, and four
user-defined runlevels. The internal runlevels are called
The user-defined runlevels are those with an accompanying
The scripts that the
To start, stop or restart a service (and all depending services),
# /etc/init.d/postfix start
If you want to stop a service, but not the services that depend on it, you can
use the
# /etc/init.d/postfix pause
If you want to see what status a service has (started, stopped, paused, ...) you
can use the
# /etc/init.d/postfix status
If the status information tells you that the service is running, but you know
that it is not, then you can reset the status information to "stopped" with the
# /etc/init.d/postfix zap
To also ask what dependencies the service has, you can use
# /etc/init.d/postfix ineed
Similarly, you can ask what services require the service (
# /etc/init.d/postfix needsme
Finally, you can ask what dependencies the service requires that are missing:
# /etc/init.d/postfix broken
Gentoo's init system uses a dependency-tree to decide what service needs to be started first. As this is a tedious task that we wouldn't want our users to have to do manually, we have created tools that ease the administration of the runlevels and init scripts.
With
You have already added init scripts to the "default" runlevel during the
installation of Gentoo. At that time you might not have had a clue what the
"default" is for, but now you should. The
To add or remove an init script, just give
# rc-update del postfix default
The
# rc-update show
Init scripts can be quite complex. It is therefore not really desirable to have the users edit the init script directly, as it would make it more error-prone. It is however important to be able to configure such a service. For instance, you might want to give more options to the service itself.
A second reason to have this configuration outside the init script is to be able to update the init scripts without the fear that your configuration changes will be undone.
Gentoo provides an easy way to configure such a service: every init script that
can be configured has a file in
APACHE2_OPTS="-D PHP4"
Such a configuration file contains variables and variables alone (just like
No, writing an init script is usually not necessary as Gentoo provides ready-to-use init scripts for all provided services. However, you might have installed a service without using Portage, in which case you will most likely have to create an init script.
Do not use the init script provided by the service if it isn't explicitly written for Gentoo: Gentoo's init scripts are not compatible with the init scripts used by other distributions!
The basic layout of an init script is shown below.
#!/sbin/runscript
depend() {
(Dependency information)
}
start() {
(Commands necessary to start the service)
}
stop() {
(Commands necessary to stop the service)
}
restart() {
(Commands necessary to restart the service)
}
Any init script
There are two dependencies you can define:
A
Let us take a look at the dependency information for the postfix service.
depend() {
need net
use logger dns
provide mta
}
As you can see, the postfix service:
In some cases you might not require a service, but want your service to be
started
As an example we view the settings of the Portmap service:
depend() {
need net
before inetd
before xinetd
}
You can also use the "*" glob to catch all services in the same runlevel, although this isn't advisable.
depend() {
before *
}
If your service must write to local disks, it should need
depend() {
need localmount
after bootmisc
}
Next to the
start() {
ebegin "Starting my_service"
start-stop-daemon --start --exec /path/to/my_service \
--pidfile /path/to/my_pidfile
eend $?
}
Both
If you need more examples of the
Other functions you can define are:
Although you do not
stop() {
ebegin "Stopping my_service"
start-stop-daemon --stop --exec /path/to/my_service \
--pidfile /path/to/my_pidfile
eend $?
}
If your service runs some other script (for example, bash, python, or perl),
and this script later changes names (for example,
start() {
ebegin "Starting my_script"
start-stop-daemon --start --exec /path/to/my_script \
--pidfile /path/to/my_pidfile --name foo
eend $?
}
$ man start-stop-daemon
Gentoo's init script syntax is based on the Bourne Again Shell (bash) so you are free to use bash-compatible constructs inside your init script.
If you want your init script to support more options than the ones we have
already encountered, you should add the option to the
opts="${opts} restartdelay"
restartdelay() {
stop
sleep 3 # Wait 3 seconds before starting again
start
}
You don't have to do anything to support a configuration file in
Also, if your init script provides a virtual dependency (such as
Many laptop users know the situation: at home you need to start
For instance you can create a second "default" runlevel which you can boot that has other init scripts assigned to it. You can then select at boottime what default runlevel you want to use.
First of all, create the runlevel directory for your second "default" runlevel.
As an example we create the
# mkdir /etc/runlevels/offline
Add the necessary init scripts to the newly created runlevels. For instance, if
you want to have an exact copy of your current
(Copy all services from default runlevel to offline runlevel) # cd /etc/runlevels/default # for service in *; do rc-update add $service offline; done(Remove unwanted service from offline runlevel) # rc-update del net.eth0 offline(Display active services for offline runlevel) # rc-update show offline(Partial sample Output) acpid | offline domainname | offline local | offline net.eth0 |
Even though
RC_COLDPLUG="yes"(Next, specify the services you do not want automatically started) RC_PLUG_SERVICES="!net.eth0"
Now edit your bootloader configuration and add a new entry for the
title Gentoo Linux Offline Usage root (hd0,0) kernel (hd0,0)/kernel-2.4.25 root=/dev/hda3 softlevel=offline
VoilĂ , you're all set now. If you boot your system and select the newly added
entry at boot, the
Using