Example #1
0
def plexconnect_control(control):
    global controlsupport
    if control == "install" or control == "uninstall" or control == "remove":
        if sys.platform.startswith('darwin'): #OSX specific
            command = Popen("./support/OSX/"+control+".bash", shell=True, stderr=PIPE,stdout=PIPE).communicate()[0] 
            time.sleep(2) # actions may still be in progress  
        else:
            if sys.platform.startswith('win32') and control == "remove":
                call(plexconnectpath+"stop", shell=True)
                time.sleep(3)
                call(plexconnectpath+control, shell=True)
                print("win "+plexconnectpath+":"+control)
 
            else:
                call(plexconnectpath+control, shell=True)
    else:
        if os.name == "posix": # OSX / Linux flavors
            command = Popen(plexconnectpath+control, shell=True, stderr=PIPE,stdout=PIPE).communicate()[0] 
        else: # win 32
            if controlsupport == False and control == "stop":
                cmdShutdown()
                shutdown()
                time.sleep(2)
                command = Popen("taskkill /FI \"IMAGENAME eq pythonw.exe\" /F", shell=True, stderr=PIPE,stdout=PIPE).communicate()[0] 
                call("echo PlexConnect is not running > plexconnect_status.txt",shell=True)
            if controlsupport == False and control == "start":
                    
                proc = Popen(["start.bat"],shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                time.sleep(2)
                call("echo PlexConnect is running > plexconnect_status.txt",shell=True)

            if controlsupport == True and control == "start":
                output = Popen("sc query PlexConnect-service", shell=True, stdout=PIPE).communicate()[0]

                if output.find("FAILED") > 0:
                    command = Popen(plexconnectpath+" install", shell=True, stderr=PIPE,stdout=PIPE).communicate()[0]  
                    time.sleep(3)
                    command = Popen(plexconnectpath+control, shell=True, stderr=PIPE,stdout=PIPE).communicate()[0] 
                    time.sleep(3)
                else:
                    command = Popen(plexconnectpath+control, shell=True, stderr=PIPE,stdout=PIPE).communicate()[0]
            else:
                    command = Popen(plexconnectpath+control, shell=True, stderr=PIPE,stdout=PIPE).communicate()[0]
                    call("echo PlexConnect is not running > plexconnect_status.txt",shell=True)

   
    time.sleep(2)
    set_platform() # update all proper programfile & paths        
    time.sleep(2)    
    plexconnect_status(localIP)
Example #2
0
def plexconnect_control(control):
    global controlsupport
    if control == "install" or control == "uninstall" or control == "remove":
        if sys.platform.startswith('darwin'): #OSX specific
            command = Popen("./support/OSX/"+control+".bash", shell=True, stderr=PIPE,stdout=PIPE).communicate()[0] 
            time.sleep(2) # actions may still be in progress  
        else:
            if sys.platform.startswith('win32') and control == "remove":
                call(plexconnectpath+"stop", shell=True)
                time.sleep(3)
                call(plexconnectpath+control, shell=True)
                print("win "+plexconnectpath+":"+control)
 
            else:
                call(plexconnectpath+control, shell=True)
    else:
        if os.name == "posix": # OSX / Linux flavors
            command = Popen(plexconnectpath+control, shell=True, stderr=PIPE,stdout=PIPE).communicate()[0] 
        else: # win 32
            if controlsupport == False and control == "stop":
                cmdShutdown()
                shutdown()
                time.sleep(2)
                command = Popen("taskkill /FI \"IMAGENAME eq pythonw.exe\" /F", shell=True, stderr=PIPE,stdout=PIPE).communicate()[0] 
                call("echo PlexConnect is not running > plexconnect_status.txt",shell=True)
            if controlsupport == False and control == "start":
                    
                proc = Popen(["start.bat"],shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                time.sleep(2)
                call("echo PlexConnect is running > plexconnect_status.txt",shell=True)

            if controlsupport == True and control == "start":
                output = Popen("sc query PlexConnect-service", shell=True, stdout=PIPE).communicate()[0]

                if output.find("FAILED") > 0:
                    command = Popen(plexconnectpath+" install", shell=True, stderr=PIPE,stdout=PIPE).communicate()[0]  
                    time.sleep(3)
                    command = Popen(plexconnectpath+control, shell=True, stderr=PIPE,stdout=PIPE).communicate()[0] 
                    time.sleep(3)
                else:
                    command = Popen(plexconnectpath+control, shell=True, stderr=PIPE,stdout=PIPE).communicate()[0]
            else:
                    command = Popen(plexconnectpath+control, shell=True, stderr=PIPE,stdout=PIPE).communicate()[0]
                    call("echo PlexConnect is not running > plexconnect_status.txt",shell=True)

   
    time.sleep(2)
    set_platform() # update all proper programfile & paths        
    time.sleep(2)    
    plexconnect_status(localIP)
Example #3
0
            raise SystemExit("Unable to write PID file: %s [%d]" %
                             (e.strerror, e.errno))


def delpid():
    global args
    os.remove(args.pidfile)


def sighandler_shutdown(signum, frame):
    signal.signal(signal.SIGINT, signal.SIG_IGN)  # we heard you!
    cmdShutdown()


if __name__ == '__main__':
    signal.signal(signal.SIGINT, sighandler_shutdown)
    signal.signal(signal.SIGTERM, sighandler_shutdown)

    parser = argparse.ArgumentParser(description='PlexConnect as daemon.')
    parser.add_argument('--pidfile', dest='pidfile')
    args = parser.parse_args()

    daemonize(args)

    running = startup()

    while running:
        running = run()

    shutdown()
        except IOError, e:
            raise SystemExit("Unable to write PID file: %s [%d]" % (e.strerror, e.errno))


def delpid():
    global args
    os.remove(args.pidfile)


def sighandler_shutdown(signum, frame):
    signal.signal(signal.SIGINT, signal.SIG_IGN)  # we heard you!
    cmdShutdown()


if __name__ == "__main__":
    signal.signal(signal.SIGINT, sighandler_shutdown)
    signal.signal(signal.SIGTERM, sighandler_shutdown)

    parser = argparse.ArgumentParser(description="PlexConnect as daemon.")
    parser.add_argument("--pidfile", dest="pidfile")
    args = parser.parse_args()

    daemonize(args)

    success = startup()

    if success:
        run()

        shutdown()