#! /bin/sh
# $Copyright$
# Copyright (C) Fujitsu Siemens Computers GmbH 2001, 2002, 2003, 2004, 2005, 2006, 2007
# All rights reserved
#
# ident "$Header$"
#
# Load the ServerView Linux eecd modules
### BEGIN INIT INFO
# Provides: eecd_mods
# Required-Start: $local_fs
# Required-Stop:
# Default-Start: 2 3 5
# Default-Stop: 0 1 6
# Description: Inserts and removes the eecd modules.
# The modules will be first compiled if necessary.
# A binary module package for machines without a
# development system is also built.
### END INIT INFO
# $Copyright$
# Copyright (C) Fujitsu Siemens Computers GmbH 2007, 2008
# All rights reserved
#
# Exit status codes (see LSB 3 spec, ch. 20) are :
# 0 OK
# 1 generic or unspecified error
# 2 invalid or excess argument(s)
# 3 unimplemented feature (e.g. "reload")
# 4 user had insufficient privileges
# 5 program is not installed
# 6 program is not configured
# 7 program is not running
# 8+ reserved (see LSB Core Spec 3.1, ch. 20)
# Set up a decent path.
PATH="/sbin:/usr/sbin:/bin:/usr/bin:/usr/src/linux:"
export PATH
# Use LSB function library for convenience.
[ -f /lib/lsb/init-functions ] && . /lib/lsb/init-functions
# Source ServerView configuration file and function library
. /etc/srvmagt/config
. /etc/srvmagt/functions
machType=$(isVM) && exit 0 # No action if we run in a virtual machine
SetSvEnv
# SV_MODULES is the complete set of eecd modules to build/load, certain PRIMERGYs
# require only a subset.
# Add our IPMI module to the set, if the native IPMI module is not configured for use.
# Add our COPA module only if a Copernicus-A (onboard or RSB) is around
SV_MODULES="smbus"
isCOPAsystem && SV_MODULES="copa $SV_MODULES"
[ ${LoadNativeIPMIDriver:=1} -eq 0 ] && SV_MODULES="${SV_MODULES} ipmi"
THIS_RELEASE=$(uname -r) # e.g. "2.6.5-7.97-default"
MOD_SUFFIX="o"
[[ ${THIS_RELEASE%%-*} > "2.6" ]] && MOD_SUFFIX="ko"
MOD_HOME=/lib/modules/$THIS_RELEASE/srvmagt
RPM_HOME=/etc/srvmagt/rpms
#
umask 0066
logger -t $MYNAME "$*: $(uname -a)"
mode="$1"
case "$mode" in
start|trace)
# On RHEL5, remove the edac kernel modules if exists
[ -d "/etc/modprobe.d/" ] && {
edac_disable
rc=$?
case $rc in
0) mylog_success_msg "Starting ServerView modules: Disable EDAC";;
1) mylog_failure_msg "Starting ServerView modules: Disable EDAC";;
esac
}
# 1. See if OpenIPMI or ServerView IPMI module needs to be loaded
if [ $LoadNativeIPMIDriver -eq 0 ]; then
# The ServerView IPMI module can be used only if the OpenIPMI is not loaded
if [ -x "/etc/init.d/ipmi" ]; then
/etc/init.d/ipmi status >/dev/null 2>&1 && {
mylog_failure_msg "Starting ServerView modules: Stop OpenIPMI first!"
exit 1
}
else
res=$(lsmod | grep "ipmi_") && {
mylog_failure_msg "Starting ServerView modules: Stop OpenIPMI first!"
exit 1
}
fi
[ -c "/dev/ipmi0" ] && {
rm -f /dev/ipmi0
logger -t $MYNAME "OpenIPMI device /dev/ipmi0 removed"
}
else
# Try to load the OpenIPMI module as requested. for RHEL5 SLES10 and VMWare ESX 3.5
if [ "$SV_NICKNAME" = "RHEL5" -o "$SV_NICKNAME" = "SLES10" -o "$SV_VMREL" = "3.5" ]; then
# Make sure that ServerView IPMI is unloaded.
if [ -x "/etc/init.d/ipmi" ]; then
res=$(lsmod | grep "ipmi ") && {
mylog_failure_msg "Starting ServerView modules: Stop us first!"
exit 1
}
logger -t $MYNAME "Starting OpenIPMI modules"
/etc/init.d/ipmi status >/dev/null 2>&1 || /etc/init.d/ipmi start >/dev/null 2>&1
if /etc/init.d/ipmi status >/dev/null 2>&1; then
logger -t $MYNAME "OpenIPMI modules successful loaded"
else
logger -t $MYNAME "load OpenIPMI modules failed (ipmi start script rc=$?)"
fi
else
mylog_failure_msg "Starting OpenIPMI modules: no init script"
exit 1
fi
else
# Load the ServerView IPMI module only if the OpenIPMI is not loaded
if [ -x "/etc/init.d/ipmi" ]; then
/etc/init.d/ipmi status >/dev/null 2>&1 && {
mylog_failure_msg "Starting ServerView modules: Stop OpenIPMI first!"
exit 1
}
else
res=$(lsmod | grep "ipmi_") && {
mylog_failure_msg "Starting ServerView modules: Stop OpenIPMI first!"
exit 1
}
fi
logger -p daemon.notice -t $MYNAME "Starting ServerView modules: on $SV_NICKNAME $SV_VMREL allways use ServerView IPMI module"
SV_MODULES="${SV_MODULES} ipmi"
fi
fi
# 2. See if ALL modules suitable for the running kernel exist. Otherwise (re)compile.
# Note: The release of the RUNNING kernel is within the searched folder name!
compileModules=1
[ -d $MOD_HOME ] && {
logger -t $MYNAME "$mode found ServerView modules in $MOD_HOME"
compileModules=0
for module in $SV_MODULES; do
[ -f $MOD_HOME/$module.$MOD_SUFFIX ] || let compileModules++
done
}
[ $compileModules -eq 0 ] || $0 makemods || {
mylog_failure_msg "Starting ServerView modules: cannot compile modules"
exit 1
}
# 3. Try to (re)load each ServerView module unless the eecd daemon runs.
[ -x /usr/sbin/eecd ] && pid=$(mypidof "/usr/sbin/eecd") && {
mylog_failure_msg "Starting ServerView modules: Stop service eecd first!"
exit 1
}
errors=0
for module in $SV_MODULES; do
res=$(lsmod | grep "$module ") && {
mylog_success_msg "Starting ServerView module $module: already loaded"
continue
}
rm -f /dev/pci/$module
[ -f $MOD_HOME/$module.$MOD_SUFFIX ] && {
flags=
[ "$mode" = trace ] && flags="${module}Debug=3"
logger -t $MYNAME "$mode inserts module $module $flags"
insmod $MOD_HOME/$module.$MOD_SUFFIX $flags >/tmp/eecd_mods.log 2>&1
insrc=$?
logger -t $MYNAME -f /tmp/eecd_mods.log
[ $insrc -eq 0 ] && {
# Creating the module's special file succeeds only if the module
# was correctly loaded.
major=$(grep $module /proc/devices) && {
major=${major%% *}
[ -e /dev/pci ] || mkdir /dev/pci && chmod 755 /dev/pci && chown root /dev/pci && chgrp root /dev/pci
mknod -m 644 /dev/pci/$module c $major 0 2>&1 | logger -t $MYNAME
}
[ -c /dev/pci/$module ] && {
logger -t $MYNAME "$mode made node $(ls -l /dev/pci/$module)"
mylog_success_msg "Starting ServerView module $module $flags"
continue
}
}
# The module will not load. Missing HW is not an error, other causes are.
# Since distinction is impossible, just log this event to /var/log/messages.
logger -t $MYNAME "Starting ServerView module $module: cannot load (missing HW?)"
continue
}
mylog_failure_msg "Starting ServerView module $module: does not exist"
let errors++
done
[ $errors -eq 0 ] && exit 0
exit 1 ;;
stop)
# Unload all ServerView modules, but NEVER unload OpenIPMI (we do not know,
# if we loaded it ourselves).
errors=0
loaded=0
for module in copa smbus ipmi; do
res=$(lsmod | grep "$module ") || {
mylog_success_msg "Stopping ServerView module $module (not loaded)"
continue
}
let loaded++
# Since the module is loaded, failure to unload indicates it is in use.
rmmod $module 2>/dev/null >/dev/null
if [ $? -eq 0 ]; then
mylog_success_msg "Stopping ServerView module $module"
else
mylog_failure_msg "Stopping ServerView module $module (still in use)"
let errors++
fi
rm -f /dev/pci/$module
done
[ -d /dev/pci ] && rmdir /dev/pci
# On RHEL5, load edac kernel modules again if they were loded
[ -d "/etc/modprobe.d/" ] && {
edac_enable
rc=$?
case $rc in
0) mylog_success_msg "Stopping ServerView modules: Reenable EDAC";;
1) mylog_failure_msg "Stopping ServerView modules: Reenable EDAC";;
esac
}
[ $loaded -eq 0 ] && exit 0
[ $errors -eq 0 ] && exit 0
exit 1;;
force-reload)
# Reload configuration, if the service supports this,
# otherwise start the service if it is not running
$0 start
exit $? ;;
restart)
$0 stop $*
$0 start $*
exit $? ;;
status)
# Status codes in this case are:
# 0 all agents are running [OK]
# 1 service is dead /var/run/<pid file> exists
# 2 service is dead and /var/lock/<lock file> ecists
# 3 one or more agents are not running
# 4 service status is unknown
# 5+ reserved (see LSB Core Spec 3.1, ch. 20)
echo "ServerView modules packages:"
rpm -q \
--queryformat '\t%{NAME}-%{VERSION}-%{RELEASE} installed %{INSTALLTIME:date}\n' \
srvmagt-mods_src
rpm -qp \
--queryformat '\t%{NAME}-%{VERSION}-%{RELEASE} built %{BUILDTIME:date}\n' \
$RPM_HOME/srvmagt-mods_bin*.rpm || echo "srvmagt-mods_bin not (yet) built"
# Show eecd modules status. Note that native OpenIPMI will not show up here.
lsmod | head -1
res=$(lsmod | grep "ipmi ") && log_success_msg "$res"
res=$(lsmod | grep "smbus ")
if [ -n "$res" ]; then
log_success_msg "$res"
exit 0
else
log_success_msg "smbus is not loaded"
exit 3
fi
;;
makemods)
# Only in the package's "src" incarnation
# Compile ServerView modules for the RUNNING kernel
# Make sure suitable kernel source is installed for module compilation
[ $MYNAME = "eecd_mods_bin" ] && exit 1
kdir=$(checkKernelSource $SV_NICKNAME $SV_ARCH)
case $? in
0)
;;
1)
mylog_failure_msg "Compiling found no $SV_NICKNAME kernel $THIS_RELEASE source"
logger -t $MYNAME "$mode found no $SV_NICKNAME kernel $THIS_RELEASE source [$kdir]"
exit 1 ;;
2)
mylog_failure_msg "kernel source $SV_PKG_ARCH and processor architecture $SV_ARCH mismatch"
exit 1 ;;
esac
logger -t $MYNAME "$mode compiles with $SV_NICKNAME kernel $THIS_RELEASE source: $kdir"
echo "Compiling ServerView modules for $SV_NICKNAME kernel $THIS_RELEASE"
logger -t $MYNAME "Compiling ServerView modules for $SV_NICKNAME kernel $THIS_RELEASE"
make -s -C /etc/srvmagt/sources all ONLY_SHOW_MODS=yes >/tmp/eecd_mods.log 2>&1
makerc=$?
logger -t $MYNAME -f /tmp/eecd_mods.log
if [ $makerc -eq 0 ]; then
mylog_success_msg "Compiling ServerView modules"
logger -t $MYNAME "$mode succeeded"
exit 0
else
mylog_failure_msg "Compiling ServerView modules"
echo "See /var/log/messages for details!"
logger -t $MYNAME "$mode failed"
exit 1
fi ;;
makepackage)
# Only in the package's "src" incarnation
# Build the binaries package srvmagt-mods_bin
[ $MYNAME = "eecd_mods_bin" ] && exit 1
echo -n "Building ServerView modules RPM package srvmagt-mods_bin"
pkg=$(/etc/srvmagt/sources/srvmagt_buildpackage)
if [ $? -eq 0 ]; then
mylog_success_msg ""
echo -e "The RPM package $pkg is in $RPM_HOME.\n"
rpm -qip "$RPM_HOME/$pkg"
exit 0
else
mylog_failure_msg ""
echo "See /var/log/messages for details!"
exit 1
fi ;;
showlog)
# Display my log file
grep $MYNAME /var/log/messages | more
exit 0 ;;
try-restart|reload|*)
echo "Usage: $0 {start|stop|trace|status|makemods|makepackage|showlog}"
exit 1 ;;
esac
exit 1
# EOF