with open('lock.pid', 'w') as lockfile: os.chmod("/etc/homeremote/lock.pid", 0666) lockfile.write(str(os.getpid())) lockfile.close() import RPi.GPIO as GPIO from mcp import MCP230XX_GPIO as mcp import tornado.websocket import tornado.ioloop import tornado.web import tornado.template import gui import signal import thread from remotehome import clients, event, events, inputs, outputs, gpio, security, cur, con, sensors, sensors_index, nogui, temp_sensors, light_sensors security = security() daemonize = False for i in sys.argv: if i == "-nogui": nogui = True if i == "-D": daemonize = True nogui = True if not nogui: gui.start() if daemonize: gui.no_output = True if __name__ == "__main__": # Get pins and set them up
if globals.inputs[i].idling: globals.inputs[i].stop_input_idle() try: sensors.temp_process.terminate() except AttributeError: pass sensors.run_sensor_refresh = False GPIO.cleanup() if not globals.nogui: gui.end() os.remove('/etc/homeremote/lock.pid') sys.exit(0) if __name__ == "__main__": globals.init_globals() globals.security = security() globals.sensors = sensors() daemonize = False for i in sys.argv: if i == "-nogui": globals.nogui = True if i == "-D": daemonize = True globals.nogui = True if not globals.nogui: gui.start() if daemonize: gui.no_output = True