diff --git a/argon-status.py b/argon-status.py index 1c054cb..1417a0e 100755 --- a/argon-status.py +++ b/argon-status.py @@ -2,11 +2,13 @@ import sys import os +import subprocess import time import math sys.path.append( "/etc/argon/" ) from argonsysinfo import * - +from argonconfig import * +from version import * import argparse # @@ -174,6 +176,9 @@ def show_hddutilization(): printTable(lst, title = 'Storage Utilization:' ) # def show_all(): + """ + Display all options that we care about + """ show_storage() show_raid() show_hddTemperature() @@ -184,15 +189,24 @@ def show_all(): show_memory() def show_memory(): + """ + Display currnent memory utilization + """ memory = argonsysinfo_getram() printTable({"Total":memory[1],"Free":memory[0]},title="Memory:") # def print_version(): - print( 'Currently running version 2023.01.15-01') + """ + Display the version of we are currently running + """ + print( 'Currently running version: ' + ARGON_VERSION ) # def setup_arguments(): + """ + Setup all of the arguments that we recoginize. + """ parser = argparse.ArgumentParser() parser.add_argument( '-v', '--version', action='store_true', help='Display the version of the argon scripts.') parser.add_argument( '-a', '--all', action='store_true', help='Display full status of the Argon EON.') @@ -206,14 +220,64 @@ def setup_arguments(): parser.add_argument( '-t', '--temp', action='store_true', help='Display information about the current temperature.') parser.add_argument( '-u', '--hdduse', action='store_true', help='Display disk utilization.') parser.add_argument( '--hddtemp', action='store_true', help='Display the temperature of the storage devices.') + parser.add_argument( '--cooling', action='store_true', help='Display cooling information about the EON.') return parser -# +def show_config(): + """ + Create a table of the HDD and CPU temperatures, and then add in all of the marked fan + speeds for the given temps. We also highlight the thing that is forcing the current fanspeed. + """ + hddtemplst = loadHDDFanConfig() + cputemplst = loadCPUFanConfig() + + actualcpu = argonsysinfo_getcputemp() + actualhdd = argonsysinfo_getmaxhddtemp() + fanspeed = argonsysinfo_getCurrentFanSpeed() + keys = {} + hdd = {'Temperature':'HDD fanspeed'} + cpu = {'Temperature':'CPU fanspeed'} + for i in hddtemplst.keys(): + keys.__setitem__( i, '' ) + + for i in cputemplst.keys(): + keys.__setitem__( i, '' ) + + for i in sorted(keys.keys()): + if i in hddtemplst.keys(): + if float(actualhdd) >= float(i) and (int(hddtemplst[i]) == int(fanspeed)): + hdd.__setitem__( i, '<' + hddtemplst[i] + '>' ) + else: + hdd.__setitem__(i,hddtemplst[i] ) + else: + hdd.__setitem__( i, '' ) + if i in cputemplst.keys(): + if (float(actualcpu) >= float(i)) and (int(cputemplst[i]) == int(fanspeed)): + cpu.__setitem__( i, "<" + cputemplst[i] + ">" ) + else: + cpu.__setitem__( i, cputemplst[i] ) + else: + cpu.__setitem__( i, '' ) -start = time.clock_gettime_ns(time.CLOCK_MONOTONIC) -usage1= argonsysinfo_diskusage() + lst = [] + lst.append( hdd ) + lst.append( cpu ) + printTable( lst, title="Temperature Settings Table:" ) +# +def check_permission(): + """ + Determine if the user can properly execute the script. Must have sudo or be root + """ + if not ('SUDO_UID' in os.environ ) and os.geteuid() != 0: + return False + return True +# def main(): + """ + Process all command line options here. This is where we modify the default settings based on the evironment + variable AGON_STATUS_DEFAULT. If there are any flags that cannot be used together, filter them out here. + """ parser = setup_arguments() if len(sys.argv) > 1: args = parser.parse_args() @@ -249,7 +313,11 @@ def main(): show_hddutilization() if args.all: show_all() + if args.cooling: + show_cpuTemperature() + show_hddTemperature() + show_fanspeed() + show_config() if __name__ == "__main__": - setup_arguments() main() diff --git a/argoneon.sh b/argoneon.sh index 9f52e9a..7fd5ae5 100755 --- a/argoneon.sh +++ b/argoneon.sh @@ -122,6 +122,8 @@ sudo curl -L $ARGONDOWNLOADSERVER/argonconfig.py -o $INSTALLATIONFOLDER/argoncon sudo chmod 755 $INSTALLATIONFOLDER/argonconfig.py sudo curl -L $ARGONDOWNLOADSERVER/argonlogging.py -o $INSTALLATIONFOLDER/argonlogging.py --silent sudo chmod 755 $INSTALLATIONFOLDER/argonlogging.py +sudo curl -L $ARGONDOWNLOADSERVER/version.py -o $INSTALLATIONFOLDER/version.py --silent +sudo chmod 755 $INSTALLATIONFOLDER/version.py # RTC Setup basename="argoneon" diff --git a/argononed.py b/argononed.py index c4a7ccc..6436748 100755 --- a/argononed.py +++ b/argononed.py @@ -36,6 +36,7 @@ from argonsysinfo import * from argonlogging import * from argonconfig import * +from version import * # Initialize I2C Bus import smbus @@ -144,10 +145,9 @@ def setFanSpeed (overrideSpeed : int = None, instantaneous : bool = True): # Pause 30s before speed reduction to prevent fluctuations time.sleep(30) - # Make sure the value is in 0-100 range newspeed = max([min([100,newspeed]),0]) - if prevspeed != newspeed: + if overrideSpeed is not None or (prevspeed != newspeed): try: if newspeed > 0: # Spin up to prevent issues on older units @@ -157,10 +157,16 @@ def setFanSpeed (overrideSpeed : int = None, instantaneous : bool = True): logging.debug( "writing to fan port, speed " + str(newspeed)) argonsysinfo_recordCurrentFanSpeed( newspeed ) except IOError: + logError( "Error trying o update fan speed.") return prevspeed return newspeed def temp_check(): + """ + Main thread for processing the temperature check functonality. We just try and set the fan speed once + a minute. However we do want to start with the fan *OFF*. + """ + setFanOff() while True: setFanSpeed (instantaneous = False) time.sleep(60) @@ -242,6 +248,7 @@ def display_loop(readq): cpuusagelist = argonsysinfo_listcpuusage() curlist = cpuusagelist except: + logError( "Error processing information for CPU display") curlist = [] if len(curlist) > 0: oled_loadbg("bgcpu") @@ -271,6 +278,7 @@ def display_loop(readq): curlist.append({"title": curdev, "value": argonsysinfo_kbstr(tmpobj[curdev]['total']), "usage": int(tmpobj[curdev]['percent']) }) #curlist = argonsysinfo_liststoragetotal() except: + logError( "Error processing information for STORAGE display") curlist = [] if len(curlist) > 0: oled_loadbg("bgstorage") @@ -310,6 +318,7 @@ def display_loop(readq): timespan = (stoptime - prevTime)/1000000000 prevTime = stoptime except: + logError( "Error processing data for BANDWIDTH display") curlist = [] if len(curlist) > 0: @@ -343,6 +352,7 @@ def display_loop(readq): tmpobj = argonsysinfo_listraid() curlist = tmpobj['raidlist'] except: + logError( "Error processing display of RAID information.") curlist = [] if len(curlist) > 0: oled_loadbg("bgraid") @@ -385,6 +395,7 @@ def display_loop(readq): oled_writetextaligned(tmpraminfo[1], stdleftoffset, 40, oledscreenwidth-stdleftoffset, 1, fontwdReg) needsUpdate = True except: + logError( "Error processing information for RAM display") needsUpdate = False # Next page due to error/no data screenjogflag = 1 @@ -460,6 +471,7 @@ def display_loop(readq): needsUpdate = True except: + logError( "Error processing temerature information for TEMP display" ) needsUpdate = False # Next page due to error/no data screenjogflag = 1 @@ -469,6 +481,7 @@ def display_loop(readq): if len(curlist) == 0: curlist = argonsysinfo_getipList() except: + logError( "Error processing information for IP display") curlist = [] if len(curlist) > 0: @@ -508,6 +521,7 @@ def display_loop(readq): needsUpdate = True except: + logError( "Error processing information of TIME display" ) needsUpdate = False # Next page due to error/no data screenjogflag = 1 @@ -570,17 +584,21 @@ def display_defaultimg(): cmd = sys.argv[1].upper() if cmd == "SHUTDOWN": # Signal poweroff + logInfo( "SHUTDOWN requested via shutdown of command of argononed service") + setFanOff() bus.write_byte(ADDR_FAN,0xFF) - + elif cmd == "FANOFF": # Turn off fan setFanOff() + logInfo( "FANOFF requested via fanoff command of the argononed service") if OLED_ENABLED == True: display_defaultimg() elif cmd == "SERVICE": # Starts the power button and temperature monitor threads try: + logInfo( "argononed service version " + ARGON_VERSION + " starting.") ipcq = Queue() t1 = Thread(target = shutdown_check, args =(ipcq, )) @@ -597,5 +615,5 @@ def display_defaultimg(): GPIO.cleanup() elif cmd == "VERSION": - print( "Version: 2023.01.15") + print( "Version: " + ARGON_VERSION ) diff --git a/argonsysinfo.py b/argonsysinfo.py index b3cc14a..19dbc92 100755 --- a/argonsysinfo.py +++ b/argonsysinfo.py @@ -12,6 +12,14 @@ fanspeed = Path('/tmp/fanspeed.txt') +def checkPermission(): + """ + Determine if the user can properly execute the script. Must have sudo or be root + """ + if not ('SUDO_UID' in os.environ ) and os.geteuid() != 0: + return False + return True + # def argonsysinfo_getCurrentFanSpeed(): """ Get the current fanspeed of the system, by reading a file we have stored the speed in. @@ -189,6 +197,8 @@ def argonsysinfo_gethddtemp(): if curdev[0:2] == "sd" or curdev[0:2] == "hd": # command = os.popen(hddtempcmd+" -d sat -A /dev/"+curdev+" | grep 194 | awk '{print $10}' 2>&1") def getSmart(smartCmd): + if not checkPermission() and not smartCmd.startswith("sudo"): + smartCmd = "sudo " + smartCmd try: command = os.popen(smartCmd) smartctlOutRaw = command.read() @@ -196,8 +206,6 @@ def getSmart(smartCmd): print (e) finally: command.close() - if 'Permission denied' in smartctlOutRaw and not smartCmd.startswith('sudo'): - return getSmart(f"sudo {smartCmd}") if 'scsi error unsupported scsi opcode' in smartctlOutRaw: return None @@ -416,7 +424,10 @@ def argonsysinfo_getraiddetail(devname): spare = 0 resync = "" hddlist =[] - command = os.popen('mdadm -D /dev/'+devname) + if not checkPermission(): + command = os.popen('sudo mdadm -D /dev/'+devname) + else: + command = os.popen('mdadm -D /dev/'+devname) tmp = command.read() command.close() alllines = tmp.split("\n") diff --git a/version.py b/version.py new file mode 100644 index 0000000..0b8c522 --- /dev/null +++ b/version.py @@ -0,0 +1,6 @@ +# +# Version number +# + +ARGON_VERSION = "2023.01.16" +