diff options
author | Willy Tarreau <willy@wtap.(none)> | 2006-07-26 11:59:30 +0200 |
---|---|---|
committer | Willy Tarreau <willy@wtap.(none)> | 2006-07-26 11:59:30 +0200 |
commit | 015a749c05281a4293ad2eade8361c3575bc0191 (patch) | |
tree | 485b632faffeb5449eeeacc5193cde5fd094aa8b | |
parent | Initial commit (diff) | |
download | init-scripts-015a749c05281a4293ad2eade8361c3575bc0191.tar.gz |
[RELEASE] init-scripts-0.1v0.1
-rw-r--r-- | .flxfiles | 26 | ||||
-rwxr-xr-x | .preinit | 56 | ||||
-rw-r--r-- | ChangeLog | 9 | ||||
l--------- | etc/initscript | 1 | ||||
-rwxr-xr-x | etc/startup.rc | 20 | ||||
-rwxr-xr-x | sbin/init.d/crond | 18 | ||||
-rwxr-xr-x | sbin/init.d/echelogd | 144 | ||||
-rwxr-xr-x | sbin/init.d/functions | 875 | ||||
-rwxr-xr-x | sbin/init.d/keyboard | 18 | ||||
-rwxr-xr-x | sbin/init.d/klogd | 11 | ||||
-rwxr-xr-x | sbin/init.d/logrotate | 16 | ||||
-rwxr-xr-x | sbin/init.d/monitor | 46 | ||||
-rwxr-xr-x | sbin/init.d/mouse | 16 | ||||
-rwxr-xr-x | sbin/init.d/network | 407 | ||||
-rwxr-xr-x | sbin/init.d/ntp | 55 | ||||
-rwxr-xr-x | sbin/init.d/pdnsd | 16 | ||||
-rwxr-xr-x | sbin/init.d/sshd | 20 | ||||
-rwxr-xr-x | sbin/init.d/stat | 100 | ||||
-rwxr-xr-x | sbin/init.d/syslog-ng | 28 | ||||
-rwxr-xr-x | sbin/init.d/sysprofiles | 3 | ||||
-rwxr-xr-x | sbin/init.d/system | 76 | ||||
-rwxr-xr-x | sbin/init.d/thttpd | 27 | ||||
-rwxr-xr-x | sbin/initscript | 10 | ||||
-rwxr-xr-x | sbin/rc.0 | 83 | ||||
l--------- | sbin/rc.6 | 1 | ||||
-rwxr-xr-x | sbin/rc.K | 41 | ||||
-rwxr-xr-x | sbin/rc.M | 68 | ||||
-rwxr-xr-x | sbin/rc.S | 126 |
28 files changed, 2317 insertions, 0 deletions
diff --git a/.flxfiles b/.flxfiles new file mode 100644 index 0000000..7ed6ff4 --- /dev/null +++ b/.flxfiles @@ -0,0 +1,26 @@ +sbin/init.d/echelogd +sbin/init.d/functions +sbin/init.d/keyboard +sbin/init.d/klogd +sbin/init.d/monitor +sbin/init.d/mouse +sbin/init.d/network +sbin/init.d/ntp +sbin/init.d/sshd +sbin/init.d/stat +sbin/init.d/syslog-ng +sbin/init.d/sysprofiles +sbin/init.d/system +sbin/init.d/thttpd +sbin/init.d/pdnsd +sbin/init.d/crond +sbin/init.d/logrotate +sbin/rc.0 +sbin/rc.6 +sbin/rc.K +sbin/rc.M +sbin/rc.S +sbin/initscript +etc/initscript +etc/startup.rc +.preinit diff --git a/.preinit b/.preinit new file mode 100755 index 0000000..90772b5 --- /dev/null +++ b/.preinit @@ -0,0 +1,56 @@ +#!/sbin/init < +# This .preinit is to be copied onto a hard disk to be used as-is. +# Don't forget to change the links at the bottom ! +# +# mem, kmem, null, zero, random, urandom, tty0, tty, console, ptmx, initctl +# full, fd +mt /proc /proc proc rw + +# we first try to mount /tmp as a tmpfs, next /var if it fails. +mt /tmp /tmp tmpfs rw +|mt /var /var tmpfs rw +md /var/tmp 1777 +md /var/run 755 +md /dev/pts 755 + +bl 0600 0 0 3 0 hd[c,ab,64][I,0-16,1] +bl 0600 0 0 22 0 hd[c,cd,64][I,0-16,1] +bl 0600 0 0 33 0 hd[c,ef,64][I,0-16,1] +bl 0600 0 0 8 0 sd[c,a-h,16][I,0-15,1] +md /dev/rd 755 # DAC960 raid disks (majors 48-55) +bl 0600 0 0 48 0 rd/c0d[i,0-31,8] +bl 0600 0 0 48 1 rd/c0d[i,0-31,8]p[i,1-7,1] +md /dev/ida 755 # Compaq raid disks (majors 72-79) +bl 0600 0 0 72 0 ida/c0d[i,0-15,16] +bl 0600 0 0 72 1 ida/c0d[i,0-15,16]p[i,1-15,1] +bl 0600 0 0 11 0 sr[i,0-16,1] +ch 0600 0 0 9 0 st[i,0-15,1] +bl 0600 0 0 9 0 md[i,0-15,1] +bl 0600 0 0 2 0 fd0 +bl 0600 0 0 2 28 fd0u1440 +ch 0600 0 5 2 0 pty[c,p-za-f,16][h,0-f,1] +ch 0600 0 5 3 0 tty[c,p-za-f,16][h,0-f,1] +ch 0600 0 5 4 1 tty[i,1-12,1] +bl 0600 0 0 7 0 loop[i,0-9,1] +bl 0600 0 0 1 0 ram[i,0-9,1] +ch 0600 0 5 4 64 ttyS[i,0-9,1] +ch 0600 0 3 10 1 psaux +bl 0400 0 0 1 250 initrd +md /dev/input 755 +ch 0600 0 0 13 63 input/mice + +ln psaux /dev/mouse +ln hdc /dev/cdrom + +md /dev/fs 755 + +# The partitions are referenced here, so that +# lilo.conf and fstab only use links. +ln hda /dev/mbr +ln hda1 /dev/boot +ln hda2 /dev/swap +ln hda3 /dev/root +ln ../hda6 /dev/fs/var + +in /sbin/init-sysv + diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..4efaf74 --- /dev/null +++ b/ChangeLog @@ -0,0 +1,9 @@ +2003/01/26: echelog +- lecture du fichier de configuration de echelog, déduction des sous fichiers + de configuration et des répertoires de spool +- do_stop spécifique +20030115-b : +- ntp: option keys à utiliser sous la forme opt_keys dans cmdline +- ntp: positonnel procname à ntpd +* echelogd: traiter l'impossibilité d'ouverture pour cause de mauvais + positionnement dans le cache du Sender/Receiver diff --git a/etc/initscript b/etc/initscript new file mode 120000 index 0000000..5193c03 --- /dev/null +++ b/etc/initscript @@ -0,0 +1 @@ +../sbin/initscript
\ No newline at end of file diff --git a/etc/startup.rc b/etc/startup.rc new file mode 100755 index 0000000..c41dbe5 --- /dev/null +++ b/etc/startup.rc @@ -0,0 +1,20 @@ +#!/bin/sh + +/sbin/init.d/sysprofiles /etc/config.rc + +#echo 1 > /proc/sys/net/ipv4/ip_forward +#/sbin/init.d/network restart lo +#/sbin/modprobe softdog 15 +#/sbin/modprobe button +#/sbin/modprobe i2c-viapro +#/sbin/modprobe i2c-isa +#/sbin/modprobe via686a +#/sbin/modprobe eeprom +#/sbin/modprobe via82cxxx_audio +#/sbin/modprobe usb-uhci +#/sbin/modprobe usb-storage +#/sbin/modprobe sd_mod +##/sbin/modprobe hid +##/sbin/modprobe mousedev +##/sbin/modprobe keybdev + diff --git a/sbin/init.d/crond b/sbin/init.d/crond new file mode 100755 index 0000000..26dcf1b --- /dev/null +++ b/sbin/init.d/crond @@ -0,0 +1,18 @@ +#!/bin/bash + +. `dirname $0`/functions + +option bin reserved_option /usr/sbin/crond +option cmdline reserved_option '$bin' + +pidfile=/var/run/cron.pid +crontab=/etc/crontab +crontabdir=/var/spool/cron + +function fct_pre_start { + if [ ! -d $crontabdir] ; then + mkdir -p -m 750 $crontabdir || return 1 + fi +} + +load_config diff --git a/sbin/init.d/echelogd b/sbin/init.d/echelogd new file mode 100755 index 0000000..53f606c --- /dev/null +++ b/sbin/init.d/echelogd @@ -0,0 +1,144 @@ +#!/bin/bash + +. `dirname $0`/functions + +option bin reserved_option /opt/echelog/sbin/echelogd +option config standard_option /etc/echelog/echelog.conf +option runas standard_option echelogc:daemon +option cmdline reserved_option '$bin -C $opt_config' +#option check_interval reserved_option 60 + +# assign default values to options and variables before parsing the cfg file +function fct_pre_start { + local path=$( dirname $opt_config ) + local file + + if [ ! -r $opt_config ] ; then + echo "Can't read configuration file '$opt_config'." + exit 1 + fi + while read ; do + set -- $REPLY + if [ "$1" = Module ] ; then + # build all directories + for file in $( grep -i "^\(SpoolDir\|StateDir\)" $path/$(eval echo $4) \ + | awk '{print $2}' ) ; do + if [ -d "$file" ] ; then : + elif [ -L "$file" -a -d "$( readlink $file )" ] ; then : + elif [ -e "$file" ] ; then + echo "Wished directory '$file' isn't a directory." + exit 1 + else + mkdir -p -m 700 $file || { echo "Can't create directory '$file'."; exit 1; } + chown $opt_runas $file + fi + done + # sender module initialization + if [ "$3" = "sender" ] ; then + valueof $path/$(eval echo $4) SpoolDir > /dev/null 2>&1 + if [ ! -e "$REPLY/spool.dat" ] ; then + touch $REPLY/.renumbered && chown $opt_runas $REPLY/.renumbered + fi + fi + fi + done < $opt_config + + # check others directories + for path in /var/lib/echelog/{socks,run} /var/{cache,log}/echelog ; do + if [ ! -e $path ] ; then + mkdir -p -m 700 $path # && chown $opt_runas $path + fi + done +} + +function kill_pid { + REPLY=$* + retry=0 + while [ "$REPLY" ]; do + retry=$[$retry+1] + if [ $retry == 1 ] ; then + $(dirname $bin)/echelogctl stop && sleep 5 || break + REPLY=`ps ho pid $REPLY` + continue + fi + if [ $retry -le 3 ]; then kill -CONT $REPLY && kill -$STOP_FIRST_WITH $REPLY || break; sleep $retry + elif [ $retry -gt 3 ]; then kill -9 $REPLY || break; sleep 1 + else break; fi + REPLY=`ps ho pid $REPLY` + done +} + +function do_stop { + local pname=$1 + local instname=$2 + local pid + local retry + shift + + pname=${procname:-$pname} + + # stop service from pidof data + svc_pidof -o $$ $pname > /dev/null + echo "# Stopping process $pname${instname:+[$instname]} (pids : $REPLY) ..." + retry=0 + + kill_pid $REPLY + + if [ "$REPLY" ]; then + echo " ==> stop $pname${instname:+[$instname]} Failed. (pids : $REPLY)" + return 1 + else + declare -F fct_post_stop >/dev/null && fct_post_stop $pname $instname + echo " ==> stop $pname${instname:+[$instname]} Done." + return 0 + fi +} + + +function fct_post_stop { + while read ; do + set -- $REPLY + if [ "$1" == Define ] ; then + kill_pid $( ps ho pid -C $( basename $( eval echo $3) ) ) + fi + done < $opt_config +} + + +function do_status { + local pname=$1 + local instname=$2 + local pids return=0 + shift + + pname=${procname:-$pname} + + # get info from pidof command + svc_pidof -o $$ $pname > /dev/null ; pids=$REPLY + if [ "$pids" ] ; then + echo "Process $pname${instname:+[$instname]} running without pidfile:$pids" + else + echo "Process $pname${instname:+[$instname]} stopped (no pidfile used)." + return=1 + fi + pids="" + while read ; do + set -- $REPLY + if [ "$1" == Define ] ; then + pids=${pids:+$pids }$( ps ho pid -C $( basename $( eval echo $3) ) ) + fi + done < $opt_config + if [ "$pids" ] ; then + echo "Children processes running pidfile:$( echo $pids )" + fi + return $return +} + + + +function do_check { + echo "$HOSTNAME $1.$2 $(date +%s) RUNNING 0 OK" +} + +load_config + diff --git a/sbin/init.d/functions b/sbin/init.d/functions new file mode 100755 index 0000000..b154a43 --- /dev/null +++ b/sbin/init.d/functions @@ -0,0 +1,875 @@ +#!/bin/bash + +# not used ? ## DEBUG FILE +# not used ? #DEBUG=/tmp/.flx.$PID.$RANDOM +# not used ? #[ -e "$DEBUG" ] && rm -f $DEBUG && touch $DEBUG +# not used ? #if [ $? != 0 ] ; then DEBUG="" ; fi + +# Test for previous sourcing already in progress +declare -F build_default_func > /dev/null && return + +# SSHD starts this script with "-c" followed by all the parameters grouped into +# one single string. So we expand it to allow remote commands. +if [ "$1" = "-c" ]; then shift; set -- $*; fi + +# Configuration file to use. Default : /etc/config.rc +export CONFIG=${CONFIG:-/etc/config.rc} + +# Path to startup scripts. Default : /sbin/init.d +# INIT_PATH=${INIT_PATH:-/sbin/init.d} +INIT_PATH=${INIT_PATH:-`dirname $0`} + +# Process name +PNAME=`basename $0` +PPATH=`dirname $0` +PFULLNAME=$0 + +# Global variable for status information. Set to "1" while processing the right +# section. +RUNNING_SECTION= + +# goes "1" if at least one instance of the required service has been found +SVC_FOUND= + +# no particular function defined yet +DEFINED_FUNCTIONS= + +# not in list mode +MUST_LIST_SECTIONS= + +# no option filter +OPTION_FILTER= + +# signal to use at first when stopping a service. Default: TERM +# May be changed by any init script (eg: sshd) +STOP_FIRST_WITH=TERM + +# set with --force to ignore current status +FORCE_START_STOP=0 + +# controls wether the service is being started with --auto +SVC_AUTO_START=0 + +# facility for syslog message +G_FACILITY=local3 + +# LOG FILE +LOGFILE=/var/log/startup.log +[ -L "$LOGFILE" ] && rm -f $LOGFILE + +# the scripts can list some global variables which they use and that should be +# unset after processing the service. This is to be set globally. +SVC_VARS= + +# this is set to $? for the first do_xxx which doesn't return 0 +STATUS_RET=0 + +######################################## +# BASIC FUNCTIONS # +######################################## +function logit { + # echo -n "'" + # echo -n "$*" | sed -e "s/'/\\\\'/" -e "s/§/' '/g" + # echo "'" + echo " $*" + [ "${1##\#*}" -a "xG_FACILITY" != x ] && \ + logger -p $G_FACILITY.info -t "flxi[$$].$PNAME" -- \ + "exec[$USER]: $*" + $* + local return=$? + [ $return != 0 -a "xG_FACILITY" != x ] && \ + logger -p $G_FACILITY.info -t "flxi[$$].$PNAME" -- \ + "exec.error[$USER]: $return" + return $return +} + +# returns the value for a given parameter in a config file. The value is both +# echoed and set to the REPLY variable. +# usage: valueof CONFIGFILE PARAMETER +function valueof { + REPLY=$( awk 'BEGIN { FS="[:= \\t]+"} {gsub("#.*", "", $0); \ + if (match($1, "^'$2'$")) { \ + gsub("^[:= \\t]*'$2'[:= \\t]+", "", $0); print $0 } }' $1 ) + echo $REPLY +} + +# returns children processes ids. +# usage: getchild PID ... +function childrenpid { + local found + local pid=" $* " + + set -- $( exec ps ahxo ppid,pid ) ; while [ $# -gt 0 ] ; do + [ -z "${pid/* $1 */}" ] && found="$found $2" ; shift ; shift ; done + + REPLY="" && [ "$found" ] && REPLY=$found && echo $REPLY +} + + +# Returns process id from process name only by looking at the process table. +# (ie: no pidfile used). Only processes which have ppid of 1 (or parent_pid) +# are returned. A list of pids to omit can be specified with "-o". +# If no process name is specified, all the parent's children are returned. +# svc_pidof [ -o "omit_pids*" ]* [ -p parent_pid ] [ PNAME ... ] +function svc_pidof { + local omit=x + local ppid=1 + local comm + local found + + while [ $# -gt 0 ] ; do + if [ "x$1" = "x-o" ] ; then omit="$omit ${2/%PPID/$$} " ; shift 2 + elif [ "x$1" = "x-p" ] ; then ppid="$2" ; shift 2 + else comm="$comm $1 " ; shift 1 + fi + done + + #set -- "$( exec ps ahxo pid,ppid,comm )" ; set -- $( echo "$1" | awk '{ print $1,$2,$3}' ) + set -- $( ps ahxo pid,ppid,comm | awk '{ print $1,$2,$3}' ) + while [ $# -gt 0 ] ; do + [ -z "${comm/* $3 */}" -a -n "${omit/* $1 */}" -a "$2" = "$ppid" ] && found="$found $1" + shift ; shift ; shift + done + REPLY="" && [ "$found" ] && REPLY=$found && echo $REPLY +} + +######################################## +# CONFIGURATION FILE LOADING FUNCTIONS # +######################################## + +# All functions handling options get the option name as a first argument, +# then the rest of the line follows. + +# default function for config directive. This one is called only for unmapped +# options, so either bad ones or unused services. +function default_config_option { + [ "$RUNNING_SECTION" ] && echo "Bad option '$1' in '$*'" +} + +# builtin function to create a variable from an option. +# The variable name is "opt_$option" where option is the option name. +function standard_option { + if [ "x$2" = "x--disable" ]; then + eval "opt_$1=" + else + eval "opt_$1='$2'" + fi +} + +# builtin function to create a variable from an option. +# The variable name is "opt_$option" where option is the option name. +function boolean_option { + if [ "x$2" = "x--disable" ]; then + eval "opt_$1=0" + else + eval "opt_$1=1" + fi +} + +# builtin function to create a variable from an option. +# The variable name is the same as the option name. +# This is mainly used for reserved options such as "bin" and "cmdline", +# or to port older startup scripts. +# The option value is NOT evaluated now, which means that cmdline can refer to +# $bin if properly quoted. Eg: cmdline '$bin -f $config' +function reserved_option { + if [ "x$2" = "x--disable" ]; then + eval "$1=" + else + eval "$1='$2'" + fi +} + +# builtin function to create a variable from an option. +# The variable name is "opt_$option" where option is the option name. +function long_option { + if [ "x$2" = "x--disable" ]; then + eval "opt_$1=" + else + local optname=$1 + shift + eval "opt_$optname='$*'" + fi +} + +# builtin function to create an array from an option. +# The variable name is "opt_$option" where option is the option name. +# The array is extended with all the args for each occurence of the option. +# If no arg is given, the option is extended with a single dash '#' so that +# we further know that it has been called. +function multiple_option { + if [ "x$2" = "x--disable" ]; then + # in case of multiple_option, "no <option> <args>" only + # means that we don't want to add <args> to <option>, + # but not that we want to clear <option> + # eval "opt_$1=( )" + : + else + local optname=$1 + shift + if [ $# -gt 0 ]; then + #eval "opt_$optname=( \$opt_$optname \"$*\" )" + eval "opt_$optname[\${#opt_$optname[*]}]='$*'" + else + # if no option is set, this reference will be lost because in fact + # it will be added as an empty entry in the list. So we replace it + # with a dash '#' to mark it as referenced. + eval "opt_$optname[\${#opt_$optname[*]}]='#'" + fi + fi +} + +# not used ? ## backup all defined functions +# not used ? #function backup_func { +# not used ? # BACKUP_FUNC="$( declare -f | sed 's/^declare -f /function /' )" +# not used ? #} +# not used ? # +# not used ? ## restore all previous defined functions +# not used ? #function restore_func { +# not used ? # # remove all defined functions +# not used ? # for func in $( declare -F | sed 's/^declare -f //') ; do unset -f $func ; done +# not used ? # eval "$BACKUP_FUNC" +# not used ? #} +# not used ? # +# not used ? ## backup variable with value +# not used ? #function backup_set { +# not used ? # BACKUP_SET="$( set | grep "^[a-zA-Z_][a-zA-Z0-9_]*=[^(]" )" +# not used ? #} +# not used ? # +# not used ? ## restore original values to variables +# not used ? #function restore_set { +# not used ? # unset -v $( set | grep "^[a-zA-Z_][a-zA-Z0-9_]*=[^(]" | cut -f1 -d= ) +# not used ? # eval "$BACKUP_SET" +# not used ? #} +# not used ? # + +# not used ? ## 'need_svc' function start needed service and wait a valid return +# not used ? #function need_svc { +# not used ? # local p=$1 +# not used ? # if [ -x $INIT_PATH/$p ] ; then +# not used ? # ( $INIT_PATH/$p $ACTION ) & +# not used ? # while [ -L /proc/$!/cwd ] ; do +# not used ? # echo "Waiting for $p to $ACTION ..." +# not used ? # done +# not used ? # fi +# not used ? # return 0 +# not used ? #} +# not used ? # +# not used ? ## 'try_svc' function start needed service before running +# not used ? #function try_svc { +# not used ? # return 0 +# not used ? #} +# not used ? # +# not used ? ## check configuration and re-set arguments that do not work +# not used ? #function set_config { +# not used ? # declare -F check_config >/dev/null || return 0 +# not used ? # check_config | while read ; do +# not used ? # set -- $REPLY +# not used ? # if [ "$1" = "KO:" ] ; then +# not used ? # shift +# not used ? # logit $* +# not used ? # fi +# not used ? # done +# not used ? #} + +# unusable for several instances ## 'replace' function to reassign +# unusable for several instances ## if replace first parameter is '-', do not repeat orginal func +# unusable for several instances ## name as first parameter of the replacement function +# unusable for several instances #function replace { +# unusable for several instances # [ "$RUNNING" != 1 ] && return +# unusable for several instances # if [ "x$1" = "x-" ] ; then +# unusable for several instances # shift +# unusable for several instances # eval "function do_$1 { $2 \$* ; }" +# unusable for several instances # else +# unusable for several instances # eval "function do_$1 { $2 $1 \$* ; }" +# unusable for several instances # fi +# unusable for several instances #} + +# default start function +# usage : do_start process_name [instance_name] +# if functions fct_pre_start() and fct_post_start() are defined, they will be +# called just before and just after the cmdline. +function do_start { + local p=$1 + local instname=$2 + local ret + do_status $p $instname > /dev/null 2>&1 + if [ $? = 0 -a $FORCE_START_STOP -eq 0 ] ; then + echo "Process $p${instname:+[$instname]} already running." + [ $SVC_AUTO_START -eq 0 ] && echo " ==> please use '--force' or 'restart' instead or check with 'status'." + return 0 + fi + + echo "# Starting $p${instname:+[$instname]} ..." + declare -F fct_pre_start >/dev/null && fct_pre_start $p $instname + logit $cmdline + ret=$? + declare -F fct_post_start >/dev/null && fct_post_start $p $instname + [ $ret -eq 0 ] && echo " ==> start $p${instname:+[$instname]} Done." || \ + { echo " ==> start $p${instname:+[$instname]} Failed." ; return 1 ; } + return 0 +} + +# +# This function tries to stop the process whose pid is specified in the file +# in $1. It returns 0 if the process is stopped, or 1 if it is still running. +# There can be only one pid per pidfile. +# +# usage : do_stop_with_pidfile pidfile [process_name [instance_name]] +# if functions fct_pre_stop() and fct_post_stop() are defined, they will be +# called just before and just after a successful kill sequence. +function do_stop_with_pidfile { + local pid + local pids + local pidfile=$1 + local pname=$2 + local instname=$3 + + svc_pidof -o $$ $pname > /dev/null ; pids=$REPLY + + if [ $FORCE_START_STOP -eq 0 ]; then + if ! [ -r "$pidfile" ] || ! read pid REPLY <"$pidfile" || ! [ -L /proc/$pid/cwd ]; then + echo "# Process $pname${instname:+[$instname]} already stopped (according to $pidfile)${pids:+, but check pids :$pids}" + return 0 + fi + fi + + valueof /proc/$pid/status Name >/dev/null ; set -- $REPLY + if [ "$pname" -a "x$pname" != "x$1" -a $FORCE_START_STOP -eq 0 ]; then + echo "# The pid in $pidfile points to a wrong process name ($pid:$1)${pids:+. Check $pids for $pname${instname:+[$instname]}}." + return 1; + fi + + echo "# Stopping $pname${instname:+[$instname]} (pid $pid according to $pidfile) ..." + declare -F fct_pre_stop >/dev/null && fct_pre_stop $pname $instname + kill -CONT $pid; kill -$STOP_FIRST_WITH $pid ; set -- 0 1 2 3 + while [ -L /proc/$pid/cwd -a $# -gt 0 ] ; do sleep $1 ; shift ; done + [ -L /proc/$pid/cwd ] && { kill -9 $pid ; sleep 1 ; } + [ -L /proc/$pid/cwd ] && { echo " ==> stop $pname${instname:+[$instname]} Failed." ; return 1; } + if [ -e "$pidfile" ]; then rm -f "$pidfile"; fi + declare -F fct_post_stop >/dev/null && fct_post_stop $pname $instname + echo " ==> stop $pname${instname:+[$instname]} Done." + return 0 +} + +# +# default stop function +# If a pidfile exists, it is used. Otherwise, all pids with same name which have +# init for parent will be killed. +# The function returns 0 if the process is(are) stopped, and 1 if not all could +# be stopped. +# +# usage : do_stop process_name [instance_name] +# if functions fct_pre_stop() and fct_post_stop() are defined, they will be +# called just before and just after a successful kill sequence. +function do_stop { + local pname=$1 + local instname=$2 + local pid + local retry + shift + + pname=${procname:-$pname} + # stop service from pidfile + [ "x$pidfile" != x ] && { do_stop_with_pidfile $pidfile $pname $instname; return $? ; } + + # stop service from pidof data + svc_pidof -o $$ $pname > /dev/null + if [ -z "$REPLY" ]; then + echo "# Process $pname${instname:+[$instname]} already stopped, cleaning up..." + declare -F fct_post_stop >/dev/null && fct_post_stop $pname $instname + echo " ==> stop $pname${instname:+[$instname]} Done." + return 0 + fi + echo "# Stopping process $pname${instname:+[$instname]} (pids : $REPLY) ..." + retry=$REPLY; # save it temporarily + declare -F fct_pre_stop >/dev/null && fct_pre_stop $pname $instname + REPLY=$retry; retry=0 + while [ "$REPLY" ]; do + retry=$[$retry+1] + if [ $retry -le 3 ]; then kill -CONT $REPLY && kill -$STOP_FIRST_WITH $REPLY || break; sleep $retry + elif [ $retry -gt 3 ]; then kill -9 $REPLY || break; sleep 1 + else break; fi + REPLY=`ps ho pid $REPLY` + done + if [ "$REPLY" ]; then + echo " ==> stop $pname${instname:+[$instname]} Failed. (pids : $REPLY)" + return 1 + else + declare -F fct_post_stop >/dev/null && fct_post_stop $pname $instname + echo " ==> stop $pname${instname:+[$instname]} Done." + return 0 + fi +} + +function do_restart { + do_stop $* + do_start $* +} + +# returns a basic check of the service, an returns one line of info of the form: +# <hostname> <service_name>.[instance_name] <date_in_secs> {RUNNING|STOPPED}[,more_info] [{OK|CONFIG_CHANGED}] +# returns 0 if running. +function do_check { + local run_stat + local status=OK + local ret uptime=0 + local pid + + do_status $1 $2 > /dev/null + ret=$? + if [ $ret -eq 0 ]; then + if [ "$REPLY" ]; then + for pid in $REPLY; do + uptime=$[$(date +%s)-$(date -d "`ps ho lstart $pid`" +%s)] + echo "`uname -n` $1.$2 `date +%s` RUNNING $uptime $status" + done + else + echo "`uname -n` $1.$2 `date +%s` RUNNING 0 $status" + fi + else + run_stat=STOPPED + case $ret in + 1) status=ALERT,nofile ;; + 2) status=ALERT,nopid ;; + 3) status=ALERT,other ;; + *) status=ALERT ;; + esac + echo "`uname -n` $1.$2 `date +%s` $run_stat $uptime $status" + fi + return $ret +} + +# returns 0 if the process is running, 1 if the pid file does not exist, +# 2 if the pid doesn't exist anymore, 3 if it has been affected to another +# process name. If the process is running, REPLY is set to its pid. +# usage : do_status_with_pidfile pidfile [process_name [instance_name]] +function do_status_with_pidfile { + local pidfile=$1 + local pname=$2 + local instname=$3 + local pid + + [ -r "$pidfile" ] || { echo "Process $pname${instname:+[$instname]} stopped (no pidfile present)" ; return 1 ; } + read pid < $pidfile + [ -L /proc/$pid/cwd ] || { echo "Process $pname${instname:+[$instname]} stopped (from pidfile)" ; return 2 ; } + valueof /proc/$pid/status Name >/dev/null ; set -- $REPLY + [ "$pname" -a "x$pname" = "x$1" ] || { + echo "Process with an other name ($1,$pid) already running." + echo " ==> you should remove invalid pidfile $pidfile" + return 3 + } + childrenpid $pid > /dev/null + local cpid=$* + echo "Process $pname${instname:+[$instname]} running :$pid ${cpid:+($cpid)}" + REPLY=$pid + return 0 +} + +# returns 0 if the process is running; 1 if it's stopped and there's no pid file, +# otherwise same as do_status_with_pidfile(). If the process is running, REPLY is +# set to its pid. +# usage : do_status process_name [instance_name] +function do_status { + local pname=$1 + local instname=$2 + shift + + pname=${procname:-$pname} + # get info from pidfile if it exist + [ "x$pidfile" != x ] && { do_status_with_pidfile $pidfile $pname $instname; return $? ; } + + # get info from pidof command + svc_pidof -o $$ $pname > /dev/null ; pids=$REPLY + [ "$pids" ] && { echo "Process $pname${instname:+[$instname]} running without pidfile:$pids" ; return 0 ; } + echo "Process $pname${instname:+[$instname]} stopped (no pidfile used)." + return 1 +} + +# lists all the known options for the current service, with their default or +# assigned values. There is a double eval so that options depending on others +# are correctly resolved. +# The output format is "process_name.[instance_name] option value" +# usage : list_options process_name [instance_name] +function do_list_options { + local i=0 + local occur=0 + local nbocc=0 + local inst="$1.$2" + + while [ $i -lt $svc_nbopts ]; do + if [ -z "$OPTION_FILTER" -o "$OPTION_FILTER" = "${svc_opts[$i]}" ]; then + + + if [ "${svc_fcts[$i]}" = "boolean_option" -o \ + "${svc_fcts[$i]}" = "standard_option" -o \ + "${svc_fcts[$i]}" = "long_option" -o \ + "${svc_fcts[$i]}" = "reserved_option" ]; then + eval eval echo $inst ${svc_opts[$i]} \$"${svc_vars[$i]}" + elif [ "${svc_fcts[$i]}" = "multiple_option" ]; then + eval nbocc='${#'"${svc_vars[$i]}"'[*]}' + if [ $nbocc -eq 0 ]; then # no value, let's at least show the option name + eval echo $inst ${svc_opts[$i]} + else + while [ $occur -lt $nbocc ]; do + eval eval echo $inst ${svc_opts[$i]} '${'"${svc_vars[$i]}"'[$occur]}' + occur=$[$occur+1] + done + fi + else + echo $inst ${svc_opts[$i]} "[defined by script]" + fi + fi + i=$[$i+1] + done +} + +# maps an option to a function. Existing options are simply overridden. +# usage: option option_name function_name [ defaults ] +function option { + local name=$1 + local fct=$2 + local def=$3 + local opt=0 + + # first, check if this option has already been defined, and return its + # index, or a new one if it's new. + while : ; do + if [ $opt -ge $svc_nbopts ]; then svc_nbopts=$[$opt+1]; break; fi + if [ "x$name" = "x${svc_opts[$opt]}" ]; then break; fi + opt=$[$opt+1] + done + + svc_opts[$opt]=$name + svc_fcts[$opt]=$fct + svc_defs[$opt]=$def + if [ "x$fct" = "xboolean_option" -o "x$fct" = "xstandard_option" -o \ + "x$fct" = "xlong_option" -o "x$fct" = "xmultiple_option" ]; then + svc_vars[$opt]=opt_$name + elif [ "x$fct" = "xreserved_option" ]; then + svc_vars[$opt]=$name + else + svc_vars[$opt]="" + fi + + #eval "function $1 { $2 $1 \$* ; }" +} + +# This function is called once at load time. It scans the config file for all +# referenced options, and assigns them to a quiet function which yells only +# an unknown option has been referenced in a requested section. The options are +# discovered by reading all the first words. +# +# usage: build_default_func config_file +function build_default_func { + local file=$1 + [ -f $file ] || return 1 + # undefine all previously defined functions + for func in $DEFINED_FUNCTIONS ; do unset -f $func ; done + DEFINED_FUNCTIONS=`awk '{gsub("#.*", "", $1); \ + if (match($1, "^[a-zA-Z0-9][a-zA-Z0-9_]*$")) \ + print $1 | "sort -u" }' $file ` + # get all first words and build a default function + for i in $DEFINED_FUNCTIONS ; do + # language exceptions should be here if really needed + # [ "$i" = "no" ] && continue; + # [ "$i" = "service" ] && continue; + # [ "$i" = "section" ] && continue; + # [ "$i" = "interface" ] && continue; + [ "$i" = "replace" ] && continue; + # [ "$i" = "try_svc" ] && continue; + # [ "$i" = "need_svc" ] && continue; + if ! eval "declare -F $i > /dev/null" ; then + eval "function $i { default_config_option $i \$* ; } " + fi + done +} + +# default 'service' function. +# Called as default_service svc_name [svc_instance] from load_config. +# SVC_ARGS is set from the service command line, and is used at next one. +function default_service { + local ret + local opt + local val + # skip first parameter (probably 'service') + #shift + + # we're in listing mode, we do nothing except listing the services + if [ "$MUST_LIST_SECTIONS" = 1 -a $# -ge 1 ]; then + [ "$1" != "${SVC_ARGS[0]}" -o "$2" != "${SVC_ARGS[1]}" ] && echo $* + SVC_ARGS=( $* ) + return + fi + + # check for running selected service + if [ "$RUNNING_SECTION" = 1 ]; then + # first, we'll check wether the next service is *exactly* the same as + # the current one, in which case they are merged, in order to avoid + # duplicate starts (system for example) + if [ "$PNAME" = "$1" -a "${SVC_ARGS[0]}" = "$2" ]; then + return + fi + + # try to insert command-line options + while [ "$FORCE_OPTIONS" ]; do # "opt=val,opt=val..." + opt=${FORCE_OPTIONS%%,*} + val=${opt#*=} + opt=${opt%%=*} + eval $opt $val + if [ "${FORCE_OPTIONS%%*,*}" ]; then # no more ',' + break; + else + FORCE_OPTIONS=${FORCE_OPTIONS#*,} + fi + done + + # unset all options to avoid conflicts with commands (eg: modprobe, ip ...) + for i in ${svc_opts[*]} ; do + unset -f $i + done + + # force a last eval on each reserved option so that they can refer to + # each other. + for i in bin pidfile procname cmdline; do eval eval "$i=\\\"\$$i\\\""; done + + # now if the script defines a fct_end_section() function, let's call + # it to fix some values, or extract som from external config files. + declare -F fct_end_section > /dev/null && fct_end_section $PNAME ${SVC_ARGS[*]} + + if [ "$SVC_AUTO_START" = 0 -o "$autostart" = 1 ]; then + do_$ACTION $PNAME ${SVC_ARGS[*]} + fi + ret=$? + if [ $ret -gt 0 ]; then + STATUS_RET=$ret + fi + if [ "x$G_FACILITY" != x ] ; then + if [ "x$ACTION" = xstart -o "x$ACTION" = xstop \ + -o "x$ACTION" = xrestart ] ; then + if [ $ret -gt 0 ] ; then + logger -p $G_FACILITY.err -t flxi[$$].$PNAME -- \ + "error[$USER]: $PNAME $ACTION ${SVC_INSTANCE[*]} = $ret" + else + logger -p $G_FACILITY.info -t flxi[$$].$PNAME -- \ + "done[$USER]: $PNAME $ACTION ${SVC_INSTANCE[*]}" + fi + fi + fi + unset -v RUNNING_SECTION SVC_ARGS bin cmdline pidfile procname $SVC_VARS + + # reset all options to the default option + for i in ${svc_opts[*]} ; do + eval "function $i { default_config_option $i \$* ; } " + done + fi + + # if service is the one wished, start it at the end + if test "x$1" = "x$PNAME" -a \ + \( "x$2" = "x${SVC_INSTANCE[0]}" -o "x${SVC_INSTANCE[0]}" = "x" \) ; then + # we can test difference between SVC_ARGS and SVC_INSTANCE + SVC_FOUND=1 + RUNNING_SECTION=1 + shift + SVC_ARGS=( $* ) + + # reset every variable + unset -v ${svc_vars[*]} + + # map all options to their functions, and set default vars. + i=0 + while [ $i -lt $svc_nbopts ]; do + eval "function ${svc_opts[$i]} { ${svc_fcts[$i]} ${svc_opts[$i]} \$* ; } " + if [ "${svc_vars[$i]}" ]; then + if [ "x${svc_fcts[$i]}" != "xmultiple_option" ]; then + eval "${svc_vars[$i]}='${svc_defs[$i]}'" + else + eval "${svc_vars[$i]}=( )" + fi + fi + i=$[$i+1] + done + + # now if the script defines a fct_begin_section() function, let's call + # it to preset some default values from external config files. + unset -v $SVC_VARS + declare -F fct_begin_section > /dev/null && fct_begin_section $PNAME ${SVC_ARGS[*]} + fi +} + +# 'no' for 'no ... ', disable a service or an option +function default_no { + local req=$1 + shift + case "$req" in + "service") + default_service + ;; + "section") + default_service + ;; + "interface") + default_service + ;; + *) + if [ "$MUST_LIST_SECTIONS" = 1 ]; then + return + fi + local opt=0 + while : ; do + if [ $opt -ge $svc_nbopts ]; then + # non error since we don't know if this is a valid word. + return + fi + if [ "x$req" = "x${svc_opts[$opt]}" ]; then + if [ "x${svc_fcts[$opt]}" != "xmultiple_option" ]; then + eval "${svc_vars[$opt]}=''" + else + # in case of multiple_option, "no <option> <args>" only + # means that we don't want to add <args> to <option>, + # but not that we want to clear <option> + # eval "${svc_vars[$opt]}=( )" + : + fi + break + fi + opt=$[$opt+1] + done + + # this doesn't work because $req is launched under a subshell ! + #if declare -F $req >/dev/null; then + # eval "$req --disable $*" + #fi + esac +} + +# source configuration file, called last. +function load_config { + # defines functions for all first words in the config file + build_default_func $CONFIG + + # defines functions for reserved keywords: no, service, section, interface. + function no { default_no $*; } + function service { default_service $*; } + function section { default_service $*; } + function interface { + if [ "$PNAME" = "network" ]; then + echo "Warning: use of 'interface $1' keyword is deprecated. Use 'section network $1' instead."; + fi + default_service network $*; + } + + if test ! -d "$CONFIG" -a -e "$CONFIG" ; then + # first keywords out of a section space are for the system, so let's enter + # automatically in system section. + service system + . $CONFIG + service "" + fi + + if [ "$SVC_FOUND" != 1 -a "$MUST_LIST_SECTIONS" != 1 ]; then + echo "Service/instance not found in $CONFIG" + [ "x$G_FACILITY" != x ] && \ + logger -p $G_FACILITY.warn -t "flxi[$$].$PNAME" -- \ + "unknown[$USER]: $PNAME $ACTION ${SVC_INSTANCE[*]}" + exit 1 + fi + return $STATUS_RET +} + +################################## +# ALWAYS LOADED WHEN SOURCED # +################################## +# build default undefined functions + +svc_opts=( ) +svc_vars=( ) +svc_defs=( ) +svc_fcts=( ) +svc_nbopts=0 + +while [ $# -gt 0 ] ; do + case "$1" in + -f|--file) # use this configuration file + export CONFIG=$2 + shift 2 + ;; + --auto) # only start services which don't have a "no autostart" statement + SVC_AUTO_START=1 + shift 1 + ;; + --force) # force start or stop disregarding current status + FORCE_START_STOP=1 + shift 1 + ;; + --list_sections) # list all known sections + MUST_LIST_SECTIONS=1 + load_config + exit 0 + ;; + --filter_option) # display only this option in list_options + OPTION_FILTER=$2 + shift 2 + ;; + -o|--option) # force options : -o "opt=val,opt=val..." + FORCE_OPTIONS=$2 + shift 2 + ;; + -*) + echo "Global options :" + grep $'^[ \t]*-[-a-z0-9_|]*)[ \t]*# ' $PPATH/functions | \ + sed -e $'s/^\\([ \t]*\\)\\([^)]*\\)\\([ \t#)]*\\)\\(.*\\)/ \\2\t\t\\4/' + echo "Other options :" + declare -F usage > /dev/null && usage $* || \ + echo " -h|--help display this help" && \ + [ "x$USAGE" != x ] && echo "$USAGE" + exit 1 + ;; + *) + break + ;; + esac +done + +# Assign the requested action to ACTION (first arg). Default : start +ACTION=${1:-start}; shift + +# Assign the requested instances to SVC_INSTANCE. Default : "" +SVC_INSTANCE=( $* ) + +# most services don't need to redefine the keywords "bin", "cmdline", +# "pidfile", "procname" and "check_interval", so let's initialize them now. +# This also means that any service can use these options without declaring them. +option bin reserved_option +option cmdline reserved_option '$bin' +option pidfile reserved_option +option procname reserved_option +option check_interval reserved_option 0 +option autostart reserved_option 1 + +return 0 + +######### end of script, here comes some documentation ######### + +When a service is started, these operations are performed for each section +containing the same name, and the same instance name if any, or any instance if +no name is set : + + - options variables are initialized to their default values + - if fct_begin_section() exists, it is called with service name and instance name + - options are interpreted + - bin,pidfile,cmdline,procname are converted through an eval so that they can + reference variables options with '$name' or '$opt_name'. + - if fct_end_section() exists, it is called with service name and instance name + - if do_start() exists, it is called with service name and instance name. + Otherwise, the default do_start() function is called with same args. This + function calls fct_pre_start() with same args if it exists, just before + starting $cmdline, and then fct_post_start() just after. + +In case of a stop, everything is the same except do_start() which is replaced +with do_stop(). This last one also calls fct_pre_stop() and fct_post_stop(), +but this last one only if the stop is successful. + +If the service is started as "service --auto start", the option "autostart" is +checked, and if set to 0, the service will not start. This is useful to +differentiate between configured services and enabled services. diff --git a/sbin/init.d/keyboard b/sbin/init.d/keyboard new file mode 100755 index 0000000..a3367b7 --- /dev/null +++ b/sbin/init.d/keyboard @@ -0,0 +1,18 @@ +#!/bin/bash + +. `dirname $0`/functions + +option keymap standard_option us +option keyrate standard_option 30 + +function do_start { + loadkeys $opt_keymap + kbdrate -r $opt_keyrate +} + +function do_stop { + loadkeys us +} + +load_config + diff --git a/sbin/init.d/klogd b/sbin/init.d/klogd new file mode 100755 index 0000000..8138ebd --- /dev/null +++ b/sbin/init.d/klogd @@ -0,0 +1,11 @@ +#!/bin/bash + +. `dirname $0`/functions + +option pidfile reserved_option /var/run/klogd.pid +option bin reserved_option /usr/sbin/klogd +option console_level standard_option 4 +option kernel_symbols standard_option /boot/`uname -r`/System.map +option cmdline reserved_option '$bin ${opt_console_level:+-c $opt_console_level} ${opt_kernel_symbols:+-k $opt_kernel_symbols}' + +load_config diff --git a/sbin/init.d/logrotate b/sbin/init.d/logrotate new file mode 100755 index 0000000..d9a9e3a --- /dev/null +++ b/sbin/init.d/logrotate @@ -0,0 +1,16 @@ +#!/bin/bash + +. `dirname $0`/functions + +option bin reserved_option /usr/sbin/logrotate +option cmdline reserved_option '$bin -s $opt_status' +option statusfile standard_option /var/lib/logrotate.status + +function fct_pre_start { + local t=$( dirname $opt_statusfile ) + if [ ! -d $t ] ; then + mkdir -p -m 755 $t || return 1 + fi +} + +load_config diff --git a/sbin/init.d/monitor b/sbin/init.d/monitor new file mode 100755 index 0000000..59cbb16 --- /dev/null +++ b/sbin/init.d/monitor @@ -0,0 +1,46 @@ +#!/bin/bash + +. `dirname $0`/functions + +option default_check_interval standard_option 300 +option check_interval standard_option 60 +option facility standard_option +option try_restart boolean_option +option html standard_option +option bin reserved_option /opt/exosec/bin/monitor +option cmdline reserved_option \ + '$bin -p $pidfile ${opt_html:+--html $opt_html} ${opt_facility:+--syslog $opt_facility} ${opt_try_restart:+--restart}' +option pidfile reserved_option /var/run/monitor.pid + +function do_check { + local run_stat pid next_stat uptime + + if [ $CONFIG -nt $pidfile ] ; then + status=CONFIG_CHANGED + else + status=OK + fi + + if do_status $1 $2 > /dev/null ; then + run_stat=RUNNING + uptime=$[ $( date +%s ) - $( date -d "$( ps ho lstart $REPLY)" +%s ) ] + + read pid < $pidfile + set -- $( ps ahxo ppid,pid,comm,lstart | \ + awk '{if ($1 == '$pid' && $3 == "sleep") print $0 } ') + if [ $# == 0 ] ; then + status=$status,$opt_check_interval + else + pid=$2 ; shift 3 ; start=$( date -d "$*" +%s) + next_stat=$[ $opt_check_interval - $(date +%s) + $start ] + status=$status,$next_stat + fi + else + uptime=0 + run_stat=STOPPED + fi + + echo "$HOSTNAME $PNAME. $(date +%s) $run_stat $uptime $status" +} + +load_config diff --git a/sbin/init.d/mouse b/sbin/init.d/mouse new file mode 100755 index 0000000..77c9685 --- /dev/null +++ b/sbin/init.d/mouse @@ -0,0 +1,16 @@ +#!/bin/bash + +. `dirname $0`/functions + +option type standard_option ps2 +option device standard_option /dev/mouse +option bin reserved_option /sbin/gpm +option procname reserved_option gpm +option cmdline reserved_option '$bin -t $opt_type -m $opt_device' +option pidfile reserved_option /var/run/gpm.pid + +function fct_pre_stop { + $cmdline -k >/dev/null 2>&1 +} + +load_config diff --git a/sbin/init.d/network b/sbin/init.d/network new file mode 100755 index 0000000..8c2a570 --- /dev/null +++ b/sbin/init.d/network @@ -0,0 +1,407 @@ +#!/bin/bash + +# service network [<ifname>] # interface name -> int_<ifname>=enable +# ip address <ip/mask> [secondary] # address for this interface +# media {auto|full|fdx|100full|100fdx|half|hdx|100half|100hdx> +# slave <if> ... +# modprobe [module [module_options]] +# lladdr <mac_addr> +# mtu <mtu> +# [no] arp +# [no] multicast +# shutdown +# ip route <ip/mask> <gw> + +. `dirname $0`/functions + +option ip option_ip +option media standard_option +option slave multiple_option +option modprobe multiple_option +option lladdr standard_option +option mtu standard_option +option arp boolean_option 1 +option multicast boolean_option 1 +option shutdown boolean_option + +SVC_VARS="addr_list route_list addr_idx route_idx" + +function fct_begin_section { + addr_list=( ) + route_list=( ) + addr_idx=0 + route_idx=0 +} + +# usage: ip <ip> {addr|route} ... +function option_ip { + shift + local cmd=$1 + shift + case "$cmd" in + addr|address) + addr_list[$addr_idx]="$*" + addr_idx=$[$addr_idx+1] + ;; + route) + route_list[$route_idx]="$*" + route_idx=$[$route_idx+1] + ;; + dhcp) + addr_list[$addr_idx]="dhcp" + addr_idx=$[$addr_idx+1] + ;; + --disable) + ;; + *) + echo "Unknown ip command : $cmd $*" + return 1 + esac +} + +function do_start { + local svcname=$1 + local instname=$2 + local arg + + if [ -z "$instname" ]; then + echo "# Starting $svcname ..." + #if [ "$opt_modprobe" != "#" ]; then + # modprobe $opt_modprobe || return 1 + #fi + arg=0 + while [ $arg -lt ${#opt_modprobe[*]} ]; do + if [ "${opt_modprobe[$arg]}" != "#" ]; then + modprobe ${opt_modprobe[$arg]} || return 1 + fi + arg=$[$arg+1] + done + arg=0 + while [ $arg -lt $route_idx ]; do + local dest gw + dest=${route_list[$arg]%%[ ]*} + gw=${route_list[$arg]##*[ ]} + ip route add $dest via $gw + arg=$[$arg+1] + done + echo " ==> start $svcname : Done." + return $? + fi + + if [ "$opt_shutdown" = 1 ]; then + return 0 + fi + + echo "# Starting $svcname${instname:+[$instname]} ..." + # we only check running instances when an interface is defined + do_status $svcname $instname > /dev/null 2>&1 + if [ $? = 0 -a $FORCE_START_STOP -eq 0 ] ; then + echo " ==> Service $svcname${instname:+[$instname]} already running."; + [ $SVC_AUTO_START -eq 0 ] && echo " ==> please use '--force' or 'restart' instead or check with 'status'." + return 0 + fi + + arg=0 + while [ $arg -lt ${#opt_modprobe[*]} ]; do + if [ "${opt_modprobe[$arg]}" != "#" ]; then + if ! modprobe ${opt_modprobe[$arg]}; then + echo " ==> start $svcname${instname:+[$instname]} : modprobe ${opt_modprobe[$arg]} Failed." + return 1 + fi + else + local err # do not merge the assignment here, local sets $? to 0 ! + err=`modprobe $instname 2>&1` + if [ $? -gt 0 ]; then + if ! grep -q "^[ ]*$instname:" /proc/net/dev >/dev/null 2>&1; then + echo " ==> modprobe $instname failed : $err" + return 1 + fi + fi + fi + arg=$[$arg+1] + done + + ip addr flush dev $instname >/dev/null 2>&1 + ip link set $instname down >/dev/null 2>&1 + + if [ "$opt_media" ]; then + case "$opt_media" in + auto) /sbin/mii-diag -r $instname >/dev/null ;; + full|fdx|100full|100fdx) /sbin/mii-diag -F 100baseTx-FD $instname >/dev/null ;; + half|hdx|100half|100hdx) /sbin/mii-diag -F 100baseTx-HD $instname >/dev/null ;; + *) /sbin/mii-diag -F $opt_media $instname >/dev/null ;; + esac + echo " ==> Link set to $opt_media for interface $instname" + fi + + if [ "$opt_lladdr" ]; then + ip link set $instname address $opt_lladdr + fi + + if [ "$opt_mtu" ]; then + ip link set $instname mtu $opt_mtu + fi + + if [ "$opt_multicast" != 1 ]; then + ip link set $instname multicast off + #else + #ip link set $instname multicast on + fi + + if [ "$opt_arp" != 1 ]; then + ip link set $instname arp off + fi + + if ! ip link set $instname up; then + echo " ==> start $svcname${instname:+[$instname]} : Failed." + return 1 + fi + if [ ${#opt_slave[*]} -gt 0 ]; then + for arg in ${opt_slave[*]}; do + if ! $PFULLNAME status $arg >/dev/null 2>&1; then + echo " ==> need to start slave $arg first" + else + ifenslave $instname $arg + fi + done + fi + + arg=0 + while [ $arg -lt $addr_idx ]; do + if [ "${addr_list[$arg]}" = "dhcp" ]; then + echo " ==> Waiting for ip address with DHCP request ... " + dhcpcd -t 10 $instname + else + ip addr add ${addr_list[$arg]} dev $instname + fi + arg=$[$arg+1] + done + + arg=0 + while [ $arg -lt $route_idx ]; do + local dest gw + dest=${route_list[$arg]%%[ ]*} + gw=${route_list[$arg]##*[ ]} + ip route add $dest via $gw dev $instname + arg=$[$arg+1] + done + echo " ==> start $svcname${instname:+[$instname]} : Done." +} + +function do_status { + local instname=$2 + if [ "$instname" ]; then + if ip link show $instname | grep -q UP; then + echo "Interface $instname is up." + return 0 + else + echo "Interface $instname is down." + return 1 + fi + #else + # if ip route list | grep -q dev; then + # echo "Network is up." + # return 0 + # else + # echo "Network is down." + # return 1 + # fi + fi + REPLY= + return 0 +} + + +function do_stop { + local svcname=$1 + local instname=$2 + local arg + + if [ -z "$instname" ]; then + echo "# Stopping $svcname ..." + arg=${#opt_modprobe[*]} + while [ $arg -gt 0 ]; do + arg=$[$arg-1] + if [ "${opt_modprobe[$arg]}" != "#" ]; then + rmmod -r ${opt_modprobe[$arg]} >/dev/null 2>&1 + fi + done + + arg=0 + while [ $arg -lt $route_idx ]; do + ip route del ${route_list[$arg]} >/dev/null 2>&1 + arg=$[$arg+1] + done + return $? + fi + + echo "# Stopping $svcname${instname:+[$instname]} ..." + + if ! do_status $svcname $instname > /dev/null 2>&1; then + echo " ==> stop $svcname${instname:+[$instname]} : already stopped." + return 0 + fi + + # we may have to kill dhcpcd + arg=0 + while [ $arg -lt $addr_idx ]; do + if [ "${addr_list[$arg]}" = "dhcp" ]; then + local proc + for proc in $(svc_pidof dhcpcd) ; do + if grep -qs $instname /proc/$proc/cmdline ; then kill $proc ; fi + done + fi + arg=$[$arg+1] + done + + ip addr flush dev $instname >/dev/null 2>&1 + ip link set $instname down >/dev/null 2>&1 + + arg=${#opt_modprobe[*]} + while [ $arg -gt 0 ]; do + arg=$[$arg-1] + if [ "${opt_modprobe[$arg]}" != "#" ]; then + rmmod -r ${opt_modprobe[$arg]} >/dev/null 2>&1 + else + rmmod -r $instname >/dev/null 2>&1 + fi + done + echo " ==> stop $svcname${instname:+[$instname]} : Done." +} + +#### these are the old versions. The slave mechanism should be checked. + +_start_if() { + local eth=$1 + local temp=`eval echo \\$int_${eth}_modprobe` + ip link show $eth >/dev/null 2>&1 + if [ "$temp" -a $? -ne 0 ] ; then + if [ "$temp" = modprobe ] ; then + modprobe $eth + else + modprobe $temp + fi + fi + + ip link show $eth | grep -q UP + if [ $? = 0 ] ; then + echo "Interface $eth already configured" + continue + fi + + if [ "`eval echo \\$int_${eth}_slave`" ]; then + # the slaves should be up before continuing + for int in `eval echo \\$int_${eth}_slave`; do + start_if $int + done + fi + + if [ "`eval echo \\$int_${eth}_media`" ]; then + media=`eval echo \\$int_${eth}_media` + case "$media" in + auto) /sbin/mii-diag -r $eth >/dev/null ;; + full|fdx|100full|100fdx) /sbin/mii-diag -F 100baseTx-FD $eth >/dev/null ;; + half|hdx|100half|100hdx) /sbin/mii-diag -F 100baseTx-HD $eth >/dev/null ;; + *) /sbin/mii-diag -F $media $eth >/dev/null ;; + esac + echo "Link set to $media for interface $eth" + fi + + ip link set $eth up + ip addr flush dev $eth >/dev/null 2>&1 + if [ "`eval echo \\$ip_dhcp_$eth`" = enable ] ; then + echo "Waiting for ip address with DHCP request ... " + dhcpcd -t 10 $eth + elif [ "`eval echo \\$ip_address_$eth`" ]; then + ip_address=`eval echo \\$ip_address_$eth` + ip_address_sec=`eval echo \\$ip_address_sec_$eth` + echo "Setting ip address $ip_address to interface $eth" + ip addr add $ip_address dev $eth + for addr in $ip_address_sec ; do + echo "Setting secondary ip address $addr to interface $eth" + ip addr add $addr dev $eth + done + fi + + if [ "`eval echo \\$int_${eth}_slave`" ]; then + ifenslave $eth `eval echo \\$int_${eth}_slave` + # we prefer no ip address on the slaves + for int in `eval echo \\$int_${eth}_slave`; do + ip addr flush dev $int + done + fi + + addr=`ip addr show $eth | grep "inet " | sed 's/^.*inet \([^ ]\+\) .*$/\1/'` + if [ ! -z "$addr" ]; then + if [ ! -z "$display_addr_in_issue" ]; then + echo " -> $eth has address $addr" + echo "$eth has address $addr" >> /etc/issue + fi + else + if [ ! -z "$display_addr_in_issue" ]; then + echo " -> $eth has no address" + echo "$eth has no address" >> /etc/issue + fi + fi +} + +_do_start() +{ + # set hostname + if [ "$hostname" ] ; then + echo "Setting hostname '$hostname'" + hostname $hostname + domainname `echo $hostname | cut -f2- -d.` + fi + + # set ip address for each interface + for eth in `set|grep -a '^int_[a-zA-Z0-9:-_]*=enable$'|\ + sed -e 's/.*_\(.*\)=.*/\1/'` ; do + start_if $eth + done + + # set ip route + for route in `echo $ip_route` ; do + way=`echo $route | cut -f1 -d:` + if [ -z "$way" ] ; then way=default ; fi + gateway=`echo $route | cut -f2 -d":"` + echo "Setting route $way via $gateway" + /sbin/ip route add $way via $gateway + done +} + +_do_stop() +{ + for eth in `set|grep -a '^int_[a-zA-Z0-9:-_]*=enable$'|\ + sed -e 's/.*_\(.*\)=.*/\1/'` ; do + echo "Shutting down $eth" + if [ "`eval echo \\$ip_dhcp_$eth`" = enable ] ; then + for proc in `pidof dhcpcd` ; do + if grep -qs $eth /proc/$proc/cmdline ; then kill $proc ; fi + done + fi + ip addr flush dev $eth >/dev/null 2>&1 + ip link set $eth down + if [ ! -z `eval echo \\$int_"$eth"_slave` ]; then + for slave in `eval echo \\$int_"$eth"_slave`; do + ip link set $slave down arp on + ip addr flush dev $slave >/dev/null 2>&1 + done + fi + if [ ! -z "$display_addr_in_issue" ]; then + grep -v "$eth " /etc/issue > /etc/issue- && mv /etc/issue- /etc/issue + fi + done +} + +_do_status() +{ + echo "'ip addr show' give:" + ip addr show + echo "'ip route show' give:" + ip route show +} + +load_config + + diff --git a/sbin/init.d/ntp b/sbin/init.d/ntp new file mode 100755 index 0000000..c654485 --- /dev/null +++ b/sbin/init.d/ntp @@ -0,0 +1,55 @@ +#!/bin/bash + +. `dirname $0`/functions + +option config standard_option /etc/ntp/ntp.conf +option keys standard_option /etc/ntp/ntp.keys +option pidfile reserved_option /var/run/ntp.pid +option hard_sync boolean_option +option force_sync boolean_option +option sync_servers long_option + +option procname reserved_option ntpd +option bin reserved_option /usr/sbin/ntpd +option cmdline reserved_option '$bin -c $opt_config -p $pidfile -k $opt_keys' + +# assign values after all the options have been read +function fct_end_section { + if [ -z "$opt_sync_servers" ]; then + valueof $opt_config server > /dev/null + opt_sync_servers=$REPLY + fi +} + +# perform a forced synchronisation before starting the daemon +function fct_pre_start { + local driftfile + + valueof $opt_config driftfile > /dev/null 2>&1 ; driftfile=$REPLY + if [ ! -e $( dirname $driftfile ) ] ; then + mkdir -p $(dirname $driftfile) + fi + if [ "$opt_force_sync" = "1" -a "$opt_sync_servers" ]; then + ntpdate -u -t 2 $opt_sync_servers + fi + if [ "$opt_hardsync" = "1" ]; then + /sbin/hwclock -w --noadjfile --localtime + fi +} + +# perform a forced synchronisation before stopping the daemon +function fct_pre_stop { + if [ "$opt_hardsync" = "1" ]; then + /sbin/hwclock -w --noadjfile --localtime + fi +} + +# execute a forced resynchronisation to sync servers +function do_update { + if [ "$opt_sync_servers" ]; then + ntpdate -t 2 -u $opt_sync_servers + /sbin/hwclock -w --noadjfile --localtime + fi +} + +load_config diff --git a/sbin/init.d/pdnsd b/sbin/init.d/pdnsd new file mode 100755 index 0000000..9adeb55 --- /dev/null +++ b/sbin/init.d/pdnsd @@ -0,0 +1,16 @@ +#!/bin/bash + +. `dirname $0`/functions + +option config standard_option /etc/pdnsd.conf +option pidfile reserved_option /var/run/syslog-ng.pid + +option bin reserved_option /usr/sbin/pdnsd +option cmdline reserved_option '$bin -c $opt_config -d -p $pidfile' + +# perform a forced synchronisation before starting the daemon +function fct_pre_start { + if [ ! -d /var/cache/pdnsd ] ; then mkdir -p /var/cache/pdnsd ; fi +} + +load_config diff --git a/sbin/init.d/sshd b/sbin/init.d/sshd new file mode 100755 index 0000000..a4c636f --- /dev/null +++ b/sbin/init.d/sshd @@ -0,0 +1,20 @@ +#!/bin/bash + +. `dirname $0`/functions + +STOP_FIRST_WITH=KILL + +option bin reserved_option /usr/sbin/sshd +option cmdline reserved_option '$bin -p $opt_port -f $opt_config -h $opt_hostkey' +option port standard_option 22 +option config standard_option /etc/ssh/sshd_config +option hostkey standard_option /etc/ssh/ssh_host_key + +# assign default values to options and variables before parsing the cfg file +function fct_end_section { + valueof $opt_config HostKey > /dev/null ; opt_hostkey=${REPLY:-$opt_hostkey} + valueof $opt_config PidFile > /dev/null ; pidfile=${REPLY:-$pidfile} +} + +load_config + diff --git a/sbin/init.d/stat b/sbin/init.d/stat new file mode 100755 index 0000000..cdbfca9 --- /dev/null +++ b/sbin/init.d/stat @@ -0,0 +1,100 @@ +#!/bin/bash + +. `dirname $0`/functions + +option output standard_option +option runas standard_option stat +option opt long_option +option freq standard_option +option method standard_option +option statusfile standard_option +option check_interval reserved_option 60 +option bin reserved_option /opt/exosec/bin/statistics + +function fct_begin_section { + # assign the default instance name from the config file argument + pidfile=/var/run/stat/$2.pid + procname=statistics + opt_statusfile=/var/run/stat/$2.nfo + opt_output=/var/run/stat/$2.log +} + +function do_start { + local p=$1 ; shift + local testname=$1 + local message + + opt_method=${opt_method:-$testname} + if [ "$FORCE_START_STOP" -eq 0 ] && do_status $p $testname > /dev/null ; then + echo "Already started, stop it before restarting" + return 1 + fi + + message="# Starting Monitoring on $testname for $testname statistics ..." + echo "$message" + + { local path + for path in `dirname $pidfile` `dirname $opt_statusfile` `dirname $opt_output`; do + mkdir -p $path 2> /dev/null && \ + { [ -z "$opt_runas" ] || chown $opt_runas $path && chmod 700 $path ; } \ + || { echo "Bad owner or rights on directory $path ($opt_runas:700), fix it." + return 1 ; } + done ; + } + + # note: here, cmdline doesn't include $bin. + cmdline="-t $opt_method -o $opt_output -s $opt_statusfile -p $pidfile + -w $opt_freq -n $testname $opt_opt" + + if [ -z "$opt_runas" ] ; then + ( $bin $cmdline ) + else + ( su - $opt_runas $cmdline ) + fi + + if [ "$?" = 0 ] ; then + echo "$message done." + else + echo "$message error." + fi +} + +function do_check { + local run_stat date status service result next_stat + local service=$1 instance=$2 + + if do_status $service $instance > /dev/null ; then + run_stat=RUNNING + uptime=$[ $( date +%s ) - $( date -d "$( ps ho lstart $REPLY)" +%s ) ] + else + run_stat=STOPPED + uptime=0 + fi + read idsvc date status result < $opt_statusfile > /dev/null 2>&1 + if [ $? != 0 ] ; then + echo "$HOSTNAME $2 $(date +%s) FATAL" ; return 1 + fi + + diff=$[ $(date +%s) - $date ] + [ $[ $diff > 2 * $opt_freq ] = 1 -a $status = OK ] && + status="ALERT" + [ $[ $diff > $opt_freq ] = 1 -a $status = OK ] && + status="WARNING" + + if [ $run_stat = RUNNING ] ; then + read pid < $pidfile + set -- $( ps ahxo ppid,pid,comm,lstart | \ + awk '{if ($1 == '$pid' && $3 == "sleep") print $0 } ') + if [ $# == 0 ] ; then + status=$status,$opt_freq + else + pid=$2 ; shift 3 ; start=$( date -d "$*" +%s) + next_stat=$[ $opt_freq - $(date +%s) + $start ] + status=$status,$next_stat + fi + fi + + echo "$HOSTNAME $service.$instance $date $run_stat $uptime $status $result" +} + +load_config diff --git a/sbin/init.d/syslog-ng b/sbin/init.d/syslog-ng new file mode 100755 index 0000000..d1824b9 --- /dev/null +++ b/sbin/init.d/syslog-ng @@ -0,0 +1,28 @@ +#!/bin/bash + +. `dirname $0`/functions + +option config standard_option /etc/syslog-ng/syslog-ng.conf +option pidfile reserved_option /var/run/syslog-ng.pid + +option bin reserved_option /sbin/syslog-ng +option cmdline reserved_option '$bin -f $opt_config -p $pidfile' + +# perform a forced synchronisation before starting the daemon +function fct_post_start { + /sbin/init.d/klogd start >/dev/null 2>&1 || echo "Error starting klogd." +} + +# perform a forced synchronisation before stopping the daemon +function fct_pre_stop { + /sbin/init.d/klogd stop >/dev/null 2>&1 || echo "Error stopping klogd." +} + +function do_update { + if [ -e $pidfile ] ; then + read < $pidfile + [ "$pidfile" ] && kill -HUP $REPLY > /dev/null 2>&1 + fi +} + +load_config diff --git a/sbin/init.d/sysprofiles b/sbin/init.d/sysprofiles new file mode 100755 index 0000000..279215a --- /dev/null +++ b/sbin/init.d/sysprofiles @@ -0,0 +1,3 @@ +#!/bin/bash +cfgfile=$1 +. /sbin/init.d/functions -f $cfgfile --list_sections|(last=;while read svc rest; do if [ "$svc" != "$last" ]; then /sbin/init.d/$svc -f $cfgfile --auto start; fi; last=$svc; done) diff --git a/sbin/init.d/system b/sbin/init.d/system new file mode 100755 index 0000000..11ebdde --- /dev/null +++ b/sbin/init.d/system @@ -0,0 +1,76 @@ +#!/bin/bash + +. `dirname $0`/functions + +option hostname standard_option +option modprobe multiple_option +option sysctl multiple_option +option file_max standard_option + +function do_start { + local svcname=$1 + local instname=$2 + local arg + + arg=0 + while [ $arg -lt ${#opt_modprobe[*]} ]; do + modprobe ${opt_modprobe[$arg]} || return 1 + arg=$[$arg+1] + done + + if [ "$opt_file_max" ]; then + echo $opt_file_max > /proc/sys/fs/file-max + fi + + if [ "$opt_hostname" ] ; then + echo "Setting hostname '$opt_hostname'" + hostname $opt_hostname + domainname `echo $opt_hostname | cut -f2- -d.` + fi + + for arg in ${opt_sysctl[*]}; do + local sysctl value + sysctl=${arg%%=*} + sysctl=${sysctl//.//} + value=${arg##*=} + if [ -e "/proc/sys/$sysctl" ]; then + echo $value > /proc/sys/$sysctl + else + echo "Non-existent sysctl entry : $arg" + fi + done + return 0 +} + +function do_status { + local instname=$2 + echo "System status :" + echo -n "Hostname : "; hostname + echo "Modules list :"; lsmod + return 0 +} + + +function do_stop { + local svcname=$1 + local instname=$2 + + arg=${#opt_modprobe[*]} + while [ $arg -gt 0 ]; do + arg=$[$arg-1] + rmmod -r ${opt_modprobe[$arg]} >/dev/null 2>&1 + done + + return 0 +} + +function do_check { + local svcname=$1 + local instname=$2 + + read uptime idletime < /proc/uptime + echo "$HOSTNAME $svcname.$instname $(date +%s) RUNNING ${uptime%%.*} OK" +} + +load_config + diff --git a/sbin/init.d/thttpd b/sbin/init.d/thttpd new file mode 100755 index 0000000..091648b --- /dev/null +++ b/sbin/init.d/thttpd @@ -0,0 +1,27 @@ +#!/bin/bash + +. `dirname $0`/functions + +option config standard_option +option port standard_option 80 +option docroot standard_option /var/www +option chroot boolean_option 1 +option symlink boolean_option 1 +option user standard_option +option address standard_option +option logfile standard_option +option charset standard_option iso-8859-1 +option bin reserved_option /usr/sbin/thttpd + +# assign default values to options and variables before parsing the cfg file +function fct_begin_section { + pidfile="/var/run/thttpd-$2.pid" + cmdline='$bin ${opt_config:+-C $opt_config} ${opt_port:+-p $opt_port} + ${opt_docroot:+-d $opt_docroot} ${opt_chroot:+-r} ${opt_symlink:+-s} + ${opt_user:+-u $opt_user} ${opt_address:+-h $opt_address} + ${opt_logfile:+-l $opt_logfile} ${opt_charset:+-T $opt_charset} + ${pidfile:+-i $pidfile}' +} + +load_config + diff --git a/sbin/initscript b/sbin/initscript new file mode 100755 index 0000000..678ae46 --- /dev/null +++ b/sbin/initscript @@ -0,0 +1,10 @@ +#!/bin/sh + +umask 022 +PATH=/bin:/sbin:/usr/sbin:/usr/bin +export PATH + +BOOTID=`cat /proc/sys/kernel/random/boot_id` +export BOOTID + +eval exec "$4" diff --git a/sbin/rc.0 b/sbin/rc.0 new file mode 100755 index 0000000..fb546de --- /dev/null +++ b/sbin/rc.0 @@ -0,0 +1,83 @@ +#! /bin/sh +# +# rc.6 This file is executed by init when it goes into runlevel +# 0 (halt) or runlevel 6 (reboot). It kills all processes, +# unmounts file systems and then either halts or reboots. +# +# Version: @(#)/etc/rc.d/rc.6 1.50 1994-01-15 +# +# Author: Miquel van Smoorenburg <miquels@drinkel.nl.mugnet.org> +# Modified by: Patrick J. Volkerding, <volkerdi@ftp.cdrom.com> +# + +# Set the path. +PATH=/sbin:/etc:/bin:/usr/bin:/usr/sbin + +# If there are SystemV init scripts for this runlevel, run them. +if [ -x /sbin/init.d/sysvinit ]; then + /sbin/init.d/sysvinit start +fi + +# Set linefeed mode to avoid staircase effect. +stty onlcr + +echo "Running shutdown script $0:" + +# Find out how we were called. +case "$0" in + *0) + command="halt" + ;; + *6) + command=reboot + ;; + *) + echo "$0: call me as \"rc.0\" or \"rc.6\" please!" + exit 1 + ;; +esac + +# Kill all processes. +# INIT is supposed to handle this entirely now, but this didn't always +# work correctly without this second pass at killing off the processes. +# Since INIT already notified the user that processes were being killed, +# we'll avoid echoing this info this time around. +if [ "$1" != "fast" ]; then # shutdown did not already kill all processes + killall5 -15 + sleep 5 + killall5 -9 +fi + +# Before unmounting file systems write a reboot or halt record to wtmp. +$command -w + +# Syncing data +sync + +# Unmount any remote filesystems: +echo "Unmounting remote filesystems." +umount -na -tnfs + +# Turn off swap, then unmount local file systems. +echo "Turning off swap." +swapoff -a +echo "Unmounting local file systems." +# Don't remount UMSDOS root volumes: +if [ ! "`cat /proc/mounts | head -1 | cut -d ' ' -f 5`" = "umsdos" ]; then + umount -na -t nonfs -t noproc + echo "Remounting root filesystem read-only." + mount -n -o remount,ro / +else + umount -na -t nonfs -t noumsdos -t noproc +fi +# This never hurts: +sync + +# Now halt (poweroff with APM kernels) or reboot. +if [ "$command" = "reboot" ]; then + echo "Rebooting." + reboot -f +else + halt -f -p +fi + diff --git a/sbin/rc.6 b/sbin/rc.6 new file mode 120000 index 0000000..120189f --- /dev/null +++ b/sbin/rc.6 @@ -0,0 +1 @@ +rc.0
\ No newline at end of file diff --git a/sbin/rc.K b/sbin/rc.K new file mode 100755 index 0000000..5150594 --- /dev/null +++ b/sbin/rc.K @@ -0,0 +1,41 @@ +#! /bin/sh +# +# rc.K This file is executed by init when it goes into runlevel +# 1, which is the administrative state. It kills all +# deamons and then puts the system into single user mode. +# Note that the file systems are kept mounted. +# +# Version: @(#)/etc/rc.d/rc.K 1.50 1994-01-18 +# Version: @(#)/etc/rc.d/rc.K 1.60 1995-10-02 (PV) +# +# Author: Miquel van Smoorenburg <miquels@drinkel.nl.mugnet.org> +# Modified by: Patrick J. Volkerding <volkerdi@ftp.cdrom.com> +# Modified by: Benoit Dolez <bdolez@meta-x.org> +# + +function loop { + echo + for i in 0 1 2 3 4 5 ; do echo -n . ; done + echo +} + +# Set the path. +PATH=/sbin:/etc:/bin:/usr/bin + +# If there are SystemV init scripts for this runlevel, run them. +if [ -x /sbin/init.d/sysvinit ]; then + /sbin/init.d/sysvinit start +fi + +# Kill all processes. +killall5 -1 +loop +killall5 -15 +loop +killall5 -9 +loop + +# Now go to the single user level +echo "Going to single user mode..." +telinit -t 1 1 + diff --git a/sbin/rc.M b/sbin/rc.M new file mode 100755 index 0000000..df6ef16 --- /dev/null +++ b/sbin/rc.M @@ -0,0 +1,68 @@ +#!/bin/sh + +if [ ! -x /bin/lcdwrite ] ; then alias lcdwrite=/bin/true ; fi +if [ ! -x /bin/lcdtee ] ; then alias lcdtee=/bin/cat ; fi + +LOG=/var/log/bootlog + +function start { + for service in $* ; do + echo -n "Starting $service ... " + echo -n "$service ... " | lcdwrite + echo "----- Starting $service with /sbin/init.d/$service -----" >> $LOG + if [ -x /sbin/init.d/$service ] ; then + /sbin/init.d/$service start >> $LOG 2>&1 + if [ $? -eq 0 ] ; then + echo "done" | lcdtee + echo "----- Done -----" >> $LOG + else + echo "failed" | lcdtee + echo "----- Failed -----" >> $LOG + fi + else + echo "failed" | lcdtee + echo "----- Failed -----" >> $LOG + fi + done +} + + +# Reinit /var/log/bootlog file +/bin/rm -rf /var/log/bootlog + +# Running multiuser part +echo "Starting Multi-user (`date`)" | tee -a $LOG + +# Enable loopback +ip link set dev lo up +ip addr add 127.0.0.1/8 dev lo + +# Starting 'crond' if exist +if [ -x /usr/sbin/crond ] ; then + if [ ! -d /var/spool/cron/crontabs ] ; then mkdir -p /var/spool/cron/crontabs ; fi + crond +fi + +# Starting 'atd' if exist +if [ -x /usr/sbin/atd ] ; then + atd +fi + +# Sourcing base configuration +if [ -x /etc/startup.rc ] ; then + /etc/startup.rc | tee -a $LOG +elif [ -d /etc/startup.rc ] ; then + for i in /etc/startup.rc/S* ; do + $i + done +else + echo "No /etc/startup.rc file" | lcdwrite | tee -a $LOG + echo "No configuration file (/etc/startup.rc)" | tee -a $LOG +fi + +# Starting SystemV like daemon +if [ -d /etc/rc$RUNLEVEL.d -a -x /sbin/init.d/sysvinit ] ; then + /sbin/init.d/sysvinit start | tee -a $LOG +fi + +# OK diff --git a/sbin/rc.S b/sbin/rc.S new file mode 100755 index 0000000..b85c86b --- /dev/null +++ b/sbin/rc.S @@ -0,0 +1,126 @@ +#!/bin/sh +# +# /etc/rc.d/rc.S: System initialization script. +# +# Mostly written by: Patrick J. Volkerding, <volkerdi@ftp.cdrom.com> +# + + +umask 022 +export PATH=/sbin:/bin:/usr/sbin:/usr/bin + +# enable swapping +/sbin/swapon -a + +# initialize LCD +if [ ! -x /bin/lcdwrite ] ; then alias lcdwrite=/bin/true ; fi +if [ ! -x /bin/lcdtee ] ; then alias lcdtee=/bin/cat ; fi +echo | lcdwrite + +if [ ! -e /proc/mounts ] ; then + # mounting /proc device + mount -vnt proc /proc /proc +fi + +# be careful, we suppose that /dev was created by preinit program +# to be read-write + +if [ ! -d /dev/pts -a -w /dev/ ] ; then + # create /dev/pts + mkdir /dev/pts +fi + +# Création du /dev/root s'il n'existe pas +if [ ! -e /dev/root ] ; then + if grep -q " root=" /proc/cmdline ; then + set `sed -e "s/^.* root=\([^ ]\+\).*/\1/" < /proc/cmdline` + ln -s $1 /dev/root + fi +fi + +# Check the integrity of / filesystem except if it's a ramdisk +# major=`ls -l /dev/root|sed -e 's/^\(.*\)\([0-9]\+\)\(, .*\)$/\2/'` +# if [ "$major" != "1" ]; then +# /sbin/e2fsck -n /dev/root +# fi + +# Création du /dev/boot s'il n'existe pas +if [ ! -e /dev/boot ] ; then + if grep -q " boot=" /proc/cmdline ; then + set `sed -e "s/^.* boot=\([^ ]\+\).*/\1/" < /proc/cmdline` + ln -s $1 /dev/boot + elif grep -q '[ ]/boot[ ]' /etc/fstab ; then + set `grep '[ ]/boot[ ]' /etc/fstab` + ln -s $1 /dev/boot + fi +fi + +# Check the integrity of all filesystems +/sbin/fsck -a -A -C -R + +if [ $? -gt 1 ] ; then + echo "Error with fsck, run 'fsck -y -a'" + PS1="(Repair filesystem) \#"; export PS1 + sulogin + echo "Unmounting file systems..." + umount -a + mount -n -o remount,ro / + sync + echo "Rebooting system..." + sleep 2 + reboot + /bin/sh +fi + +# mount file systems in fstab (and create an entry for /) +# but not NFS because TCP/IP is not yet configured +mount -nat nonfs,noproc + +if [ ! -w /var ] ; then + echo "Mounting /var as tmpfs" + umount /var >/dev/null 2>&1 + mount -o mode=755 -t tmpfs /var /var +fi + +# Creat /var directories if they don't exist +if [ ! -d /var/tmp ] ; then mkdir -m 1777 /var/tmp ; fi +if [ ! -d /var/run ] ; then mkdir /var/run ; fi +if [ ! -d /var/lib ] ; then mkdir /var/lib ; fi +if [ ! -d /var/spool ] ; then mkdir /var/spool ; fi +if [ ! -d /var/log ] ; then mkdir /var/log ; fi +if [ ! -d /var/cache ] ; then mkdir /var/cache ; fi +if [ ! -d /var/empty ] ; then mkdir /var/empty ; fi +if [ ! -d /var/adm/. ] ; then ln -s log /var/adm ; fi + +sync + +if [ ! -w /tmp ] ; then + echo "Mounting /tmp as tmpfs" + umount /tmp >/dev/null 2>&1 + mount -o mode=1777 -t tmpfs /tmp /tmp +fi + +/bin/rm -rf /tmp/* /tmp/.[^.]* /tmp/..?* +touch /var/log/wtmp /var/log/lastlog + +if mkdir /tmp/.$BOOTID ; then + dmesg > /tmp/.$BOOTID/dmesg +fi + +# Clean up temporary files on the /var volume: +/bin/rm -f /var/run/utmp /var/run/*.pid + +# Looks like we have to create this. +cat /dev/null > /var/run/utmp + +# Writing Status +for dir in / /dev /tmp /var /etc /boot ; do + s="" + if [ -L $dir ] ; then s=$s"a symbolic-link " ; t=L ; fi + if [ -w $dir ] ; then s=$s"read-write "; t=RW ; else + s=$s"read-only " ; t=RO ; fi + echo "$dir is $s" +done + +echo "Base system done." | lcdtee + |