def Check(): # Write check command in history sslib.Inhistory("Routine check") # Read the usrlist usrlist = sslib.GetUsrList() # Get now time to check nowdate = sslib.nowdate() for usrname in usrlist: # change 'dict' to 'MyUsr' usr = sslib.MyUsr(usrlist[usrname]) # Check the usr Result = usr.check() print Result if Result == "turnon": # Write the result in history sslib.Inhistory("Turn on " + usrname + "'s service") TurnOn(usrlist[usrname]) if Result == "turnoff": # Write the result in history sslib.Inhistory("Turn off " + usrname + "'s service") TurnOff(usrlist[usrname]) # Write check command in history sslib.Inhistory("End check")
def Stop(): # Write stop command in history sslib.Inhistory("Command: " + "Stop") # First, turn off all shadowsocks service process usrlist = sslib.GetUsrList() nowdate = sslib.nowdate() for usrname in usrlist: usr = sslib.MyUsr(usrlist[usrname]) if usr.offline(): sslib.Inhistory("Turn off " + usrname + "'s service") TurnOff(usrlist[usrname]) sslib.Success("Kill all service") # Second, turn off the Start() service process # To get pidpos try: ssetc = sslib.GetEtc() piddir = ssetc["piddir"] except: piddir = "/tmp" pidpos = os.path.join(piddir, "ssrun.pid") if os.path.exists(pidpos): f = open(pidpos, "r") txt = f.read().split("\n") f.close() for i in txt: if len(i) > 0: # print i (status, output) = commands.getstatusoutput("kill " + i) if status == 0: sslib.Inhistory("Kill " + i) # print output # After kill the process,remember to remove 'ssrun.pid' os.remove(pidpos) sslib.Success("Stop") else: # No such file sslib.Error(2, "No such file")