diff options
-rw-r--r-- | monitor_unified.py | 37 |
1 files changed, 1 insertions, 36 deletions
diff --git a/monitor_unified.py b/monitor_unified.py index e1400dc..c61ab3e 100644 --- a/monitor_unified.py +++ b/monitor_unified.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python # -*- coding: utf-8 -*- __author__ = "Franek Ćazarewicz-Muradyan" @@ -492,41 +492,6 @@ class Rain(Sensor): # GPIO.add_event_detect(self.pin, GPIO.FALLING, callback=self.read(), # bouncetime=300) -def clean_exit(sig,frame): - #do some other cleanup if you want - os.remove('/var/run/user/1000RPGH_starter.pid') - os.exit(0) - -def start(): - signal.signal(signal.SIGTERM, clean_exit)#from start-stop-daemon - signal.signal(signal.SIGINT, clean_exit)#from ctrl-c - with open('/var/run/user/1000/RPGH_starter.pid', 'x') as pid_file: - pid_file.write(str(os.getpid())) - do_main_loop() - -def main(): - try: action=sys.argv[1] - except IndexError: action='stop' - if action=='start': - start() - elif action=='start_fork': - if os.fork():sys.exit(0) - start() - elif action=='stop': - with open('/var/run/user/1000/RPGH_starter.pid', 'r') as pid_file: - pid=int(pid_file.read()) - os.kill(pid,signal.SIGTERM) - - #optional clean up - try: - child=psutil.Process(pid) - except FileNotFoundError:#psutil didn't find the pid dir in /proc - sys.exit() - try: - child.wait(timeout=10) - except psutil.TimeoutExpired:#we didn't exit/clean up in time - child.kill() - os.remove('/var/run/user/1000/RPGH_starter.pid') if __name__ == '__main__': fq = cfg.getint('hardware_settings', 'read_frequency') |