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
Q

How does the insserv command determine the default runlevels for a daemon and dependent daemons?

A

It references the INIT INFO script section of each daemon to determine the default runlevels for the daemon and dependent daemons.

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

What does the command insserv script_name do?

A

Starts the script and associated daemon at the runlevels specified in the init block of the script code.

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

What does the command insserv -r script_name do?

A

Keeps the script and associated daemon from starting at any runlevel.

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

What does the command insserv -d script_name do?

A

Restores the script and associated daemon to default runlevels defined in the init block of the script code.

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

What does the chkconfig command do?

A

Configures default runlevels for a daemon on a System V distribution.

31
Q

What does the comand chkconfig –addscript_name do?

A

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
Q

What does the comand chkconfig –delscript_name do?

A

Removes a service from chkconfig management, and removes symbolic links to the service from /etc/rc0-6.d. E.g., chkconfig –del ldap.

33
Q

What does the comand chkconfig –level runlevel(s) script_name do?

A

Specifies the runlevel(s) to which a service should belong. E.g., chkconfig –level 5 lpd

34
Q

What does the comand chkconfig –level runlevel(s) script_name on do?

A

Enables the service in the specified runlevels. If –level runlevels is omitted, defaults to runlevels 2 thorugh 5. E.g., chkconfig ypxfrd on.

35
Q

What does the comand chkconfig –level runlevel(s) script_name off do?

A

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
Q

What does the comand chkconfig script_name reset do?

A

Resets the service to the default runlevels specified in the init script.

37
Q

What does the comand chkconfig –list do?

A

Lists all services and their runlevels.

38
Q

What does the command chkconfig -l do?

A

In BSD distributions, lists services and their runlevels.

39
Q

What does the command chkconfig -s do?

A

In BSD distributions, specifies the level to which a service should belong.

40
Q

What is upstart?

A

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
Q

What are the upstart runlevels?

A
  • 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
Q

What is a job in the context of upstart?

A

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
Q

What is a task in the context of upstart?

A

A task is a job that performs its work and returns to a waiting state when it is done.

44
Q

What is a service in the context of upstart?

A

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
Q

What does the start command do in the context of upstart?

A

Starts a daemon that is not currently running. (This is a symbolic link to the initctl command.)

46
Q

What does the stop command do in the context of upstart?

A

Halts a running daemon. (This is a symbolic link to the initctl command.)

47
Q

What does the restart command do in the context of upstart?

A

Stops and restarts a daemon. (This is a symbolic link to the initctl command.)

48
Q

What does the reload command do in the context of upstart?

A

Requests that a daemon read and apply its configuration files without stopping. (This is a symbolic link to the initctl command.)

49
Q

What does the runlevel command do in the context of upstart?

A

Displays the runlevel information. (This is a symbolic link to the initctl command.)

50
Q

Does upstart support the /etc/inittab file?

A

Yes, but it is deprecated.

51
Q

Which commands are used to change the current runlevel on systems that use upstart?

A

The reboot, shutdown, and telinit commands are used to change the current runlevel on systems that use upstart.

52
Q

What specifies the default runlevel on systems that use upstart?

A

The DEFAULT_RUNLEVEL environment variable in the /etc/init/rc-sysinit.conf configuration file sets the default runlevel on systems that use upstart.

53
Q

What is systemd?

A

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
Q

What are important characteristics and features of systemd?

A
  • 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
Q

What are control groups in the context of systemd?

A

Control groups (AKA cgroups) are used to track processes (instead of process IDs) for systemd.

56
Q

What are important characteristics of control groups (cgroups)?

A
  • 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
Q

What comand is used to manage services and runlevels on systems that use systemd?

A

The systemctl command manages services and runlevels on systems that use systemd.

58
Q

What does the systemctl command do?

A

On systems that use systemd, the systemctl command manages services and runlevels. It combines the functionality of both service and chkconfig.

59
Q

What specifies the default runlevel on systems that use systemd?

A

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
Q

Initialization (init) sequence on BSD distributions.

A
  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
Q

Initialization (init) sequence on System V distributions.

A
  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
Q

Key characteristics of upstart.

A
  • 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
Q

Key characteristics of systemd.

A
  • 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
Q

Which command is used to manage services and runlevels in systemd?

A

The systemctl command manages services and runlevels on systems that use systemd. It combines the functionality of service and chkconfig.

65
Q

How do you switch to runlevel 5 on systems that use systemd?

A

systemctl isolate runlevel5.target or systemctl isolate graphical.target

66
Q

What is the file that controls default runlevel on systems that use systemd?

A

/etc/systemd/system/default.target, which is a symbolic link to a runlevelX.target regular file.

67
Q

What is the command to view runlevel targets on systems that use systemd?

A

systemctl list-units –type=target

68
Q

What is the syntax of the command to change or view the state of services on systems that use systemd?

A

systemctl start|stop|restart|status service_name.service

69
Q

What is the syntax of the command enable or disable services on systems that use systemd?

A

systemctl enable|disable|is-enabled service_name.service

70
Q

Where are the systemd runlevel targets stored?

A

/lib/systemd/system

71
Q

How is the default runlevel set in systemd?

A

By creating a symbolic link from /etc/systemd/system/default.target to one of the targets in /lib/systemd/system.

72
Q

Where are the files for managing services located on a systemd system?

A

/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.