def writePidToFile(pidfile): if path.isfile(pidfile): info(pidfile + " already exists, exiting") with open(pidfile, 'r') as file: pid = int(file.read()) if ProcessInfo.IsRunning(pid) and pid != getpid(): Daemon.Exit() return pid = str(getpid()) with open(pidfile, 'w') as file: file.write(pid)
def CheckSubscription(self): inviteCode = self.config.get('Agent', 'InviteCode') cayenneApiClient = CayenneApiClient(self.CayenneApiHost) authId = cayenneApiClient.loginDevice(inviteCode) if authId == None: error( 'Registration failed for invite code {}, closing the process'. format(inviteCode)) Daemon.Exit() else: info('Registration succeeded for invite code {}, auth id = {}'. format(inviteCode, authId)) self.config.set('Agent', 'Initialized', 'true') self.MachineId = authId