3.4 Init Scripts Flashcards

2
Q

What is the role and function of init scripts?

A

Init scripts determine which services and daemons are configured at various runlevels.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which distribution stores the init scripts in the /etc/rc.d/init.d directory?

A

System V distributions store the init scripts in the /etc/rc.d/init.d directory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the /etc/init.d/rc5.d directory contain?

A

The /etc/init.d/rc5.d directory contains init scripts for services configured for runlevel 5.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How would you view what init scripts are available in your distribution?

A

You can view the init scripts available by examining the /etc/rc.d/init.d directory (System V distributions) or the /etc/init.d directory (BSD distributions).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What command runs an init script?

A

The service command runs an init script.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What identifier kills or starts an init script?

A

The ‘K’ identifier kills an init script, while the ‘S’ identifier starts an init script.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is involved in init script configuration?

A

Specifying whether specific daemons start at a specified runlevel.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Where are init scripts stored?

A

Init scripts are stored in /etc/init.d (BSD distribution) or /etc/rc.d/init.d (System V distribution).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are some features of init scripts?

A
  • They are configured differently for BSD and System V distributions.
  • They have symbolic links that are stored in subdirectories that correspond to the runlevel under which each script should start.
  • They can be started and stopped manually.
  • They are started at boot using the init script.
  • They contain code that determines the appropriate runlevels on which the script can operate.
  • Configuration commands use code in the scripts to configure the appropriate levels at which scripts can start and stop.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the code inside an init script that determines appropriate runleves on which the script can operate?

A
  • The default-start line defines the runlevels in which the script starts by default.
  • The required-start line defines services that must be running before this service can start.
  • The should-start line defines the services that are recommended to start before this service starts.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does the rc script do?

A

The rc script (BSD and System V) switches between runlevels.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does the halt script do?

A

The halt script (BSD and System V) stops and reboots the computer. It runs when the init 0 or init 6 commands are invoked.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does the boot script do?

A

The boot script (BSD) is run by the init process when a computer starts. It runs the scripts contained in /etc/init.d/boot.d and performs tasks that include:

  • Loading the kernel module
  • Checking the file system
  • Setting the system clock
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does the rc.sysinit script do?

A

The rc.sysinit script (System V) is run by the init process when a computer starts. This script performs tasks that include:

  • Loading the kernel module
  • Checking the file system
  • Setting the system clock
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does the boot.local script do?

A

The boot.local script (BSD) runs specific tasks at startup as specified by the administrator. It is where you put commands you want to run every tim ethe system starts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What does the rc.local script do?

A

The rc.local script (System V) runs specific tasks at startup as specified by the administrator. It is where you put commands you want to run every tim ethe system starts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How does init determine the default runlevel at boot time?

A

At boot time, init uses the /etc/inittab file to determine the default runlevel, such as runlevel 5.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Given a specified runlevel, how does init know which processes to start?

A

The init process looks at the directory associated with the runlevel to determine what processes to start. The directory for runlevel 5 is named rc5.d. Additional directories named rc0.d through rc6.d specify what processes to start for each runlevel.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What kinds of files do the rc directories contain?

A

Each rc directory contains symbolic links that point to a specific init script in /etc/init.d or /etc/rc.d/init.d. Init follows the links and runs the scripts to start or stop processes. Init repeats the process using the appropriate rc directory whenever the runlevel changes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What do the names of the symbolic links in the rc directories mean?

A
  • Link names starting with an S start a script for the runlevel.
  • Link names starting with a K kill a running process when the computer changes runlevels.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What does the service command do?

A

Manages the current state of a daemon.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What are the options of the service daemon_name command?

A
  • start starts a daemon that is not currently running.
  • stop halts a running daemon.
  • restart stops and restarts a daemon.
  • reload requests that a daemon read and apply its configuration files without stopping.
  • status shows the status of a single daemon or daemons.
  • –status-all shows the status of all daemons.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Aside from the service command, how else can you control a daemon init script?

A

You can use the absolute path to the daemon script and the option to configure the daemon (e.g., /etc/rc.d/init.d/httpd stop).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What does the insserv command do?

A

It configures default runlevels for a daemon on a BSD distribution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
How does the **insserv** command determine the default runlevels for a daemon and dependent daemons?
It references the INIT INFO script section of each daemon to determine the default runlevels for the daemon and dependent daemons.
27
What does the command **insserv *script\_name*** do?
Starts the script and associated daemon at the runlevels specified in the *init block* of the script code.
28
What does the command **insserv -r *script\_name*** do?
Keeps the script and associated daemon from starting at any runlevel.
29
What does the command **insserv -d *script\_name*** do?
Restores the script and associated daemon to default runlevels defined in the *init block* of the script code.
30
What does the **chkconfig** command do?
Configures default runlevels for a daemon on a *System V distribution*.
31
What does the comand **chkconfig --add*script\_name*** do?
Adds a new service to be managed by **chkconfig**, and makes sure the service has a start or kill entry at every runlevel. E.g., **chkconfig --add atd**.
32
What does the comand **chkconfig --del*script\_name*** do?
Removes a service from **chkconfig** management, and removes symbolic links to the service from **/etc/rc0-6.d**. E.g., **chkconfig --del ldap**.
33
What does the comand **chkconfig --level *runlevel(s) script\_name*** do?
Specifies the runlevel(s) to which a service should belong. E.g., **chkconfig --level 5 lpd**
34
What does the comand **chkconfig --level *runlevel(s) script\_name* on** do?
Enables the service in the specified runlevels. If **--level *runlevels*** is omitted, defaults to runlevels 2 thorugh 5. E.g., **chkconfig ypxfrd on**.
35
What does the comand **chkconfig --level *runlevel(s) script\_name* off** do?
Disables the service in the specified runlevels. If **--level *runlevels*** is omitted, defaults to runlevels 2 thorugh 5. E.g., **chkconfig --level 345 nfslock off**.
36
What does the comand **chkconfig *script\_name* reset** do?
Resets the service to the default runlevels specified in the init script.
37
What does the comand **chkconfig --list** do?
Lists all services and their runlevels.
38
What does the command **chkconfig -l** do?
In BSD distributions, lists services and their runlevels.
39
What does the command **chkconfig -s** do?
In BSD distributions, specifies the level to which a service should belong.
40
What is *upstart*?
*Upstart* is an event-based replacement for the **/sbin/init** daemon; it will start and stop tasks and services whenever the Linux system enters a specific runlevel, but will also start and stop services upon receiving information that something on the system has changed (known as an event).
41
What are the *upstart* runlevels?
* **0** - halt state * **1** - single user mode * **2** - graphical, multi-user mode with networking (Default) * **3**, **4**, **5** - same as runlevel 2, but not used * **6** - reboot (the system restarts itself)
42
What is a *job* in the context of *upstart*?
A *job* is a series of instructions that **init** reads which typically include a *program* and the name of an *event*. The Upstart **init** daemon runs the *program* when the *event* is triggered. *Jobs* are divided into *tasks* and *services*.
43
What is a *task* in the context of *upstart*?
A *task* is a *job* that performs its work and returns to a waiting state when it is done.
44
What is a *service* in the context of *upstart*?
A *service* is a *job* that does not normally terminate by itself. The **init** daemon monitors each service, restarting the service if it fails and killing the service when it is stopped manually or by an event.
45
What does the **start** command do in the context of *upstart*?
Starts a daemon that is not currently running. (This is a symbolic link to the **initctl** command.)
46
What does the **stop** command do in the context of *upstart*?
Halts a running daemon. (This is a symbolic link to the **initctl** command.)
47
What does the **restart** command do in the context of *upstart*?
Stops and restarts a daemon. (This is a symbolic link to the **initctl** command.)
48
What does the **reload** command do in the context of *upstart*?
Requests that a daemon read and apply its configuration files without stopping. (This is a symbolic link to the **initctl** command.)
49
What does the **runlevel** command do in the context of *upstart*?
Displays the runlevel information. (This is a symbolic link to the **initctl** command.)
50
Does *upstart* support the **/etc/inittab** file?
Yes, but it is deprecated.
51
Which commands are used to change the current runlevel on systems that use *upstart*?
The **reboot**, **shutdown**, and **telinit** commands are used to change the current runlevel on systems that use *upstart*.
52
What specifies the default runlevel on systems that use *upstart*?
The `DEFAULT_RUNLEVEL` environment variable in the **/etc/init/rc-sysinit.conf** configuration file sets the default runlevel on systems that use *upstart*.
53
What is *systemd*?
*Systemd* is a replacement for both the **/sbin/init** daemon and *upstart*, and is designed to allow services to be started in parallel at system startup.
54
What are important characteristics and features of *systemd*?
* It is compatible with SysV and Linux Standards Base (LSB) init scripts * It uses socket and D-Bus activation for starting services * It allows you to start daemons on-demand * It tracks processes using Linux control groups * It supports snapshotting and restoring of the system state
55
What are *control groups* in the context of *systemd*?
*Control groups* (AKA *cgroups*) are used to track processes (instead of process IDs) for *systemd*.
56
What are important characteristics of *control groups* (*cgroups*)?
* A *cgroup* is a collection of processes that are bound together by common criteria. * *Cgroups* are hierarchical. They are organized into parent-child relationships; a child group inherits parameters from its parent group.
57
What comand is used to manage services and runlevels on systems that use *systemd*?
The **systemctl** command manages services and runlevels on systems that use *systemd*.
58
What does the **systemctl** command do?
On systems that use *systemd*, the **systemctl** command manages services and runlevels. It combines the functionality of both **service** and **chkconfig**.
59
What specifies the default runlevel on systems that use *systemd*?
The **/etc/systemd/system/default.target** symbolic link controls the default runlevel on systems that use *systemd*. It links to one of the files in the **/lib/systemd/system/** directory. Examples: * **default.target** - default file * **multi-user.target** - runlevel 3 * **graphical.target** - runlevel 5
60
Initialization (init) sequence on BSD distributions.
1. Execute /etc/init.d/boot, which executes scripts in /etc/init.d/boot.d 2. Process /etc/inittab to determine the appropriate runlevel 3. Run the initialization scripts that correspond to the appropriate runlevel 4. Execute /etc/init.d/boot.local
61
Initialization (init) sequence on System V distributions.
1. Execute /etc/rc.d/rc.sysinit 2. Process /etc/inittab to determine the appropriate runlevel 3. Run the initialization scripts that correspond to the appropriate runlevel 4. Execute /etc/init.d/boot.local
62
Key characteristics of *upstart*.
* Developed for Ubuntu * Asynchronous * Event-based * * Receives notification of events from other processes * Runs jobs (tasks or services) when certain events occur * Responds to runlevel changes just like init * Dynamically manages services based on events * Can determine if service has stopped and can restart automatically
63
Key characteristics of *systemd*.
* Drop-in replacement for **init** * Compatible with init scripts. * Can start services in parallel, rather than in serial * Dramatically reduces time to get system up-and-running * Uses sockets and D-Bus activation * Tracks processes with control groups * Supports snapshots
64
Which command is used to manage services and runlevels in *systemd*?
The **systemctl** command manages services and runlevels on systems that use *systemd*. It combines the functionality of **service** and **chkconfig**.
65
How do you switch to runlevel 5 on systems that use *systemd*?
**systemctl isolate runlevel5.target** or **systemctl isolate graphical.target**
66
What is the file that controls default runlevel on systems that use *systemd*?
**/etc/systemd/system/default.target**, which is a symbolic link to a runlevelX.target regular file.
67
What is the command to view runlevel targets on systems that use *systemd*?
**systemctl list-units --type=target**
68
What is the syntax of the command to change or view the state of services on systems that use *systemd*?
**systemctl start|stop|restart|status *service\_name*.service**
69
What is the syntax of the command enable or disable services on systems that use *systemd*?
**systemctl enable|disable|is-enabled *service\_name*.service**
70
Where are the *systemd* runlevel targets stored?
**/lib/systemd/system**
71
How is the default runlevel set in *systemd*?
By creating a symbolic link from **/etc/systemd/system/default.target** to one of the targets in **/lib/systemd/system**.
72
Where are the files for managing services located on a *systemd* system?
**/lib/systemd/system/\*.service** files represent control groups and are used for managing services. They are equivalent to **init** scripts in **/etc/rc.d/init.d**.