summaryrefslogtreecommitdiff
path: root/scripts/ipmi_info
blob: 13ed3b31d219aeba7c27258e2f700534a4b80abc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#! /bin/sh
#
# ipmi_info         
#
# chkconfig: 345 91 07
# description: ipmi_info saves the OS info (hostname, OS release) into
#		the IPMI System Info variables, if supported.
#               It does nothing if IPMI System Info is not supported.
#
### BEGIN INIT INFO
# Provides: ipmi_info
# Required-Start: $local_fs $network $remote_fs
# Required-Stop:  $local_fs $network $remote_fs
# Default-Start:  
# Default-Stop:   
# Short-Description: ipmi_info saves OS info to the IPMI system info
# Description: ipmi_info saves OS info to the IPMI system info
### END INIT INFO

name=ipmi_info
iuprog=/usr/bin/ipmiutil
tmp=/tmp/ipmi_info.tmp

getosver() {
   if [ -f /etc/os-release ]; then
      . /etc/os-release
      echo "${NAME} ${VERSION} kernel ${KERNEL_VERSION}"
   elif [ -f /etc/redhat-release ]; then
      cat /etc/redhat-release |head -n1 
   elif [ -f /etc/SuSE-release ]; then
      cat /etc/SuSE-release |head -n1 
   elif [ -f /etc/mvl-release ]; then
      sver=`grep Monta /etc/mvl-release |awk '{ print $4 }' |cut -f1 -d'.'`
      echo "Monta Vista Linux version $sver"
   elif [ -f /etc/debian_version ]; then
      sver=`grep Debian /etc/issue |awk '{ print $3 }'`
      echo "Debian Linux version $sver"
   else 
      sver=`uname -r`
      styp=`uname -s`
      echo "$styp $sver"
   fi
}

start()
{
	echo -n "Starting $name: "
	echo
	retval=0
	PID=0
        
	${iuprog} health -i >$tmp 2>&1
	if [ $? -eq 0 ]; then
           name=`hostname`
           os=`getosver`
	   echo "setting name=$name, os=$os ..." >>$tmp
	   ${iuprog} health -n "$name"  >>$tmp 2>&1 
	   ${iuprog} health -o "$os" >>$tmp 2>&1 
        else
           # IPMI System Info is not supported.
	   retval=0
	fi
	echo
	return $retval
}

stop()
{
	echo -n "Stopping $name: "
	echo
        retval=0
	echo
	return $retval
}

restart()
{
	stop
	start
}

rh_status() {
    echo "$name is stopped"
    retval=3
    return $retval
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
  start)
        rh_status_q && exit 0
	start
	;;
  stop)
        rh_status_q || exit 0
	stop
	;;
  status)
	rh_status 
	;;
  restart)
	restart
	;;
  reload)
        rh_status_q || exit 7
	restart
	;;
  force_reload)
	restart
	;;
  condrestart|try-restart)
	rh_status_q || exit 0
	restart
	;;
  *)
	echo "Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
	exit 2
esac

exit $?