Automating Linux App Startup Session L51 David Boyes Sine Nomine Associates.

Slides:



Advertisements
Similar presentations
Introduction to Linux Linux startup process Unix Shells and scripts.
Advertisements

Booting and Shuting Down WeeSan Lee. Roadmap Bootstrapping Boot Loaders Startup/Init Scripts Reboot & Shutdown Q&A.
Genesis: from raw hardware to processes System booting sequence: how does a machine come into life.
Chapter 9: Understanding System Initialization The Complete Guide To Linux System Administration.
Booting and Shutting Down the UNIX Operating System Arcadio A. Sincero Jr. 6/6/2001 CMSC 691X, Section 6080.
Cosc 4750 Booting and shutdown. Bootstrapping Starting up a computer, load kernel into memory and begin executing. a vulnerable time, since errors in.
FreeBSD startup and repair AfNOG 2007 Abuja, Nigeria Hervey Allen Materials from Brian Candler.
LinuxChix System Startup and Recovery. What happens at startup? ● The BIOS loads and runs the MBR ● A series of "bootstrap" programs are loaded – see.
Chapter 2 Booting and Shutting Down Kim Grempler (Sections 2.0 to 2.3) Leon Dague (Sections 2.4 to 2.7)
Introduction to Linux Init Scripts In this session we will cover the Linux initialization process, run levels, how to change the run level and how to initialize.
 Starting up a computer › Load kernel into memory and execute it. (1)BIOS load and run the MBR (Master Boot Record) (2)MBR searches for the bootable.
Linux Boot Up Process Bootstrapping –Bootstrapping is the standard term for “ starting up a computer”. During bootstrapping, the kernel is loaded into.
Unix kernel Kernel refers to the core part of an operating system Historically, UNIX kernels are monolithic Newer versions of UNIX allow part of the kernel.
Information Networking Security and Assurance Lab National Chung Cheng University 1 if condition Condition is defined as: "Condition is nothing but comparison.
Starting and Stopping Linux. Boot Process BIOS initializes hardware –Loads the boot sector MBR loads the bootloader –Point to kernel Kernel initializes.
Processes & Daemons Chapter IV / Part III. Commands Internal commands: alias, cd, echo, pwd, time External commands, code is in a file: grep, ls, more.
System Startup and Shutdown
Chapter 2 Booting Up and Shutting Down. Computer Center, CS, NCTU 2 Boot Up?
Linux Shell. 2 Linux Command-Line Interface ■ Linux shells: A shell is a command interpreter that allows you to type commands from the keyboard to interact.
Linux System Administration LINUX SYSTEM ADMINISTRATION.
UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2012 by Scott Orr and the Trustees of Indiana University.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – Shell Programming The activities of.
Shell Programming, or Scripting Shirley Moore CPS 5401 Fall August 29,
Booting Up and Shutting Down. Computer Center, CS, NCTU 2 Booting Up  Starting up a computer Load kernel into memory and execute it. (1)BIOS load and.
Booting and boot levels
System Startup & Shutdown Objectives –to interpret the Unix startup and shutdown configuration files –to be able to create a customised run level Contents.
E X C E E D I N G E X P E C T A T I O N S RUNLEVELS Linux System Administration Dr. Hoganson Kennesaw State University A runlevel is a mode of operation.
1 Operating Systems Lecture 3 Shell Scripts. 2 Brief review of unix1.txt n Glob Construct (metacharacters) and other special characters F ?, *, [] F Ex.
1 Linux Basics for Networking. 2 Module - Linux Basics for Networking ♦ Overview This module focuses on the basics of networking using Redhat Enterprise.
CIT 470: Advanced Network and System AdministrationSlide #1 CIT 470: Advanced Network and System Administration Booting and Runlevels.
2/19/2003 Lecture 3 Computer System Administration Lecture 3 Setup (continued)
IBM GLOBAL SERVICES Nov , 2004 Miami, FL © Sine Nomine Associates 2004 zSeries Expo V86 David Boyes Supercharged VM Startup: A System V-Style INIT.
UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2010 by Scott Orr and the Trustees of Indiana University.
Linux Services Muhammad Amer. 2 xinetd Programs  In computer networking, xinetd, the eXtended InterNET Daemon, is an open-source super-server daemon.
Shell Scripting AFNOG IX Rabat, Morocco May 2008.
SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.
Guide to Linux Installation and Administration1 Chapter 4 Running a Linux System.
System Startup & Shutdown
Linux Startup Process Presenter: Dipu Gupta.
Linux Security. Module 13 – Linux Security ♦ Overview Linux is more prone today to security loopholes and attacks, both inside and outside the network.
(A Very Short) Introduction to Shell Scripts CSCI N321 – System and Network Administration Copyright © 2000, 2003 by Scott Orr and the Trustees of Indiana.
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
COMP075 OS2 Managing Linux Services. Services? Services are processes that start, usually when the system starts, and run, usually, until the system stops.
CIT 500: IT Fundamentals Startup. Slide #2 Topics 1.Booting 2.Bootstrap loaders 3.Run levels 4.Startup scripts 5.Shutdown and reboot.
Runlevel initialization. Boot to Linux Grub interface.
UNIX Startup and Shutdown CSCI N321 – System and Network Administration Copyright © 2000, 2009 by Scott Orr and the Trustees of Indiana University.
Unix System Administration Booting and Shutting Down Chapter 2.
ACCESS CONTROL. Components of a Process  Address space  Set of data structures within the kernel - process’s address space map - current status - execution.
If condition1 then statements elif condition2 more statements […] else even more statements fi.
Group, group, group One after the other: cmd1 ; cmd2 One or both: cmd1 && cmd2 Only one of them: cmd1 || cmd2 Cuddling (there):( cmd1 ; cmd2 ) Cuddling.
Sys Admin Course Service Management Fourie Joubert.
An Introduction to processes R Bigelow. A Unix Process A process in Unix is simple a program The Unix system is made up of a group of processes all interacting.
System initialization Unit objectives A.Outline steps necessary to boot a Linux system, configure LILO and GRUB boot loaders, and dual boot Linux with.
Using Networks. Assignment Issues find syntax Permissions HW4 3c /proc vs /tmp vs /var.
The Linux startup process Jerry Feldman The Linux Expertise Center Hewlett-Packard Company Document produced via OpenOffice.org.
System Administration Startup Process. Why Care? ● Every process on your system comes about by following a specific chain of events from the machine startup.
Getting Started with Linux
The Linux Kernel About 6 million lines of code
Operating System Basics
Chap-I Network and System Configuration in Linux
Booting Up and Shutting Down
Implementation of a simple shell, xssh (Section 1 version)
Session (1) Secure Unix Administration Who is a system administrator?
Linux Start Sequence Summary
Chapter 4 Booting and Shutdown
FreeBSD startup and repair
OPS235: Week 1 Installing Linux (Lab1: Investigations 4 - )
SUSE Linux Enterprise Desktop Administration
Linux and TCP/IP Networking
CST8177 Scripting 2: What?.
Presentation transcript:

Automating Linux App Startup Session L51 David Boyes Sine Nomine Associates

Agenda Runlevels, init, and symlinks, oh, my! Sequence of events during startup A sample application startup script Caveats on insserv, yast and friends Q&A (if we have time)

Why Do This? Like any other production system, applications need to start at boot time without human intervention. Presentation spawned by a discussion in the Hillgang (and later the Linux-390) mailing list in early October

Linux (and Unix) Startup Bootstrap loader for specific HW (stage1) 3card loader Stage 2 loader (grub, zilo, lilo) Kernel (vmunix) Init Runlevel scripts

Runlevels 0 = halt 1/S = single user 2 = single user with network 3 = multiuser with network, no graphics 4 = reserved for future use 5 = multiuser with network, graphical 6 = shutdown/reboot 7-9 = reserved for future use

Runlevels Specials: boot halt Not Sys V standard, but becoming common

init Always process 1 (careful with job control!) Two variations: System V and BSD Linux is System V based Solaris and AIX are SysV FreeBSD can be either (sysvinit package)

BSD init /etc/rc.boot /etc/rc.local /etc/rc. Difficult to manage for complex environment

Sys V init Mostly compatible at a high level /etc/rc.boot /etc/rc.local New: /etc/init.d/ /etc/init.d/rc.d/

Sys V init Startup scripts go in /etc/init.d Symlinks built in /etc/rc.d Snn  /etc/init.d/ Knn  /etc/init.d/ Both symlinks point to the same physical file Script called with different arguments to determine function

SysV init Scripts executed in numerical order on entry and exit from runlevel: Eg, S01xxx before S02xxx Scripts at same number are executed in alphabetic order (S01able before S01baker, etc) Called with ‘ start ’ Kxx scripts called on exit from runlevel Called with ‘ stop ’ parameter

SysV init SuSE and RH use numbering to force prereq management and startup sequencing Prereq/sequence checking based on magic header in file Automated tools will renumber things – caution! Scripts without magic headers are assigned S01 THIS MAY MAKE YOUR SYSTEM UNBOOTABLE!

Sample Script Header #! /bin/sh ### BEGIN INIT INFO # Provides: sshd # Required-Start: $network # Required-Stop: $network # Default-Start: 3 5 # Default-Stop: # Description: Start the sshd daemon ### END INIT INFO. /etc/rc.status. /etc/sysconfig/ssh

Script Header, Cont. # Shell functions sourced from /etc/rc.status: # rc_check check and set local and overall rc status # rc_status check and set local and overall rc status # rc_status -v ditto but be verbose in local rc status # rc_status -v -r ditto and clear the local rc status # rc_failed set local and overall rc status to failed # rc_reset clear local rc status (overall remains) # rc_exit exit appropriate to overall rc status # First reset status of this service rc_reset

Script Header (RH) #!/bin/bash # # xinetd This starts and stops xinetd. # # chkconfig: # description: xinetd is a powerful replacement for inetd. \ # [… text omitted..] # processname: /usr/sbin/xinetd # config: /etc/sysconfig/network # config: /etc/xinetd.conf # pidfile: /var/run/xinetd.pid PATH=/sbin:/bin:/usr/bin:/usr/sbin # Source function library.. /etc/init.d/functions

Samples Start with the working versions in /etc/init.d. ‘ man init.d ’ Don ’ t try to manipulate the links manually

Sample Script case "$1" in start) if ! test -f /etc/ssh/ssh_host_key ; then echo Generating /etc/ssh/ssh_host_key. ssh-keygen -t rsa1 -b f /etc/ssh/ssh_host_key -N '' fi [ …. Code omitted … ] echo -n "Starting SSH daemon" ## Start daemon with startproc(8). If this fails ## the echo return value is set appropriate. startproc -f /usr/sbin/sshd $SSHD_OPTS # Remember status and be verbose rc_status -v ;;

Sample Script stop) echo -n "Shutting down SSH daemon" ## Stop daemon with killproc(8) and if this fails ## set echo the echo return value. if [ -x /bin/netstat ]; then netstat -nlp 2>/dev/null | while read prot a b local remote state pro g; do if [ "${local##*:}" = "22" ] ; then if [ -n "$prog" ]; then kill -TERM ${prog%/*} fi done else rc_failed 1 fi # Remember status and be verbose rc_status -v ;;

Sample Script try-restart) ## Stop the service and if this succeeds (i.e. the ## service was running before), start it again. $0 status >/dev/null && $0 restart # Remember status and be quiet rc_status ;;

Sample Script restart) ## Stop the service and regardless of whether it was ## running or not, start it again. $0 stop $0 start # Remember status and be quiet rc_status ;;

Sample Script force-reload|reload) ## Signal the daemon to reload its config. Most daemons ## do this on signal 1 (SIGHUP). echo -n "Reload service sshd" [ … code omitted...] rc_status -v ;;

Sample Script status) echo -n "Checking for service sshd: " ## Check status with checkproc(8), if process is running ## checkproc will return with exit status 0. # Status has a slightly different for the status command: # 0 - service running # 1 - service dead, but /var/run/ pid file exists # 2 - service dead, but /var/lock/ lock file exists # 3 - service not running if [ -x /bin/netstat ]; then netstat -nlp 2>/dev/null | ( while read prot a b local remote state p rog; do [ … code omitted … ] fi rc_status -v ;;

Sample Script probe) ## Optional: Probe for the necessity of a reload, ## give out the argument which is required for a reload. test /etc/ssh/sshd_config -nt /var/run/sshd.pid && echo reload ;;

Sample Script *) echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|relo ad|probe}" exit 1 ;; esac rc_exit

Linux Tools for Manipulating init insserv chkconfig /etc/sysconfig Not really a tool, but a place to store config info, Bourne shell syntax

chkconfig chkconfig -s|--set [name state] chkconfig -e|--edit [names] chkconfig -c|--check name [state] chkconfig -l|--list [--deps] [names] chkconfig -a|--add [names] chkconfig -d|--del [names]

Danger, Will Robinson! SLES 7 insserv is BROKEN Make sure your scripts have correct headers! SLES 8 insserv is OK. Works OK in RH Note that comment header is different in RH, but both RH and United Linux headers can be in same file.

Q&A

Contact Info David Boyes Sine Nomine Associates