Commit 5c39c2aa authored by Mikhail Karpenko's avatar Mikhail Karpenko

Install tempmon to /usr/bin and update its init script

parent f7dc5d36
#!/bin/sh #!/bin/sh
DEAMON=/usr/bin/init_tempmon.py
PATH=/sbin:/bin:/usr/sbin:/usr/bin PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/init_tempmon
NAME=init_tempmon NAME=init_tempmon
DESC="temperature monitor daemon" DESC="temperature monitor daemon"
SCRIPT_NAME=init_tempmon.py
MNTPOINT=/mnt/mmc # PID file name, must match to the name in init_tempmon.py sript
MMCDEV=/dev/mmcblk0p1 PID_FILE=/var/run/init_tempmon.pid
SOME_SCRIPT=init_tempmon.py
. /etc/init.d/functions
test -x $DEAMON || exit 0
case "$1" in case "$1" in
start) start)
if [ ! -f $PID_FILE ]; then
echo -n "Starting $DESC: " echo -n "Starting $DESC: "
if [ -f $MNTPOINT/$SOME_SCRIPT ]; then echo $SCRIPT_NAME
echo " Launching $SOME_SCRIPT" $DEAMON &
$MNTPOINT/$SOME_SCRIPT
else else
echo " $SOME_SCRIPT not found. Nothing to launch." echo "Already running"
fi fi
;; ;;
stop) stop)
if [ -f $PID_FILE ]; then
echo -n "Stopping $DESC: " echo -n "Stopping $DESC: "
echo "$NAME." echo "$NAME"
pid=$(cat $PID_FILE)
/bin/kill $pid
rm $PID_FILE
else
echo "Not running, nothing to stop"
fi
;; ;;
restart) restart)
if [ -f $PID_FILE ]; then
echo -n "Restarting $DESC: " echo -n "Restarting $DESC: "
echo "$NAME." echo "$NAME"
pid=$(cat $PID_FILE)
/bin/kill $pid
$DEAMON &
else
echo "Not running, nothing to restart"
fi
;; ;;
status) status)
echo -n "$NAME status:" echo -n "$NAME status: "
if [ -f /var/run/$NAME ]; then if [ -f $PID_FILE ]; then
echo -n "Running" echo "Running"
else else
echo -n "Not running" echo "Not running"
fi fi
;; ;;
*) *)
......
...@@ -26,6 +26,7 @@ import os ...@@ -26,6 +26,7 @@ import os
import sys import sys
import time import time
import subprocess import subprocess
import atexit
from posix import EX_OSFILE, F_OK from posix import EX_OSFILE, F_OK
DEBUG = 0 DEBUG = 0
...@@ -40,6 +41,8 @@ TEMP_HYSTERESIS = 2.0 ...@@ -40,6 +41,8 @@ TEMP_HYSTERESIS = 2.0
SAMPLING_TIME = 1 SAMPLING_TIME = 1
""" Temperature scaling factor. """ """ Temperature scaling factor. """
SCALE_CFT = 0.001 SCALE_CFT = 0.001
""" The name of the file in /var/run which will contain PID """
PID_NAME = "init_tempmon"
ctrl_path_pref = "/sys/devices/soc0/elphel393-pwr@0/" ctrl_path_pref = "/sys/devices/soc0/elphel393-pwr@0/"
ctrl_fn = {"poweroff_fn": "power_off", ctrl_fn = {"poweroff_fn": "power_off",
...@@ -51,7 +54,8 @@ hwmon_fn = {"offset": "in_temp0_offset", ...@@ -51,7 +54,8 @@ hwmon_fn = {"offset": "in_temp0_offset",
"raw": "in_temp0_raw", "raw": "in_temp0_raw",
"scale": "in_temp0_scale"} "scale": "in_temp0_scale"}
out_path_pref = "/var/volatile/tmp/" out_path_pref = "/var/volatile/tmp/"
out_fn = {"core_temp_fn": "core_temp"} out_fn = {"core_temp_fn": "core_temp",
"temp_params_fn": "core_temp_params"}
class temp_monitor(): class temp_monitor():
def __init__(self, ctrl_path_pref, ctrl_file_names, hwmon_path_pref, hwmon_fn, def __init__(self, ctrl_path_pref, ctrl_file_names, hwmon_path_pref, hwmon_fn,
...@@ -63,16 +67,35 @@ class temp_monitor(): ...@@ -63,16 +67,35 @@ class temp_monitor():
self.hwmon_path_prefix = hwmon_path_pref self.hwmon_path_prefix = hwmon_path_pref
self.hwmon_fnames = hwmon_fn self.hwmon_fnames = hwmon_fn
self.samples_window = [] self.samples_window = []
self.pid_fname = "/var/run/" + PID_NAME + ".pid"
""" Number of samples for temperature averaging """ """ Number of samples for temperature averaging """
self.samples_num = 5 self.samples_num = 5
self.fan_cmd = {"fan_cmd_on": "0x101", self.fan_cmd = {"fan_cmd_on": "0x101",
"fan_cmd_off": "0x100"} "fan_cmd_off": "0x100"}
self.params = {"temp_minor": TEMP_FAN_ON,
"temp_major": TEMP_SHUTDOWN,
"temp_hyst": TEMP_HYSTERESIS,
"temp_sampling_time": SAMPLING_TIME}
""" Create output files """ """ Create output files """
try: try:
self.core_temp_out_f = open(out_path_prefix + out_fnames["core_temp_fn"], "w") self.core_temp_out_f = open(out_path_prefix + out_fnames["core_temp_fn"], "w")
except IOError: except IOError:
print "Failed to create file: '%s%s'" % (out_path_prefix, out_fnames["core_temp_fn"]) print "Failed to create file: '%s%s'" % (out_path_prefix, out_fnames["core_temp_fn"])
try:
self.core_temp_params_f = open(out_path_prefix + out_fnames["temp_params_fn"], "w")
except IOError:
self.core_temp_out_f.close()
print "Failed to create file: '%s%s'" % (out_path_prefix, out_fnames["temp_params_fn"])
""" Create pid file """
with open(self.pid_fname, "w") as pid_file:
pid_file.write(str(os.getpid()))
atexit.register(self.delpid)
def delpid(self):
if os.access(self.pid_fname, F_OK):
os.remove(self.pid_fname)
def check_files(self): def check_files(self):
""" """
...@@ -141,23 +164,37 @@ class temp_monitor(): ...@@ -141,23 +164,37 @@ class temp_monitor():
samples.sort() samples.sort()
avg = samples[len(samples) / 2] avg = samples[len(samples) / 2]
if core_temp < (TEMP_FAN_ON - TEMP_HYSTERESIS) and self.is_fan_on: if core_temp < (self.params["temp_minor"] - self.params["temp_hyst"]) and self.is_fan_on:
self.fan_ctrl("off") self.fan_ctrl("off")
elif core_temp >= TEMP_FAN_ON and core_temp < TEMP_SHUTDOWN and not self.is_fan_on: elif core_temp >= self.params["temp_minor"] and core_temp < self.params["temp_major"] and not self.is_fan_on:
self.fan_ctrl("on") self.fan_ctrl("on")
elif avg >= TEMP_SHUTDOWN: elif avg >= self.params["temp_major"]:
self.shutdown() self.shutdown()
self.core_temp_out_f.seek(0) self.core_temp_out_f.seek(0)
self.core_temp_out_f.write(str(core_temp)) self.core_temp_out_f.write(str(core_temp))
self.core_temp_out_f.flush() self.core_temp_out_f.flush()
print "Core temperature: '%f', median: '%f'" % (core_temp, avg) # print "Core temperature: '%f', median: '%f'" % (core_temp, avg)
time.sleep(SAMPLING_TIME) time.sleep(self.params["temp_sampling_time"])
except (KeyboardInterrupt, SystemExit): except (KeyboardInterrupt, SystemExit):
print "Got keyboard interrupt. Exiting." self.core_temp_out_f.close()
self.core_temp_params_f.close()
os.remove(self.pid_fname)
print "'%s': got keyboard interrupt. Exiting." % os.path.basename(__file__)
sys.exit(0) sys.exit(0)
def read_temp_params(self):
"""
Read parameters from file and update local values.
"""
for key, val in self.params.items():
self.core_temp_params_f.seek(0)
file_lines = self.core_temp_params_f.readlines()
for line in file_lines:
if line.find(key) == 0:
self.core_temp_params_f[key] = float(line.split(":")[1].strip())
if __name__ == "__main__": if __name__ == "__main__":
if DEBUG: if DEBUG:
ctrl_path_pref = "" ctrl_path_pref = ""
......
...@@ -21,7 +21,7 @@ SRC_URI = "file://init_tempmon \ ...@@ -21,7 +21,7 @@ SRC_URI = "file://init_tempmon \
S = "${WORKDIR}/" S = "${WORKDIR}/"
INITSCRIPT_NAME = "init_tempmon" INITSCRIPT_NAME = "init_tempmon"
INITSCRIPT_PARAMS = "defaults 96" INITSCRIPT_PARAMS = "defaults 94"
RDEPENDS_${PN} += "python-core" RDEPENDS_${PN} += "python-core"
...@@ -29,6 +29,7 @@ FILES_${PN} = "\ ...@@ -29,6 +29,7 @@ FILES_${PN} = "\
/etc/* \ /etc/* \
/usr/* \ /usr/* \
" "
PACKAGES = " init-tempmon"
#This needs to get the script into rc?.d/ #This needs to get the script into rc?.d/
inherit update-rc.d inherit update-rc.d
...@@ -36,20 +37,6 @@ inherit update-rc.d ...@@ -36,20 +37,6 @@ inherit update-rc.d
do_install_append() { do_install_append() {
install -d ${D}${sysconfdir}/init.d install -d ${D}${sysconfdir}/init.d
install -m 0755 ${WORKDIR}/init_tempmon ${D}${sysconfdir}/init.d install -m 0755 ${WORKDIR}/init_tempmon ${D}${sysconfdir}/init.d
install -d ${D}${bindir}
for RLOC in ${PRODUCTION_ROOT_LOCATION}; do install -m 0755 ${S}/init_tempmon.py ${D}${bindir}
if [ ! -d ${DEPLOY_DIR_IMAGE}/${RLOC} ]; then
mkdir -p ${DEPLOY_DIR_IMAGE}/${RLOC}
fi
if [ -f ${S}init_tempmon.py ]; then
if [ -f ${DEPLOY_DIR_IMAGE}/${RLOC}/init_tempmon.py ]; then
rm ${DEPLOY_DIR_IMAGE}/${RLOC}/init_tempmon.py
fi
cp ${S}init_tempmon.py ${DEPLOY_DIR_IMAGE}/${RLOC}/init_tempmon.py
else
echo "NOT 3 FOUND!"
fi
done
} }
PACKAGES = " init-tempmon"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment