This commit is contained in:
Derek Macias 2016-01-29 16:41:53 -07:00
parent 8bfaca7966
commit 6bf837bfcb
11 changed files with 201 additions and 137 deletions

View File

@ -6,7 +6,7 @@ Title="Event Log"
<thead> <thead>
<tr> <tr>
<th class="sorter-false filter-false"> Status </th> <th class="sorter-false filter-false"> Status </th>
<th class="sorter-digit filter-false"> Event ID </th> <th class="sorter-metric filter-false"> Event ID </th>
<th class="filter-time" data-placeholder="by time"> Time Stamp </th> <th class="filter-time" data-placeholder="by time"> Time Stamp </th>
<th class="filter-name" data-placeholder="by name"> Sensor Name </th> <th class="filter-name" data-placeholder="by name"> Sensor Name </th>
<th class="filter-desc" data-placeholder="Search..."> Description </th> <th class="filter-desc" data-placeholder="Search..."> Description </th>

View File

@ -69,7 +69,7 @@ function detectFanLow() {
} }
} }
$(function() { $(function() {
showStatus('<?=$sName?>'); //showStatus('<?=$sName?>');
}); });
</script> </script>

View File

@ -33,4 +33,5 @@ Icon="sensorspage.png"
<script type="text/javascript" src="/plugins/ipmitool-plugin/js/jquery.ipmitool-plugin.js"></script> <script type="text/javascript" src="/plugins/ipmitool-plugin/js/jquery.ipmitool-plugin.js"></script>
<script type="text/javascript" src="/plugins/tablesorter/js/jquery.tablesorter.combined.min.js"></script> <script type="text/javascript" src="/plugins/tablesorter/js/jquery.tablesorter.combined.min.js"></script>
<script type="text/javascript" src="/plugins/tablesorter/js/pager/jquery.tablesorter.pager.js"></script> <script type="text/javascript" src="/plugins/tablesorter/js/pager/jquery.tablesorter.pager.js"></script>
<script type="text/javascript" src="/plugins/tablesorter/js/parsers/parser-metric.min.js"></script>
<script type="text/javascript" src="/webGui/javascript/jquery.switchbutton.js"></script> <script type="text/javascript" src="/webGui/javascript/jquery.switchbutton.js"></script>

View File

@ -14,38 +14,38 @@ $sName = "ipmievd";
Enable Event Notifications: Enable Event Notifications:
: <select id="SERVICE" name="SERVICE" size="1" onChange="checkRUNNING(this.form);"> : <select id="SERVICE" name="SERVICE" size="1" onChange="checkRUNNING(this.form);">
<?=mk_option($ipmitool_service, "disable", "No");?> <?=mk_option($service, "disable", "No");?>
<?=mk_option($ipmitool_service, "enable", "Yes");?> <?=mk_option($service, "enable", "Yes");?>
</select> </select>
Enable Remote Connection: Enable Remote Connection:
: <select id="REMOTE" class="ipmitool-run" name="REMOTE" title="" size="1" onChange="checkREMOTE(this.form);"> : <select id="REMOTE" class="ipmitool-run" name="REMOTE" title="" size="1" onChange="checkREMOTE(this.form);">
<?=mk_option($ipmitool_remote, "disable", "No");?> <?=mk_option($remote, "disable", "No");?>
<?=mk_option($ipmitool_remote, "enable", "Yes");?> <?=mk_option($remote, "enable", "Yes");?>
</select> </select>
<label class="ipmitool-lan">IPMI IP Address:</label> <label class="ipmitool-lan">IPMI IP Address:</label>
: <input id="IPADDR" type="text" class="ipmitool-lan ipmitool-ipaddr" name="IPADDR" maxlength="40" value="<?=$ipmitool_ipaddr;?>" title="IPMI IP address" placeholder="" > : <input id="IPADDR" type="text" class="ipmitool-lan ipmitool-ipaddr" name="IPADDR" maxlength="40" value="<?=$ipaddr;?>" title="IPMI IP address" placeholder="" >
<label class="ipmitool-lan">IPMI User Name:</label> <label class="ipmitool-lan">IPMI User Name:</label>
: <input id="USER" type="text" class="ipmitool-lan" name="USER" maxlength="40" value="<?=$ipmitool_user;?>" title="username for remote access IPMI" placeholder="username for remote access" > : <input id="USER" type="text" class="ipmitool-lan" name="USER" maxlength="40" value="<?=$user;?>" title="username for remote access IPMI" placeholder="username for remote access" >
<label class="ipmitool-lan">IPMI Password:</label> <label class="ipmitool-lan">IPMI Password:</label>
: <input id="PASSWORD" type="password" class="ipmitool-lan" name="PASSWORD" maxlength="40" value="<?=$ipmitool_password;?>" title="password for remote access IPMI" placeholder="password for remote access" > : <input id="PASSWORD" type="password" class="ipmitool-lan" name="PASSWORD" maxlength="40" value="<?=$password;?>" title="password for remote access IPMI" placeholder="password for remote access" >
Display CPU temperature: Display CPU temperature:
: <select name="CPU_TEMP"> : <select name="CPU_TEMP">
<?=ipmi_get_options($ipmitool_cpu, 'Temperature', $ipmitool_options);?> <?=ipmi_get_options($cpu, 'Temperature', $options);?>
</select> </select>
Display Motherboard temperature: Display Motherboard temperature:
: <select name="MB_TEMP"> : <select name="MB_TEMP">
<?=ipmi_get_options($ipmitool_mb, 'Temperature', $ipmitool_options);?> <?=ipmi_get_options($mb, 'Temperature', $options);?>
</select> </select>
Display Fan speed: Display Fan speed:
: <select name="IPMI_FAN"> : <select name="IPMI_FAN">
<?=ipmi_get_options($ipmitool_fan, 'Fan', $ipmitool_options);?> <?=ipmi_get_options($fan, 'Fan', $options);?>
</select> </select>
<input id="DEFAULT" class="ipmitool-run" type="button" value="Default" onClick="resetDATA(this.form);"> <input id="DEFAULT" class="ipmitool-run" type="button" value="Default" onClick="resetDATA(this.form);">
@ -54,7 +54,9 @@ Display Fan speed:
<script type="text/javascript"> <script type="text/javascript">
$(function(){ $(function(){
showStatus('<?=$sName;?>'); $('.tabs')
.append("<span class='status'>Fan Control: <?=$ipmifan_status;?> </span>")
.append("<span class='status'>Event Notification: <?=$ipmievd_status;?> </span>");
checkRUNNING(document.ipmitool_settings); checkRUNNING(document.ipmitool_settings);
checkREMOTE(document.ipmitool_settings); checkREMOTE(document.ipmitool_settings);
decData(document.ipmitool_settings); decData(document.ipmitool_settings);
@ -71,7 +73,7 @@ function resetDATA(form) {
} }
function checkRUNNING(form) { function checkRUNNING(form) {
if ("<?=$ipmitool_running;?>" == "yes") if ("<?=$ipmievd_running;?>" == "yes")
{ {
$(".ipmitool-run").prop("disabled", true); $(".ipmitool-run").prop("disabled", true);
form.btnApply.disabled = "disabled"; form.btnApply.disabled = "disabled";

View File

@ -1,5 +1,5 @@
<?php <?php
require_once '/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmitool_helpers.php'; require_once '/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmitool_helpers.php';
$cmd = "/usr/bin/ipmitool sel ".$_GET["options"].$ipmitool_options; $cmd = "/usr/bin/ipmitool sel ".$_GET["options"].$options;
exec($cmd); exec($cmd);
?> ?>

View File

@ -1,4 +1,4 @@
<?php <?php
require_once '/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmitool_helpers.php'; require_once '/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmitool_helpers.php';
echo json_encode(ipmi_events($ipmitool_options)); echo json_encode(ipmi_events($options));
?> ?>

View File

@ -1,75 +1,85 @@
<?php <?php
/* ipmi tool variables*/ /* ipmi tool variables*/
$plugin = 'ipmitool-plugin'; $plugin = 'ipmitool-plugin';
$ipmitool_cfg = parse_ini_file("/boot/config/plugins/$plugin/$plugin.cfg"); $cfg = parse_ini_file("/boot/config/plugins/$plugin/$plugin.cfg");
$ipmitool_service = isset($ipmitool_cfg['SERVICE']) ? $ipmitool_cfg['SERVICE'] : "disable"; $service = isset($cfg['SERVICE']) ? $cfg['SERVICE'] : "disable";
$ipmitool_remote = isset($ipmitool_cfg['REMOTE']) ? $ipmitool_cfg['REMOTE'] : "disable"; $remote = isset($cfg['REMOTE']) ? $cfg['REMOTE'] : "disable";
$ipmitool_running = trim(shell_exec( "[ -f /proc/`cat /var/run/ipmievd.pid0 2> /dev/null`/exe ] && echo 'yes' || echo 'no' 2> /dev/null" )); $ipmievd_running = trim(shell_exec( "[ -f /proc/`cat /var/run/ipmievd.pid0 2> /dev/null`/exe ] && echo 'yes' || echo 'no' 2> /dev/null" ));
$running = "<span class='green'>Running</span>";
// get ip address of local ipmi $stopped = "<span class='orange'>Stopped</span>";
$ipmitool_lanip = trim(shell_exec("/usr/bin/ipmitool lan print | grep 'IP Address ' | sed -n -e 's/^.*: //p'")); $ipmievd_status = ($ipmievd_running == "yes") ? $running : $stopped;
$ipmifan_status = ($ipmifan_running == "yes") ? $running : $stopped;
// use save ip address or use local ipmi address // use save ip address or use local ipmi address
$ipmitool_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}$/', $ipmitool_cfg['IPADDR']) ? $ipmitool_cfg['IPADDR'] : $ipmitool_lanip; $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'] :
trim(shell_exec("/usr/bin/ipmitool lan print | grep 'IP Address ' | sed -n -e 's/^.*: //p'"));
$ipmitool_cpu = isset($ipmitool_cfg['CPU_TEMP']) ? $ipmitool_cfg['CPU_TEMP'] : ""; // cpu temp display name $cpu = isset($cfg['CPU_TEMP']) ? $cfg['CPU_TEMP'] : ""; // cpu temp display name
$ipmitool_mb = isset($ipmitool_cfg['MB_TEMP']) ? $ipmitool_cfg['MB_TEMP'] : ""; // mb temp display name $mb = isset($cfg['MB_TEMP']) ? $cfg['MB_TEMP'] : ""; // mb temp display name
$ipmitool_fan = isset($ipmitool_cfg['IPMI_FAN']) ? $ipmitool_cfg['IPMI_FAN'] : ""; // fan speed display name $fan = isset($cfg['IPMI_FAN']) ? $cfg['IPMI_FAN'] : ""; // fan speed display name
$ipmitool_user = isset($ipmitool_cfg['USER']) ? $ipmitool_cfg['USER'] : ""; // user for remote access $user = isset($cfg['USER']) ? $cfg['USER'] : ""; // user for remote access
$ipmitool_password = isset($ipmitool_cfg['PASSWORD']) ? $ipmitool_cfg['PASSWORD'] : ""; // password for remote access $password = isset($cfg['PASSWORD']) ? $cfg['PASSWORD'] : ""; // password for remote access
$sensors = [$cpu, $mb, $fan];
// options for remote access or not // options for remote access or not
$ipmitool_options = ($remote == "enable") ? " -I lanplus -H '$ipmitool_ipaddr' -U '$ipmitool_user' -P '". $options = ($remote == "enable") ? "-I lanplus -H '$ipaddr' -U '$user' -P '".
base64_decode($ipmitool_password)."' " : ""; base64_decode($password)."'" : "";
/* get an array of all sensors and their values */ /* get an array of all sensors and their values */
function ipmi_sensors($options) { function ipmi_sensors($options) {
$cmd = "/usr/bin/ipmitool -vc sdr $options 2>/dev/null"; $cmd = "/usr/bin/ipmitool -vc sdr $options -N 1 -R 1 2>/dev/null";
exec($cmd, $output); exec($cmd, $output, $return);
if ($return)
return [];
// key names for ipmitool sensor output // key names for ipmitool sensor output
$sensor_keys = array('Name','Reading','Units','Status','Entity','Location','Type','Nominal', $keys = ['Name','Reading','Units','Status','Entity','Location','Type','Nominal',
'NormalMin','NormalMax','UpperNonRec','UpperCritical','UpperNonCritical','LowerNonRec', 'NormalMin','NormalMax','UpperNonRec','UpperCritical','UpperNonCritical','LowerNonRec',
'LowerCritical','LowerNonCritical','MinRange','MaxRange' ); 'LowerCritical','LowerNonCritical','MinRange','MaxRange'];
$sensors_array = []; $sensors = [];
foreach($output as $sensor){ foreach($output as $line){
// add sensor keys as keys to ipmitool output // add sensor keys as keys to ipmitool output
$sensor_array = array_combine($sensor_keys, array_slice(explode(",", $sensor),0,18,true)); $sensor = array_combine($keys, array_slice(explode(",", $line),0,18,true));
// add sensor to array of sensors // add sensor to array of sensors
$sensors_array[] = $sensor_array; $sensors[] = $sensor;
} }
return $sensors_array; return $sensors;
} }
/* get array of events and their values */ /* get array of events and their values */
function ipmi_events($options){ function ipmi_events($options=null){
$cmd = "/usr/bin/ipmitool -c sel elist $options 2>/dev/null"; $cmd = "/usr/bin/ipmitool -c sel elist $options -N 1 -R 1 2>/dev/null";
exec($cmd, $output); exec($cmd, $output, $return);
if ($return)
return [];
// key names for ipmitool event output // key names for ipmitool event output
$event_keys = array('Event','Datestamp','Timestamp','Sensor','Description','Status'); $keys = array('Event','Datestamp','Timestamp','Sensor','Description','Status');
$events_array = []; $events = [];
foreach($output as $event){ foreach($output as $line){
// add event keys as keys to ipmitool output cut to match // add event keys as keys to ipmitool output cut to match
$event_array = array_combine($event_keys, array_slice(explode(",", $event),0,6,true)); $event = array_combine($keys, array_slice(explode(",", $line),0,6,true));
$events_array[] = $event_array; $events[] = $event;
} }
return $events_array; return $events;
} }
/* get select options for a given sensor type */ /* get select options for a given sensor type */
function ipmi_get_options($selected, $type, $options){ function ipmi_get_options($selected, $type, $options){
$sensors_array = ipmi_sensors($options); $sensors = ipmi_sensors($options=null);
$options = "<option value='false'>No</option>\n"; $options = "<option value='false'>No</option>\n";
foreach($sensors_array as $sensor){ foreach($sensors as $sensor){
if ($sensor["Type"] == $type && $sensor["Status"] != "ns"){ if ($sensor["Type"] == $type && $sensor["Status"] != "ns"){
$name = $sensor["Name"]; $name = $sensor["Name"];
$options .= "<option value='$name'"; $options .= "<option value='$name'";
@ -85,14 +95,25 @@ function ipmi_get_options($selected, $type, $options){
} }
/* get reading for a given sensor by name */ /* get reading for a given sensor by name */
function ipmi_get_reading($sensor, $options) { function ipmi_get_reading($names, $options=null) {
$readings = [];
$cmd = "/usr/bin/ipmitool -c sdr $options -N 1 -R 1 2>/dev/null";
exec($cmd, $output, $return);
$sensors_array = ipmi_sensors($options); if ($return)
return [];
foreach($sensors_array as $sensor_array){ for ($i = 0; $i < sizeof($names); $i++) {
if ($sensor_array["Name"] == $sensor) {
return $sensor_array["Reading"]; foreach($output as $sensor){
} $sensors = explode(",", $sensor);
if ($sensors[0] == $names[$i]) // check name
$readings[$names[$i]] = $sensors[1]; // reading
}
} }
return $readings; // reading
} }
?> //echo json_encode(ipmi_get_reading($sensors, $options));
//echo json_encode(ipmi_sensors($options));
?>

View File

@ -1,4 +1,4 @@
<?php <?php
require_once '/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmitool_helpers.php'; require_once '/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmitool_helpers.php';
echo json_encode(ipmi_sensors($ipmitool_options)); echo json_encode(ipmi_sensors($options));
?> ?>

View File

@ -1,27 +1,23 @@
<? <?
require_once '/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmitool_helpers.php'; require_once '/usr/local/emhttp/plugins/ipmitool-plugin/include/ipmitool_helpers.php';
function my_temp($reading, $unit, $dot) { function ipmi_temp($reading, $unit, $dot) {
return ($reading>0 ? ($unit=='F' ? round(9/5*$reading+32) : str_replace('.',$dot,$reading)) : '##')."&thinsp;$unit"; return ($reading>0 ? ($unit=='F' ? round(9/5*$reading+32) : str_replace('.',$dot,$reading)) : '##')."&thinsp;$unit";
} }
$sensors_array = []; if ($cpu || $mb || $fan){
$readings = ipmi_get_reading($sensors, $options);
$temps = [];
if ($ipmitool_cpu){ if ($readings[$cpu])
$ipmitool_cpu_temp = ipmi_get_reading($ipmitool_cpu, $ipmitool_options); $temps[] = "<img src='/plugins/$plugin/icons/cpu.png' title='$cpu' class='icon'>".ipmi_temp($readings[$cpu], $_GET['unit'], $_GET['dot']);
if ($ipmitool_cpu_temp)
$sensors_array[] = "<img src='/plugins/$plugin/icons/cpu.png' title='$ipmitool_cpu' class='icon'>".my_temp($ipmitool_cpu_temp, $_GET['unit'], $_GET['dot']); if ($readings[$mb])
$temps[] = "<img src='/plugins/$plugin/icons/mb.png' title='$mb' class='icon'>".ipmi_temp($readings[$mb], $_GET['unit'], $_GET['dot']);
if ($readings[$fan])
$temps[] = "<img src='/plugins/$plugin/icons/fan.png' title='$fan' class='icon'>".$readings[$fan]."&thinsp;rpm";
} }
if ($ipmitool_mb){ if ($temps)
$ipmitool_mb_temp = ipmi_get_reading($ipmitool_mb, $ipmitool_options); echo "<span id='temps' style='margin-right:16px'>".implode('&nbsp;', $temps)."</span>";
if ($ipmitool_mb_temp)
$sensors_array[] = "<img src='/plugins/$plugin/icons/mb.png' title='$ipmitool_mb' class='icon'>".my_temp($ipmitool_mb_temp, $_GET['unit'], $_GET['dot']);
}
if ($ipmitool_fan){
$ipmitool_fan_rpm = ipmi_get_reading($ipmitool_fan, $ipmitool_options);
if ($ipmitool_fan_rpm)
$sensors_array[] = "<img src='/plugins/$plugin/icons/fan.png' title='$ipmitool_fan' class='icon'>".$ipmitool_fan_rpm."&thinsp;rpm";
}
if ($sensors_array)
echo "<span id='temps' style='margin-right:16px'>".implode('&nbsp;', $sensors_array)."</span>";
?> ?>

View File

@ -68,8 +68,6 @@ function sensorArray(Refresh){
$.each(data, function (i, val) { $.each(data, function (i, val) {
if (data[i].Status != "ns") { if (data[i].Status != "ns") {
var Reading = parseFloat(data[i].Reading); var Reading = parseFloat(data[i].Reading);
//if (data[i].Name == "+5VSB")
//Reading = 6.2;
var LowerNonRec = parseFloat(data[i].LowerNonRec); var LowerNonRec = parseFloat(data[i].LowerNonRec);
var LowerCritical = parseFloat(data[i].LowerCritical); var LowerCritical = parseFloat(data[i].LowerCritical);
var LowerNonCritical = parseFloat(data[i].LowerNonCritical); var LowerNonCritical = parseFloat(data[i].LowerNonCritical);
@ -83,18 +81,15 @@ function sensorArray(Refresh){
if (data[i].Type=="Voltage"){ if (data[i].Type=="Voltage"){
// if voltage is less than lower non-recoverable // if voltage is less than lower non-critical
// or voltage is greater than upper non-recoverable // or voltage is greater than upper non-critical show orange
if (Reading < LowerNonRec || Reading > UpperNonRec) if (Reading < LowerNonCritical && Reading > UpperNonCritical)
Color = "red";
// if voltage is between lower non recoverable and
if (Reading > LowerNonRec && Reading < UpperNonRec)
Color = "red";
if (Reading > LowerCritical && Reading < UpperCritical)
Color = "orange"; Color = "orange";
if (Reading > LowerNonCritical && Reading < UpperNonCritical)
Color = "green"; // if voltage is less than lower critical
// or voltage is greater than upper critical show red
if (Reading < LowerCritical || Reading > UpperCritical)
Color = "red";
} else if (data[i].Type=="Fan"){ } else if (data[i].Type=="Fan"){

View File

@ -8,19 +8,70 @@ $DEBUG = FALSE;
# DO NOT TOUCH # DO NOT TOUCH
set_time_limit(0); set_time_limit(0);
$program_name = pathinfo(__FILE__, PATHINFO_FILENAME); $prog = pathinfo(__FILE__, PATHINFO_FILENAME);
$lockfile = "/var/run/${program_name}.pid"; $lockfile = "/var/run/$prog.pid";
$service_file = __FILE__; $service = __FILE__;
openlog($program_name, LOG_PID | LOG_PERROR, LOG_LOCAL0); openlog($prog, LOG_PID | LOG_PERROR, LOG_LOCAL0);
$usage = <<<EOT $usage = <<<EOF
Usage: $program_name = start the daemon
$program_name -q = quit the program if it is running
EOT; Process settings files in ipmitool-plugin config. Control fans based on the config value and [options].
Usage: $prog [options] = start daemon
-c, --cron create a cron job
-d, --debug turn on debugging
-q, --quit terminate $prog if running
-v, --verbose print all messages
--help display this help and exit
--version output version information and exit
EOF;
$shortopts = "cquv";
$longopts = [
"cron",
"debug",
"help",
"quiet",
"quit",
"verbose",
"version"
];
$args = getopt($shortopts, $longopts);
if (array_key_exists("help", $args)) {
echo $usage;
exit(1);
}
if (array_key_exists("version", $args)) {
echo "IPMI Fan Control: 1.0\n";
exit(1);
}
$argcr = (array_key_exists("c", $args) || array_key_exists("cron", $args));
$argd = (array_key_exists("d", $args) || array_key_exists("debug", $args));
$argq = (array_key_exists("q", $args) || array_key_exists("quit", $args));
$argu = (array_key_exists("u", $args) || array_key_exists("uninstall", $args));
$argv = (array_key_exists("v", $args) || array_key_exists("verbose", $args));
// ipmitool raw 0x3a 0x01 0xAA 0xBB 0xCC 0xDD 0xEE 0xFF 0xGG 0xHH
//ipmitool raw 0x3a 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
// 0x00 = smartfan mode
// 0x01 - 0x64 = 1% - 100%
$asrock_array = [
'CPU_FAN1' => 'AA',
'CPU_FAN2' => 'BB',
'REAR_FAN1' => 'CC',
'REAR_FAN2' => 'DD',
'FRNT_FAN1' => 'EE',
'FRNT_FAN2' => 'FF'
];
function debug($m){ function debug($m){
global $program_name, $DEBUG; global $prog, $DEBUG;
if($DEBUG){ if($DEBUG){
$STDERR = fopen('php://stderr', 'w+'); $STDERR = fopen('php://stderr', 'w+');
fwrite($STDERR, $m."\n"); fwrite($STDERR, $m."\n");
@ -32,9 +83,6 @@ $background_args = "";
if(isset($argv)){ if(isset($argv)){
for ($i=0; $i <= count($argv); $i++) { for ($i=0; $i <= count($argv); $i++) {
switch ($argv[$i]) { switch ($argv[$i]) {
case '-q':
$quit = TRUE;
break;
case '--background': case '--background':
$background = TRUE; $background = TRUE;
break; break;
@ -56,29 +104,29 @@ if(isset($argv)){
} }
# Deal with cron # Deal with cron
if (isset($cron) && is_numeric($cron) && ! isset($quit)){ if ($cron) && is_numeric($cron) && !$argq){
exec("crontab -l 2>/dev/null", $crontab); exec("crontab -l 2>/dev/null", $crontab);
$crontab = array_unique($crontab); $crontab = array_unique($crontab);
if (! isset($quit)){ if (!$argq){
$entry = sprintf("*/%s * * * * ${service_file}${background_args} 1> /dev/null 2>&1", $cron); $entry = sprintf("*/%s * * * * ${service}${background_args} 1> /dev/null 2>&1", $cron);
if (! preg_grep("#${service_file}#", $crontab)){ if (! preg_grep("#${service}#", $crontab)){
$crontab[] = $entry; $crontab[] = $entry;
debug("\nCRONTAB\n".implode("\n", $crontab)."\n"); debug("\nCRONTAB\n".implode("\n", $crontab)."\n");
file_put_contents("/tmp/${program_name}.cron", implode(PHP_EOL, $crontab)); file_put_contents("/tmp/$prog.cron", implode(PHP_EOL, $crontab));
shell_exec("crontab /tmp/${program_name}.cron"); shell_exec("crontab /tmp/$prog.cron");
unlink("/tmp/$program_name.cron"); unlink("/tmp/$prog.cron");
} }
} }
unset($crontab); unset($crontab);
} else if (isset($quit)){ } else if ($argq){
exec("crontab -l 2>/dev/null", $crontab); exec("crontab -l 2>/dev/null", $crontab);
$crontab = array_unique($crontab); $crontab = array_unique($crontab);
if (preg_grep("#${service_file}#", $crontab)){ if (preg_grep("#${service}#", $crontab)){
$crontab = preg_grep("#${service_file}#", $crontab, PREG_GREP_INVERT); $crontab = preg_grep("#${service}#", $crontab, PREG_GREP_INVERT);
debug("\nCRONTAB\n".implode("\n", $crontab)."\n"); debug("\nCRONTAB\n".implode("\n", $crontab)."\n");
file_put_contents("/tmp/${program_name}.cron", implode(PHP_EOL, $crontab)); file_put_contents("/tmp/$prog.cron", implode(PHP_EOL, $crontab));
shell_exec("crontab /tmp/${program_name}.cron"); shell_exec("crontab /tmp/$prog.cron");
unlink("/tmp/$program_name.cron"); unlink("/tmp/$prog.cron");
}; };
unset($crontab); unset($crontab);
} }
@ -86,47 +134,47 @@ if (isset($cron) && is_numeric($cron) && ! isset($quit)){
if (is_file($lockfile)){ if (is_file($lockfile)){
$lock_pid = file($lockfile, FILE_IGNORE_NEW_LINES)[0]; $lock_pid = file($lockfile, FILE_IGNORE_NEW_LINES)[0];
$pid_running=preg_replace("/\s+/", "", shell_exec("ps -p ${lock_pid}| grep ${lock_pid}")); $pid_running=preg_replace("/\s+/", "", shell_exec("ps -p ${lock_pid}| grep ${lock_pid}"));
if (! $pid_running){ if (!$pid_running){
if (! isset($quit)){ if (!$argq){
file_put_contents($lockfile, getmypid()); file_put_contents($lockfile, getmypid());
} else { } else {
echo "${lock_pid} is not currently running"; echo "$lock_pid is not currently running";
unlink($lockfile); unlink($lockfile);
exit(0); exit(0);
} }
} else { } else {
if (isset($quit)){ if ($argq){
syslog(LOG_INFO, "killing daemon with PID [${lock_pid}]"); syslog(LOG_INFO, "killing daemon with PID [${lock_pid}]");
exec("kill $lock_pid"); exec("kill $lock_pid");
unlink($lockfile); unlink($lockfile);
if (function_exists('at_exit')) at_exit(); if (function_exists('at_exit')) at_exit();
exit(0); exit(0);
} else { } else {
echo "$program_name is already running [${lock_pid}]".PHP_EOL; echo "$prog is already running [${lock_pid}]".PHP_EOL;
exit(0); exit(0);
} }
} }
} else { } else {
if(isset($quit)){ if($argq){
echo "$program_name not currently running".PHP_EOL; echo "$prog not currently running".PHP_EOL;
exit(0); exit(0);
} else { } else {
file_put_contents($lockfile, getmypid()); file_put_contents($lockfile, getmypid());
} }
} }
if(!isset($background)){ if(!$background){
exec("php $service_file --background $background_args 1>/dev/null ".($DEBUG ? "":"2>&1 ")."&"); exec("php $service --background $background_args 1>/dev/null ".($DEBUG ? "":"2>&1 ")."&");
exit(0); exit(0);
} else { } else {
syslog(LOG_INFO, "process started. To terminate it, type: $program_name -q"); syslog(LOG_INFO, "process started. To terminate it, type: $prog -q");
} }
############################## ##############################
##### PROGRAM SECTION ###### ##### PROGRAM SECTION ######
############################## ##############################
$plugin = "dynamix.system.autofan"; $plugin = "ipmitool-plugin";
$config_file = "/boot/config/plugins/${plugin}/fan.conf"; $cfg_file = "/boot/config/plugins/$plugin/$plugin.cfg";
function scan_dir($dir, $type = ""){ function scan_dir($dir, $type = ""){
$out = array(); $out = array();
@ -165,8 +213,8 @@ while(TRUE){ while(TRUE){
#### DO YOUR STUFF HERE #### #### DO YOUR STUFF HERE ####
# Load config file or die # Load config file or die
if(is_file($config_file)){ if(is_file($cfg_file)){
$params = (is_file($config_file)) ? parse_ini_file($config_file) : array(); $params = parse_ini_file($cfg_file);
extract($params, EXTR_OVERWRITE); extract($params, EXTR_OVERWRITE);
} else { } else {
unlink($lockfile); unlink($lockfile);
@ -174,13 +222,13 @@ if(is_file($config_file)){
} }
# Wait probes to become ready # Wait probes to become ready
if (! is_file($PWM_CONTROLLER) || ! is_file($PWM_FAN)){ if (!is_file($PWM_CONTROLLER) || ! is_file($PWM_FAN)){
sleep(15); sleep(15);
continue; continue;
} }
# Set PWM_HIGH and PWM_OFF # Set PWM_HIGH and PWM_OFF
$PWM_HIGH = 255; $PWM_HIGH = 64;
$PWM_OFF = $PWM_LOW-5; $PWM_OFF = $PWM_LOW-5;
# Disable fan mininum RPM # Disable fan mininum RPM
@ -235,14 +283,15 @@ debug("\nDECLARED VARIABLES:\n".print_r($defined_vars, true));
unset($defined_vars); unset($defined_vars);
$time1 = time(); $time1 = time();
$MD5 = shell_exec("md5sum $config_file|awk '{print $1}'"); $MD5 = shell_exec("md5sum $cfg_file|awk '{print $1}'");
$MD5 = md5_file($config_file); $MD5 = md5_file($cfg_file);
for ($i=0; $i < $INTERVAL*6 ; $i++) { for ($i=0; $i < $INTERVAL*6 ; $i++) {
sleep(10); sleep(10);
if (md5_file($config_file) != $MD5){syslog(LOG_INFO, "config file updated, reloading."); $i=10000;} if (md5_file($cfg_file) != $MD5){syslog(LOG_INFO, "config file updated, reloading."); $i=10000;}
} }
debug("Sleeped ".(time()-$time1)." seconds."); debug("Sleep ".(time()-$time1)." seconds.");
###### END OF SECTION ###### ###### END OF SECTION ######
};};?> };
};
?>