diff --git a/source/ipmitool-plugin/etc/rc.d/rc.ipmievd b/source/ipmitool-plugin/etc/rc.d/rc.ipmievd new file mode 100755 index 00000000..c0d2852a --- /dev/null +++ b/source/ipmitool-plugin/etc/rc.d/rc.ipmievd @@ -0,0 +1,81 @@ +#!/bin/sh +# start/stop/restart ipmievd daemon: +PROG="ipmievd" +DAEMON="/usr/sbin/$PROG" +LOCKFILE="/var/lock/$PROG" +PIDFILE="/var/run/$PROG.pid0" +CONFIG="/boot/config/plugins/ipmitool-plugin/ipmitool-plugin.cfg" +OPTIONS="" + +# read our configuration +[ -e "$CONFIG" ] && source "$CONFIG" + +# Start ipmievd: +ipmievd_start() { + # no-op if already running + if [[ ! -r "$PIDFILE" && "$IPMIEVD" == "enable" ]]; then + if [ $REMOTE == "enable" ]; then + OPTIONS="-I lanplus -H $IPADDR -U $USER -P $(echo $PASSWORD | base64 --decode)" + fi + echo "starting $PROG..." + sleep 1 + + nohup $DAEMON sel $OPTIONS > /dev/null 2>&1 | logger -tipmitool & + touch $LOCKFILE + TIMER=0 + while [ ! -e $PIDFILE ]; do + sleep 1 + let TIMER=$TIMER+1 + if [ $TIMER -gt 5 ]; then + echo -n "$PIDFILE not created" + break + fi + done + else + echo "$PROG is running " + fi +} + +# Stop ipmievd: +ipmievd_stop() { + # no-op if not running + if [ -r $PIDFILE ]; then + #stop ipmievd + echo "stopping $PROG..." + + TIMER=0 + while `killall $PROG 2>/dev/null`; do + sleep 1 + TIMER=$((TIMER+1)) + if [ $TIMER -ge 30 ]; then + killall -9 $PROG + sleep 1 + break + fi + done + rm -f $LOCKFILE && rm -f $PIDFILE + else + echo "$PROG is stopped " + fi +} + +# Restart ipmievd: +ipmievd_restart() { + ipmievd_stop + sleep 1 + ipmievd_start +} + +case "$1" in +'start') + ipmievd_start + ;; +'stop') + ipmievd_stop + ;; +'restart') + ipmievd_restart + ;; +*) + echo "usage rc.ipmievd: start|stop|restart" +esac \ No newline at end of file diff --git a/source/ipmitool-plugin/etc/rc.d/rc.ipmitail b/source/ipmitool-plugin/etc/rc.d/rc.ipmitail new file mode 100755 index 00000000..22ec43b9 --- /dev/null +++ b/source/ipmitool-plugin/etc/rc.d/rc.ipmitail @@ -0,0 +1,78 @@ +#!/bin/sh +# start/stop/restart ipmitail daemon: +PROG="ipmitail" +DAEMON="/usr/sbin/$PROG" +LOCKFILE="/var/lock/$PROG" +PIDFILE="/var/run/$PROG.pid" +CONFIG="/boot/config/plugins/ipmitool-plugin/ipmitool-plugin.cfg" +OPTIONS="" + +# read our configuration +[ -e "$CONFIG" ] && source "$CONFIG" + +# Start ipmitail: +ipmitail_start() { + # no-op if already running +if [[ ! -r "$PIDFILE" && "$IPMIEVD" == "enable" ]]; then + echo "starting $PROG..." + sleep 1 + + nohup $DAEMON >/dev/null 2>&1 | echo $! > $PIDFILE & + touch $LOCKFILE + TIMER=0 + while [ ! -e $PIDFILE ]; do + sleep 1 + let TIMER=$TIMER+1 + if [ $TIMER -gt 5 ]; then + echo -n "$PIDFILE not created" + break + fi + done +else + echo "$PROG is running " +fi +} + +# Stop ipmitail: +ipmitail_stop() { +# no-op if not running +if [ -r $PIDFILE ]; then + #stop ipmitail + echo "stopping $PROG..." + + TIMER=0 + while `killall $PROG 2>/dev/null`; do + sleep 1 + TIMER=$((TIMER+1)) + if [ $TIMER -ge 30 ]; then + killall -9 $PROG + sleep 1 + break + fi + done + rm -f $LOCKFILE && rm -f $PIDFILE +else + echo "$PROG is stopped " +fi +} + +# Restart ipmitail: +ipmitail_restart() { + ipmitail_stop + sleep 1 + ipmitail_start +} + +case "$1" in +'start') + ipmitail_start + ;; +'stop') + ipmitail_stop + ;; +'restart') + ipmitail_restart + ;; +*) + echo "usage rc.ipmitail: start|stop|restart" +esac \ No newline at end of file diff --git a/source/ipmitool-plugin/install/doinst.sh b/source/ipmitool-plugin/install/doinst.sh index 1a248525..0c74a26f 100644 --- a/source/ipmitool-plugin/install/doinst.sh +++ b/source/ipmitool-plugin/install/doinst.sh @@ -1 +1,25 @@ #!/bin/sh +RC_SCRIPT="/etc/rc.d/rc.ipmievd" +RC_SCRIPT2="/etc/rc.d/rc.ipmitail" +SD_RCFILE="/etc/rc.d/rc.local_shutdown" + +# Update file permissions of scripts +chmod +0755 /usr/local/emhttp/plugins/ipmitool-plugin/scripts/* \ + /usr/sbin/ipmitail \ + /usr/sbin/ipmifan \ + $RC_SCRIPT \ + $RC_SCRIPT2 + +###Stop Scripts### + +# Add stop script to rc.local_shutdown script +if ! grep "$RC_SCRIPT" $SD_RCFILE >/dev/null 2>&1 + then echo -e "\n[ -x $RC_SCRIPT ] && $RC_SCRIPT stop" >> $SD_RCFILE +fi +[ ! -x $SD_RCFILE ] && chmod u+x $SD_RCFILE + +# Add stop script to rc.local_shutdown script +if ! grep "$RC_SCRIPT2" $SD_RCFILE >/dev/null 2>&1 + then echo -e "\n[ -x $RC_SCRIPT2 ] && $RC_SCRIPT2 stop" >> $SD_RCFILE +fi +[ ! -x $SD_RCFILE ] && chmod u+x $SD_RCFILE \ No newline at end of file diff --git a/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/IPMIFans.page b/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/IPMIFans.page index a15d39eb..5b094b1b 100644 --- a/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/IPMIFans.page +++ b/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/IPMIFans.page @@ -5,248 +5,248 @@ Title="Fan Control" -IPMI Fan Control: +IPMI Fan Control: : +   - + - temperature sensor: -: - + - Low temperature threshold: -: - + - High temperature threshold: -: - +   - + - temperature sensor: -: - + - Low temperature threshold: -: - + - High temperature threshold: -: - +   - + - temperature sensor: -: - + - Low temperature threshold: -: - + - High temperature threshold: -: - +   - + - temperature sensor: -: - + - Low temperature threshold: -: - + - High temperature threshold: -: - +   - + - temperature sensor: -: - + - Low temperature threshold: -: - + - High temperature threshold: -: - +   - + - temperature sensor: -: - + - Low temperature threshold: -: - + - High temperature threshold: -: - +   - + - temperature sensor: -: - + - Low temperature threshold: -: - + - High temperature threshold: -: - +   - + - temperature sensor: -: - + - Low temperature threshold: -: - + - High temperature threshold: -: - +   - + - temperature sensor: -: - + - Low temperature threshold: -: - + - High temperature threshold: -: - +   - + - temperature sensor: -: - + - Low temperature threshold: -: - + - High temperature threshold: -: - + diff --git a/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/IPMISensors.page b/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/IPMISensors.page index 41ea2f66..c5dacc40 100644 --- a/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/IPMISensors.page +++ b/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/IPMISensors.page @@ -32,5 +32,5 @@ Icon="sensorspage.png" - + diff --git a/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/IPMISettings.page b/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/IPMISettings.page index a77400a6..7b76cb35 100644 --- a/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/IPMISettings.page +++ b/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/IPMISettings.page @@ -16,35 +16,35 @@ Enable Event Notifications: Enable Remote Connection: : -: +: -: +: -: +: Display CPU temperature: : Display Motherboard temperature: : Display Fan speed: : diff --git a/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmi_event_delete.php b/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmi_event_delete.php index c1944db4..4815bae9 100644 --- a/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmi_event_delete.php +++ b/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmi_event_delete.php @@ -1,5 +1,5 @@ diff --git a/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmitool_events.php b/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmitool_events.php index 72b9c1bc..35584ea7 100644 --- a/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmitool_events.php +++ b/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmitool_events.php @@ -1,4 +1,4 @@ \ No newline at end of file diff --git a/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmitool_helpers.php b/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmitool_helpers.php index 3bb1432b..46f1415e 100644 --- a/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmitool_helpers.php +++ b/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmitool_helpers.php @@ -1,41 +1,41 @@ /dev/null`/exe ] && echo 1 || echo 0 2> /dev/null" )); $ipmifan_running = trim(shell_exec( "[ -f /proc/`cat /var/run/ipmifan.pid 2> /dev/null`/exe ] && echo 1 || echo 0 2> /dev/null" )); -$running = "Running"; -$stopped = "Stopped"; -$ipmievd_status = ($ipmievd_running) ? $running : $stopped; -$ipmifan_status = ($ipmifan_running) ? $running : $stopped; +$ipmi_running = "Running"; +$ipmi_stopped = "Stopped"; +$ipmievd_status = ($ipmievd_running) ? $ipmi_running : $ipmi_stopped; +$ipmifan_status = ($ipmifan_running) ? $ipmi_running : $ipmi_stopped; // use save ip address or use local ipmi address -$ipaddr = preg_match('/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/', $cfg['IPADDR']) ? - $cfg['IPADDR'] : +$ipmi_ipaddr = preg_match('/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/', $ipmi_cfg['IPADDR']) ? + $ipmi_cfg['IPADDR'] : trim(shell_exec("/usr/bin/ipmitool lan print | grep 'IP Address ' | sed -n -e 's/^.*: //p'")); -$cpu_temp = isset($cfg['CPU_TEMP']) ? $cfg['CPU_TEMP'] : ""; // cpu temp display name -$mb_temp = isset($cfg['MB_TEMP']) ? $cfg['MB_TEMP'] : ""; // mb temp display name -$fan_disp = isset($cfg['FAN_DISP']) ? $cfg['FAN_DISP'] : ""; // fan speed display name -$user = isset($cfg['USER']) ? $cfg['USER'] : ""; // user for remote access -$password = isset($cfg['PASSWORD']) ? $cfg['PASSWORD'] : ""; // password for remote access +$ipmi_cpu_temp = isset($ipmi_cfg['CPU_TEMP']) ? $ipmi_cfg['CPU_TEMP'] : ""; // cpu temp display name +$ipmi_mb_temp = isset($ipmi_cfg['MB_TEMP']) ? $ipmi_cfg['MB_TEMP'] : ""; // mb temp display name +$ipmi_fan_disp = isset($ipmi_cfg['FAN_DISP']) ? $ipmi_cfg['FAN_DISP'] : ""; // fan speed display name +$ipmi_user = isset($ipmi_cfg['USER']) ? $ipmi_cfg['USER'] : ""; // user for remote access +$ipmi_password = isset($ipmi_cfg['PASSWORD']) ? $ipmi_cfg['PASSWORD'] : ""; // password for remote access // options for remote access or not -$options = ($remote == "enable") ? "-I lanplus -H '$ipaddr' -U '$user' -P '". - base64_decode($password)."'" : ""; +$ipmi_options = ($ipmi_remote == "enable") ? "-I lanplus -H '$ipmi_ipaddr' -U '$ipmi_user' -P '". + base64_decode($ipmi_password)."'" : ""; // Get sensor info and check connection if remote enabled -$sensors = ipmi_sensors($options); -$fans = ipmi_get_fans($sensors); +$ipmi_sensors = ipmi_sensors($ipmi_options); +$ipmi_fans = ipmi_get_fans($ipmi_sensors); -if($remote == "enable"){ - $conn = ($sensors) ? true : false; - $conn_check = ($conn) ? "Connection successful" : "Connection failed"; +if($ipmi_remote == "enable"){ + $ipmi_conn = ($ipmi_sensors) ? true : false; + $ipmi_conn_check = ($ipmi_conn) ? "Connection successful" : "Connection failed"; } /* get an array of all sensors and their values */ diff --git a/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmitool_sensors.php b/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmitool_sensors.php index 4b52d9e6..f7329e85 100644 --- a/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmitool_sensors.php +++ b/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmitool_sensors.php @@ -1,4 +1,4 @@ \ No newline at end of file diff --git a/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmitool_temp.php b/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmitool_temp.php index 58da0706..182c0a8b 100644 --- a/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmitool_temp.php +++ b/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmitool_temp.php @@ -1,23 +1,23 @@ 0 ? ($unit=='F' ? round(9/5*$reading+32) : str_replace('.',$dot,$reading)) : '##')." $unit"; } -if ($cpu_temp || $mb_temp || $fan_disp){ - $readings = ipmi_get_reading([$cpu_temp, $mb_temp, $fan_disp], $options); - $temps = []; +if ($ipmi_cpu_temp || $ipmi_mb_temp || $ipmi_fan_disp){ + $ipmi_readings = ipmi_get_reading([$ipmi_cpu_temp, $ipmi_mb_temp, $ipmi_fan_disp], $ipmi_options); + $ipmi_temps = []; - if ($readings[$cpu_temp]) - $temps[] = "".ipmi_temp($readings[$cpu_temp], $_GET['unit'], $_GET['dot']); + if ($ipmi_readings[$ipmi_cpu_temp]) + $ipmi_temps[] = "".format_ipmi_temp($ipmi_readings[$ipmi_cpu_temp], $_GET['unit'], $_GET['dot']); - if ($readings[$mb_temp]) - $temps[] = "".ipmi_temp($readings[$mb_temp], $_GET['unit'], $_GET['dot']); + if ($ipmi_readings[$ipmi_mb_temp]) + $ipmi_temps[] = "".format_ipmi_temp($ipmi_readings[$ipmi_mb_temp], $_GET['unit'], $_GET['dot']); - if ($readings[$fan_disp]) - $temps[] = "".$readings[$fan_disp]." rpm"; + if ($ipmi_readings[$ipmi_fan_disp]) + $ipmi_temps[] = "".$ipmi_readings[$ipmi_fan_disp]." rpm"; } -if ($temps) - echo "".implode(' ', $temps).""; +if ($ipmi_temps) + echo "".implode(' ', $ipmi_temps).""; ?> \ No newline at end of file diff --git a/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/scripts/start b/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/scripts/start index f0ac9f22..a1c18b99 100755 --- a/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/scripts/start +++ b/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/scripts/start @@ -1,36 +1,4 @@ #!/bin/sh -# read our configuration -DAEMON="/usr/sbin/ipmievd" -IPMITAIL="/usr/local/emhttp/plugins/ipmitool-plugin/scripts/ipmitail" -LOCKFILE="/var/lock/ipmievd" -PIDFILE="/var/run/ipmievd.pid0" -CONFIG="/boot/config/plugins/ipmitool-plugin/ipmitool-plugin.cfg" -OPTIONS="" - -if [ -e $CONFIG ]; then - source $CONFIG - if [ $IPMIEVD == "enable" ]; then - # no-op if already running - if [ ! -r $PIDFILE ]; then - if [ $REMOTE == "enable" ]; then - OPTIONS="-I lanplus -H $IPADDR -U $USER -P $(echo $PASSWORD | base64 --decode)" - fi - sleep 1 - - nohup $DAEMON sel $OPTIONS > /dev/null 2>&1 | logger -tipmitool & - touch $LOCKFILE - TIMER=0 - while [ ! -e $PIDFILE ]; do - sleep 1 - let TIMER=$TIMER+1 - if [ $TIMER -gt 5 ]; then - echo -n "$PIDFILE not created" - break - fi - done - if [ -r $PIDFILE ]; then - nohup $IPMITAIL >/dev/null 2>&1 < /dev/null & - fi - fi - fi -fi +/etc/rc.d/rc.ipmievd start +sleep 1 +/etc/rc.d/rc.ipmitail start diff --git a/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/scripts/stop b/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/scripts/stop index aa09ab90..f1d24deb 100755 --- a/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/scripts/stop +++ b/source/ipmitool-plugin/usr/local/emhttp/plugins/ipmitool-plugin/scripts/stop @@ -1,30 +1,4 @@ #!/bin/sh -DAEMON="ipmievd" -TAIL="ipmitail" -LOCKFILE="/var/lock/$DAEMON" -PIDFILE="/var/run/$DAEMON.pid0" - -# no-op if not running -if [ -r $PIDFILE ]; then -TIMER=0 -while `killall $DAEMON 2>/dev/null`; do - sleep 1 - TIMER=$((TIMER+1)) - if [ $TIMER -ge 30 ]; then - killall -9 $DAEMON - sleep 1 - break - fi -done -TIMER=0 -while `killall $TAIL 2>/dev/null`; do - sleep 1 - TIMER=$((TIMER+1)) - if [ $TIMER -ge 30 ]; then - killall -9 $TAIL - sleep 1 - break - fi -done -rm -f $LOCKFILE && rm -f $PIDFILE -fi +/etc/rc.d/rc.ipmievd stop +sleep 1 +/etc/rc.d/rc.ipmitail stop diff --git a/source/ipmitool-plugin/usr/sbin/ipmifan b/source/ipmitool-plugin/usr/sbin/ipmifan new file mode 100755 index 00000000..f4551118 --- /dev/null +++ b/source/ipmitool-plugin/usr/sbin/ipmifan @@ -0,0 +1,292 @@ +#!/usr/bin/php + 'AA', + 'CPU_FAN2' => 'BB', + 'REAR_FAN1' => 'CC', + 'REAR_FAN2' => 'DD', + 'FRNT_FAN1' => 'EE', + 'FRNT_FAN2' => 'FF' +]; + +function debug($m){ + global $prog, $DEBUG; + if($DEBUG){ + $STDERR = fopen('php://stderr', 'w+'); + fwrite($STDERR, $m."\n"); + fclose($STDERR); + } +} + +/*$background_args = ""; +if(isset($argv)){ + for ($i=0; $i <= count($argv); $i++) { + switch ($argv[$i]) { + case '--background': + $background = TRUE; + break; + case '-c': + $cron = $argv[$i+1]; + $background_args .= " ${argv[$i]} ${argv[$i+1]}"; + break; + case '-d': + $DEBUG = TRUE; + $background_args .= " ${argv[$i]}"; + break; + } + } +}*/ + +# Deal with cron +if ($cron) && is_numeric($cron) && !$quit){ + exec("crontab -l 2>/dev/null", $crontab); + $crontab = array_unique($crontab); + if (!$quit){ + $entry = sprintf("*/%s * * * * ${service}${background_args} 1> /dev/null 2>&1", $cron); + if (! preg_grep("#${service}#", $crontab)){ + $crontab[] = $entry; + debug("\nCRONTAB\n".implode("\n", $crontab)."\n"); + file_put_contents("/tmp/$prog.cron", implode(PHP_EOL, $crontab)); + shell_exec("crontab /tmp/$prog.cron"); + unlink("/tmp/$prog.cron"); + } + } + unset($crontab); +} else if ($quit){ + exec("crontab -l 2>/dev/null", $crontab); + $crontab = array_unique($crontab); + if (preg_grep("#${service}#", $crontab)){ + $crontab = preg_grep("#${service}#", $crontab, PREG_GREP_INVERT); + debug("\nCRONTAB\n".implode("\n", $crontab)."\n"); + file_put_contents("/tmp/$prog.cron", implode(PHP_EOL, $crontab)); + shell_exec("crontab /tmp/$prog.cron"); + unlink("/tmp/$prog.cron"); + }; + unset($crontab); +} + +if (is_file($lockfile)){ + $lock_pid = file($lockfile, FILE_IGNORE_NEW_LINES)[0]; + $pid = preg_replace("/\s+/", "", shell_exec("ps -p ${lock_pid}| grep ${lock_pid}")); + if (!$pid){ + if (!$quit){ + file_put_contents($lockfile, getmypid()); + } else { + echo "$lock_pid is not currently running"; + unlink($lockfile); + exit(0); + } + } else { + if ($quit){ + syslog(LOG_INFO, "killing daemon with PID [$lock_pid]"); + exec("kill $lock_pid"); + unlink($lockfile); + if (function_exists('at_exit')) at_exit(); + exit(0); + } else { + echo "$prog is already running [$lock_pid]".PHP_EOL; + exit(0); + } + } +} else { + if($quit){ + echo "$prog not currently running".PHP_EOL; + exit(0); + } else { + file_put_contents($lockfile, getmypid()); + } +} + +/*if(!$background){ + exec("php $service --background $background_args 1>/dev/null ".($DEBUG ? "":"2>&1 ")."&"); + exit(0); +} else { + syslog(LOG_INFO, "process started. To terminate it, type: $prog -q"); +} +*/ +############################## +##### PROGRAM SECTION ###### +############################## +$plugin = "ipmitool-plugin"; +$cfg_file = "/boot/config/plugins/$plugin/$plugin.cfg"; + +function scan_dir($dir, $type = ""){ + $out = array(); + foreach (array_slice(scandir($dir), 2) as $entry){ + $sep = (preg_match("/\/$/", $dir)) ? "" : "/"; + $out[] = $dir.$sep.$entry ; + } + return $out; +} + +function get_highest_temp($hdds){ + $highest_temp="0"; + foreach ($hdds as $hdd) { + if (shell_exec("hdparm -C ${hdd} 2>/dev/null| grep -c standby") == 0){ + $temp = preg_replace("/\s+/", "", shell_exec("smartctl -A ${hdd} 2>/dev/null| grep -m 1 -i Temperature_Celsius | awk '{print $10}'")); + $highest_temp = ($temp > $highest_temp) ? $temp : $highest_temp; + } + } + debug("Highest temp is ${highest_temp}ºC"); + return $highest_temp; +} + +function get_all_hdds(){ + $hdds = array(); + $flash = preg_replace("/\d$/", "", realpath("/dev/disk/by-label/UNRAID")); + foreach (scan_dir("/dev/") as $dev) { + if(preg_match("/[sh]d[a-z]+$/", $dev) && $dev != $flash) { + $hdds[] = $dev; + } + } + return $hdds; +} + +$hdds = get_all_hdds(); +while(TRUE){ while(TRUE){ +#### DO YOUR STUFF HERE #### + +# Load config file or die +if(is_file($cfg_file)){ + $params = parse_ini_file($cfg_file); + extract($params, EXTR_OVERWRITE); +} else { + unlink($lockfile); + exit(1); +} + +/*# Wait probes to become ready +if (!is_file($PWM_CONTROLLER) || ! is_file($PWM_FAN)){ + sleep(15); + continue; +}*/ + +# Set PWM_HIGH and PWM_OFF +$PWM_HIGH = 64; +$PWM_OFF = $PWM_LOW-5; + +# Disable fan mininum RPM +$FAN_RPM_MIN = file(split("_", $PWM_FAN)[0]."_min", FILE_IGNORE_NEW_LINES)[0]; +$D_FAN_RPM_MIN = ($FAN_RPM_MIN > 0) ? $FAN_RPM_MIN : FALSE; + +# Enable speed change on fan +/*$PWM_MODE=file("${PWM_CONTROLLER}_enable", FILE_IGNORE_NEW_LINES)[0]; +if($PWM_MODE != 1){ + $DEFAULT_PWM_MODE = $PWM_MODE; + file_put_contents("${PWM_CONTROLLER}_enable", 1); +}*/ + +# Calculate size of increments. +$TEMP_INCREMENTS = $TEMP_HIGH-$TEMP_LOW; +$PWM_INCREMENTS = round(($PWM_HIGH-$PWM_LOW)/$TEMP_INCREMENTS); +# Get current fan rpm and pwm +$CURRENT_PWM = preg_replace("/\s*/", "", file_get_contents($PWM_CONTROLLER)); +$CURRENT_RPM = preg_replace("/\s*/", "", file_get_contents($PWM_FAN)); +# Get current fan PWM percentage +$CURRENT_PERCENT_PWM = round(($CURRENT_PWM*100)/$PWM_HIGH); +$CURRENT_OUTPUT = "${CURRENT_PWM} (${CURRENT_PERCENT_PWM}% @ ${CURRENT_RPM}rpm)"; + +# Calculate a new scenario +# Get highest drive temperature +$HIGHEST_TEMP = get_highest_temp($hdds); +if ($HIGHEST_TEMP <= $TEMP_LOW){ + $NEW_PWM = $PWM_OFF; + $NEW_PERCENT_PWM = 0; +} else if ($HIGHEST_TEMP >= $TEMP_HIGH){ + $NEW_PWM = $PWM_HIGH; + $NEW_PERCENT_PWM = 100; +} else { + $NEW_PWM = (($HIGHEST_TEMP-$TEMP_LOW)*$PWM_INCREMENTS)+$PWM_LOW; + $NEW_PERCENT_PWM = round(($NEW_PWM*100)/$PWM_HIGH); +} + +# Change the fan speed as needed +if ($CURRENT_PWM != $NEW_PWM){ + file_put_contents($PWM_CONTROLLER, $NEW_PWM); + sleep(5); + $NEW_RPM = preg_replace("/\s*/", "", file_get_contents($PWM_FAN)); + $NEW_PERCENT_PWM = round(($NEW_PWM*100)/$PWM_HIGH); + $NEW_OUTPUT = "${NEW_PWM} (${NEW_PERCENT_PWM}% @ ${NEW_RPM}rpm)"; + syslog(LOG_INFO, "highest disk temp is ${HIGHEST_TEMP}ºC, adjusting fan PWM from: $CURRENT_OUTPUT to: $NEW_OUTPUT"); +} + +# PRINT VARIABLES DEBUG +$defined_vars = get_defined_vars(); +foreach (array("_GET","_POST","_COOKIE","_FILES","argv","argc","_SERVER") as $i) {unset($defined_vars[$i]);} +debug("\nDECLARED VARIABLES:\n".print_r($defined_vars, true)); +unset($defined_vars); + +$time1 = time(); +$MD5 = shell_exec("md5sum $cfg_file|awk '{print $1}'"); +$MD5 = md5_file($cfg_file); +for ($i=0; $i < $INTERVAL*6 ; $i++) { + sleep(10); + if (md5_file($cfg_file) != $MD5){syslog(LOG_INFO, "config file updated, reloading."); $i=10000;} +} +debug("Sleep ".(time()-$time1)." seconds."); + +###### END OF SECTION ###### +}; +}; +?> \ No newline at end of file diff --git a/source/ipmitool-plugin/usr/sbin/ipmitail b/source/ipmitool-plugin/usr/sbin/ipmitail new file mode 100755 index 00000000..401243e0 --- /dev/null +++ b/source/ipmitool-plugin/usr/sbin/ipmitail @@ -0,0 +1,23 @@ +#!/bin/bash + +DAEMON="ipmievd: " +LASTMSG="Waiting for events" +exec /usr/bin/tail -n 0 -F /var/log/syslog | \ + +while read LINE; +do + +# do not notify on ipmievd start +[[ "$LINE" == *"Reading sensors"* ]] && continue + +[[ "$LINE" == *"Waiting for events"* ]] && continue + +# do not notify on remote communication failure +[[ "$LINE" == *"Get SEL Info command failed"* ]] && continue + +# only notify when ipmievd: is in the system log +[[ "$LINE" != *$DAEMON* ]] && continue +MESSAGE=$(echo "$LINE" | sed -e 's/.*$DAEMON//') +sleep 1 | +exec /usr/local/emhttp/webGui/scripts/notify -s "Notice [$HOSTNAME]" -d "$MESSAGE" -i "warning" && continue 2 +done \ No newline at end of file