CST8177 - Linux II booting, services, SysVinit Todd Kelley kelleyt@algonquincollege.com CST8177- Todd Kelley 1 .midterm .more booting .SysVinit .services 2 Today's Topics .Power button pressed .BIOS .POST .MBR : contains grub stage 1 .grub stage 1 : to find grub stage 2 .grub stage 2 : to launch kernel .kernel running .init process (PID 1) : consults inittab ./etc/inittab ./etc/init.d/rc.sysinit ./etc/rc.d/rc 3 : assuming default runlevel 3 Booting Sequence (CentOS) CST8177 - Todd Kelley 3 ./etc/inittab contains records of the form .id:runlevels:action:process .id: identifies an entry .runlevels: the runlevels in which the action should be taken .action: the action that should be taken .process: the process to be executed /etc/inittab CST8177 - Todd Kelley 4 .Some of the possible Actions: .respawn: process to be restarted whenever it terminates .wait: process to be started once, and init will wait for its termination .once: process executed once upon entering runlevel .boot: executed during system boot (runlevels ignored) .bootwait: executed during system boot, and init waits for its termination (runlevels ignored) .initdefault: runlevel to be entered on system boot (process ignored) .sysinit: executed before any boot or bootwait (runlevels ignored) /etc/inittab (cont'd) CST8177 - Todd Kelley 5 .id:3:initdefault: .si::sysinit:/etc/rc.d/rc.sysinit .l0:0:wait:/etc/rc.d/rc 0 .l1:1:wait:/etc/rc.d/rc 1 .l2:2:wait:/etc/rc.d/rc 2 .l3:3:wait:/etc/rc.d/rc 3 .l4:4:wait:/etc/rc.d/rc 4 .l5:5:wait:/etc/rc.d/rc 5 .l6:6:wait:/etc/rc.d/rc 6 CentOS /etc/inittab CST8177 - Todd Kelley 6 .# consoles: virtual consoles CTRL-ALT-F(1-6) .1:2345:respawn:/sbin/mingetty tty1 .2:2345:respawn:/sbin/mingetty tty2 .3:2345:respawn:/sbin/mingetty tty3 .4:2345:respawn:/sbin/mingetty tty4 .5:2345:respawn:/sbin/mingetty tty5 .6:2345:respawn:/sbin/mingetty tty6 .# the X display manager (GUI) .x:5:respawn:/etc/X11/prefdm -nodaemon gettys and xdm CST8177 - Todd Kelley 7 .# default runlevel 3 ./etc/init.d/rc.sysinit ./etc/init.d/rc 3 When booting CST8177 - Todd Kelley 8 ./etc/init.d/* .these are scripts for starting, stopping, restarting services ./etc/rc.d/rc.N.d/* #where N is a runlevel .these are symbolic links to service's script .begins with K means service should not be running in that runlevel: call it with "stop" argument .begins with S means service should be running in that runlevel: call it with "start" argument .chkconfig maintains these scripts SysVinit scripts CST8177 - Todd Kelley 9 .all /etc/init.d/* scripts manageable by chkconfig have two or more commented lines .first tells chkconfig what runlevels, and start and stop priority .runlevels is "-" if by default should not be started in any runlevel .second is a description .For example: /etc/init.d/ntpd .# chkconfig: - 58 74 .# description: ntpd is the NTPv4 daemon. \ .# The Network .... chkconfig CST8177 - Todd Kelley 10 .The /etc/rc.d/rcN.d/ (N=0,1,2,3,4,5,6) directories contain symbolic links to scripts in /etc/init.d .These links are maintained by chkconfig .Upon entering runlevel 3 (for example): .each /etc/rc3.d/K* script is called with "stop" (if that service is running) .each /etc/rc3.d/S* script is called with "start" (if that service is not running) .The ordering of the scripts is given by the chkconfig priority, which is a number in the symlink name, that orders the scripts /etc/rc.d/rcN.d/* CST8177 - Todd Kelley 11 .example /etc/rc3.d/S03vmware-tools .vmware-tools is configured to run in runlevel 3 .otherwise, there would be a K99-vmware-tools script there instead .03 is the priority of starting vmware-tools service when entering that run level .This is a symlink to /etc/init.d/vmware-tools /etc/rc.d/rcN.d/* (cont'd) CST8177 - Todd Kelley 12 .service SCRIPT COMMAND [OPTIONS] .SCRIPT is /etc/init.d/SCRIPT .COMMAND is an argument to the script .start .stop .restart .etc .start and stop must be recognized by SCRIPT .Example: service ntpd start .same effect as /etc/init.d/ntpd start .Example: service ntpd stop .same effect as /etc/init.d/ntpd stop service - run a System V init script CST8177 - Todd Kelley 13