#!/usr/bin/env python import os import sys import signal import time from socket import gethostname from subprocess import Popen,PIPE debug=0 class daemon: def __init__(self): self.pid_filename='/var/run/nvtempd.pid' self.modes={0:'Auto',1:'Manual'} self.default_mode=0 ################### Editable bits ################# self.max_fan_speed=80 #hard coded maximum by nvidia YMMV (in%) self.min_fan_speed=30 #hard coded minimum by nvidia YMMV (in%) self.go_auto_temp=40 #below this temperature we let the card take care of itself self.fans=[0,1,2] #self.fans=[0,1,2,3] #add more if you have more self.exe='/usr/bin/nvidia-settings' self.ENV={'DISPLAY':':0'} self.gpu=0 ################### End Editable bits ############# self.match="(%s%s[gpu:%s])"%(gethostname(),self.ENV['DISPLAY'],self.gpu) self.firstrun=1 self.curve={} x=0 while x <= 120: #GPUCoreTemp only reposts to the nearest degree C, no point running the curve every time, cheaper to make a dictionary of temp vs fan speed. #self.curve.update({x:(((x- a )/ b )** c + d) alter a &| b to move the curve left/right , c to set the steepness of the change, can be visualized in kmplot with y=(((x-15)/25.7)^5)+30 self.curve.update({x:(((x-15)/25.7)**5)+30}) # if self.curve[x]>self.max_fan_speed:self.curve.update({x:self.max_fan_speed}) if self.curve[x]/dev/null 2>&1'%(sys.argv[0].replace('/','\\/'))) sys.exit(0) def stop(self): pid=0 try: pid=self.read_file(self.pid_filename) os.remove(self.pid_filename) except: self.force_stop(pid) os.system('/bin/kill -SIGUSR1 %s'%pid) timer=60 while timer > 0 and not os.system('ps -A|grep -qw "%s"'%pid): time.sleep(0.1) timer-=1 if not os.system('ps -A|grep -q "%s"'%pid):self.force_stop(pid) sys.exit(0) def status(self): signal.signal(signal.SIGINT,self.simple_exit) try: interval=sys.argv[2] except:interval=0 run=True while run: if os.system('ps aux|grep -v grep 2>/dev/null|grep -q "python %s start"'%sys.argv[0]): isRunning='Not running' else: isRunning='Yes, PID:%s'%self.read_file(self.pid_filename) temp=self.get_gpu_temp(self.gpu) self.get_mode() print('#####################################') print(' Running : %s'%isRunning) print(' Temp : %s°C'%temp) for fan in self.fans: print(' Fan %s Set to : %s%%'%(fan,self.get_fan_speed(fan))) print(' Fan %s Current RPM : %s'%(fan,self.get_rpm(fan))) print(' Current Mode : %s'%self.current_mode) print('#####################################') time.sleep(int(interval)) run=interval def usage(): print('Usage: %s '%sys.argv[0][sys.argv[0].rfind('/')+1:]) try: action=sys.argv[1] if action == 'start': main=daemon() if debug: main.start() sys.exit() fork_ret=os.fork() if fork_ret == 0: main.start() else: sys.exit(0) elif action == 'stop': main=daemon() main.stop() elif action == 'status': main=daemon() main.status() else: usage() except IndexError: usage() #endtry