0b1545
#!/bin/sh
0b1545
#
0b1545
# Copyright 2009 Red Hat, Inc.
0b1545
# License: GPLv2
0b1545
# Author: Dan Horák <dhorak@redhat.com>
0b1545
#
0b1545
# cpi Set Control Program Identification on IBM zSeries
0b1545
#
0b1545
# chkconfig:   12345 80 20
0b1545
# description: Set Control Program Identification on IBM zSeries \
0b1545
#              that's reported on a Linux LPAR
0b1545
0b1545
### BEGIN INIT INFO
0b1545
# Provides: cpi
0b1545
# Required-Start: 
0b1545
# Required-Stop: 
0b1545
# Should-Start: 
0b1545
# Should-Stop: 
0b1545
# Default-Start: 1 2 3 4 5 
0b1545
# Default-Stop: 0 6
0b1545
# Short-Description: Set control program identification on IBM zSeries
0b1545
# Description: Set Control Program Identification on IBM zSeries \
0b1545
#              that's reported on a Linux LPAR
0b1545
### END INIT INFO
0b1545
0b1545
# Source function library.
0b1545
. /etc/init.d/functions
0b1545
0b1545
prog="cpi"
0b1545
0b1545
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
0b1545
0b1545
cpipath=/sys/firmware/cpi
0b1545
0b1545
start() {
0b1545
    [ `id -u` -eq 0 ] || return 4
0b1545
    
0b1545
    echo -n $"Starting $prog: "
0b1545
0b1545
    if [ -d $cpipath ]; then
0b1545
        retval=0
0b1545
        echo LINUX > $cpipath/system_type 2> /dev/null || retval=1
0b1545
        [ $retval -eq 0 ] && echo "$SYSTEM_NAME" > $cpipath/system_name 2> /dev/null || retval=1
0b1545
        [ $retval -eq 0 ] && echo "$SYSPLEX_NAME" > $cpipath/sysplex_name 2> /dev/null || retval=1
0b1545
        level_maj=`uname -r | cut -d '-' -f 1 | cut -d '.' -f 1`
0b1545
        level_min=`uname -r | cut -d '-' -f 1 | cut -d '.' -f 2`
0b1545
        level_mic=`uname -r | cut -d '-' -f 1 | cut -d '.' -f 3`
0b1545
        level=`printf '%02x%02x%02x' $level_maj $level_min $level_mic`
0b1545
        [ $retval -eq 0 ] && echo $level > $cpipath/system_level 2> /dev/null || retval=1
0b1545
0b1545
        [ $retval -eq 0 ] && echo 1 > $cpipath/set 2> /dev/null || retval=1
0b1545
    else
0b1545
        retval=1
0b1545
    fi
0b1545
0b1545
    [ $retval -eq 0 ] && success || failure
0b1545
    echo
0b1545
    return $retval
0b1545
}
0b1545
0b1545
stop() {
0b1545
    echo -n $"Stopping $prog: "
0b1545
0b1545
    # nothing to do
0b1545
    success
0b1545
    echo
0b1545
    return 0
0b1545
}
0b1545
0b1545
restart() {
0b1545
    stop
0b1545
    start
0b1545
}
0b1545
0b1545
reload() {
0b1545
    restart
0b1545
}
0b1545
0b1545
force_reload() {
0b1545
    restart
0b1545
}
0b1545
0b1545
rh_status() {
0b1545
    if [ -d $cpipath ]; then
0b1545
        echo -n "System type: "; cat $cpipath/system_type
0b1545
        echo -n "System level: "; cat $cpipath/system_level
0b1545
        echo -n "System name: "; cat $cpipath/system_name
0b1545
        echo -n "Sysplex name: "; cat $cpipath/sysplex_name
0b1545
        retval=0
0b1545
    else
0b1545
        echo "Control Program Identification system interface doesn't exist."
0b1545
        retval=1
0b1545
    fi
0b1545
    return $retval
0b1545
}
0b1545
0b1545
rh_status_q() {
0b1545
    rh_status >/dev/null 2>&1
0b1545
}
0b1545
0b1545
0b1545
case "$1" in
0b1545
    start)
0b1545
        $1
0b1545
        ;;
0b1545
    stop)
0b1545
        $1
0b1545
        ;;
0b1545
    restart)
0b1545
        $1
0b1545
        ;;
0b1545
    reload)
0b1545
        rh_status_q || exit 7
0b1545
        $1
0b1545
        ;;
0b1545
    force-reload)
0b1545
        force_reload
0b1545
        ;;
0b1545
    status)
0b1545
        rh_status
0b1545
        ;;
0b1545
    condrestart|try-restart)
0b1545
        rh_status_q || exit 0
0b1545
        restart
0b1545
        ;;
0b1545
    *)
0b1545
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
0b1545
        exit 2
0b1545
esac
0b1545
exit $?