def start_tornado(): for port in PORTS: s = Screen(TORNADO_SCREEN.format(port=port)) if s.exists is False: s.initialize() s.send_commands('python main.py --port={port}'.format(port=port)) info('Starting tornado instance(s) in port(s) {ports}'.format(ports=dumps(PORTS)))
def start(self): steam_appid = self.gsconfig["steamcmd"]["appid"] srcds_launch = ( "-game {game} " "-console -usercon " "-fork {fork} " "-secure -autoupdate " "-steam_dir {steam_dir} " "-steamcmd_script {runscript} " "-maxplayers {maxplayers} " "+port {port} " "+ip {ip} " "+map {map}".format( game=GAME[steam_appid], fork=self.gsconfig[steam_appid]["fork"], steam_dir=self.path["steamcmd"], runscript="runscript.txt", maxplayers=self.gsconfig[steam_appid]["maxplayers"], port=self.gsconfig[steam_appid]["port"], ip=self.gsconfig[steam_appid]["ip"], map=self.gsconfig[steam_appid]["map"], ) ) extra_parameters = "" srcds_run = "{path}/srcds_run {launch} {extra}".format( path=self.path["game"], launch=srcds_launch, extra=extra_parameters ) s = Screen(steam_appid, True) s.send_commands(srcds_run)
def start(self): steam_appid = self.gsconfig['steamcmd']['appid'] srcds_launch = '-game {game} ' \ '-console -usercon -secure -autoupdate ' \ '-steam_dir {steam_dir} ' \ '-steamcmd_script {runscript} ' \ '-maxplayers {maxplayers} ' \ '+port {port} ' \ '+ip {ip} ' \ '+map {map} ' \ '+servercfgfile servercustom.cfg ' \ '+sv_setsteamaccount {steamaccount}' \ .format(game=GAME[steam_appid], steam_dir=self.path['steamcmd'], runscript='runscript.txt', maxplayers=self.gsconfig[steam_appid]['maxplayers'], port=self.gsconfig[steam_appid]['port'], ip=self.gsconfig[steam_appid]['ip'], map=self.gsconfig[steam_appid]['map'], steamaccount=self.gsconfig[steam_appid]['sv_setsteamaccount'] ) extra_parameters = '' srcds_run = '{path}/srcds_run {launch} {extra}' \ .format(path=self.path['game'], launch=srcds_launch, extra=extra_parameters ) s = Screen(steam_appid, True) s.send_commands(srcds_run)
def clock_loop(): screen = Screen(screenName) count = 0 while True: if screen.exists: if autoSave: #If time for an auto save... if count == saveX: #Send the save-all command to the Minecraft server... print("Autosaving...") screen.send_commands("save-all") #Reset the counter... count=0 else: #Increse the counter by one count += 1 if autoRestart: timenow = datetime.datetime.now() if timenow.strftime('%H:%M') == restartTime: screen.send_commands("say Server restarting in five seconds...") screen.send_commands("save-all") time.sleep(5) screen.send_commands("kick @a Server restarting... come back in 45 seconds...") screen.send_commands("stop") count = 0 time.sleep(60) time.sleep(1)
def main(): FolderCMD = os.getcwd() # Getting parser args, parser = get_parser() # Create screen session for Master MasterShell = Screen("Master", True) #MasterShell.enable_logs() MasterShell.send_commands('cd ' + FolderCMD + ' ; python Master.py -j ' + str(args.threads) + ' -input ' + args.basicinput + ' -energies ' + str(args.Elist[0]) + " " + str(args.Elist[1]) + " " + str(args.Elist[2])) # Create screen sessions for Slaves SlaveShell = [] for j in range(args.threads): name = 'Slave' + str(j + 1) SlaveShell.append(Screen(name, True)) #SlaveShell[j].enable_logs() SlaveShell[j].send_commands('cd ' + FolderCMD + ' ; python Slave.py -id ' + name) os.system('screen -r Master')
def screen_manager(screen_name, command): print 'Enter screen_manager,screen_name:%s,command:%s.' % (screen_name, command) s = Screen(screen_name, True) s.enable_logs() s.send_commands(command) print next(s.logs) print 'Exit screen_manager,screen_name:%s.' % screen_name
def start(self): steam_appid = self.gsconfig['steamcmd']['appid'] # Steamapi key provided, check for workshop content if self.gsconfig['steamcmd']['steamapi'] != 'ignore' and self.gsconfig[ steam_appid]['workshop'] != 'ignore': srcds_launch = '-game {game} ' \ '-console -usercon -secure -autoupdate '\ '-steam_dir {steam_dir} ' \ '-steamcmd_script {runscript} '\ '-maxplayers {maxplayers} '\ '+port {port} '\ '+ip {ip} ' \ '+map {map} ' \ '+gamemode {gamemode} ' \ '+host_workshop_collection {workshop} ' \ '-authkey {authkey}' \ .format(game=GAME[steam_appid], steam_dir=self.path['steamcmd'], runscript='runscript.txt', maxplayers=self.gsconfig[steam_appid]['maxplayers'], port=self.gsconfig[steam_appid]['port'], ip=self.gsconfig[steam_appid]['ip'], map=self.gsconfig[steam_appid]['map'], workshop=self.gsconfig[steam_appid]['workshop'], gamemode=self.gsconfig[steam_appid]['gamemode'], authkey=self.gsconfig['steamcmd']['steamapi'], ) extra_parameters = '' else: srcds_launch = '-game {game} ' \ '-console -usercon -secure -autoupdate ' \ '-steam_dir {steam_dir} ' \ '-steamcmd_script {runscript} ' \ '-maxplayers {maxplayers} ' \ '+port {port} ' \ '+ip {ip} ' \ '+map {map} ' \ .format(game=GAME[steam_appid], steam_dir=self.path['steamcmd'], runscript='runscript.txt', maxplayers=self.gsconfig[steam_appid]['maxplayers'], port=self.gsconfig[steam_appid]['port'], ip=self.gsconfig[steam_appid]['ip'], map=self.gsconfig[steam_appid]['map'], ) extra_parameters = '' srcds_run = '{path}/srcds_run {launch} {extra}' \ .format(path=self.path['game'], launch=srcds_launch, extra=extra_parameters ) s = Screen(steam_appid, True) s.send_commands(srcds_run)
def start(self): steam_appid = self.gsconfig['steamcmd']['appid'] # Steamapi key provided, check for workshop content if self.gsconfig['steamcmd']['steamapi'] != 'ignore' and self.gsconfig[steam_appid]['workshop'] != 'ignore': srcds_launch = '-game {game} ' \ '-console -usercon -secure -autoupdate '\ '-steam_dir {steam_dir} ' \ '-steamcmd_script {runscript} '\ '-maxplayers {maxplayers} '\ '+port {port} '\ '+ip {ip} ' \ '+map {map} ' \ '+gamemode {gamemode} ' \ '+host_workshop_collection {workshop} ' \ '-authkey {authkey}' \ .format(game=GAME[steam_appid], steam_dir=self.path['steamcmd'], runscript='runscript.txt', maxplayers=self.gsconfig[steam_appid]['maxplayers'], port=self.gsconfig[steam_appid]['port'], ip=self.gsconfig[steam_appid]['ip'], map=self.gsconfig[steam_appid]['map'], workshop=self.gsconfig[steam_appid]['workshop'], gamemode=self.gsconfig[steam_appid]['gamemode'], authkey=self.gsconfig['steamcmd']['steamapi'], ) extra_parameters = '' else: srcds_launch = '-game {game} ' \ '-console -usercon -secure -autoupdate ' \ '-steam_dir {steam_dir} ' \ '-steamcmd_script {runscript} ' \ '-maxplayers {maxplayers} ' \ '+port {port} ' \ '+ip {ip} ' \ '+map {map} ' \ .format(game=GAME[steam_appid], steam_dir=self.path['steamcmd'], runscript='runscript.txt', maxplayers=self.gsconfig[steam_appid]['maxplayers'], port=self.gsconfig[steam_appid]['port'], ip=self.gsconfig[steam_appid]['ip'], map=self.gsconfig[steam_appid]['map'], ) extra_parameters = '' srcds_run = '{path}/srcds_run {launch} {extra}' \ .format(path=self.path['game'], launch=srcds_launch, extra=extra_parameters ) s = Screen(steam_appid, True) s.send_commands(srcds_run)
def launch_cmd(screen, s=None): if s is None: s = Screen(screen["name"], True) s.enable_logs() s.send_commands("cd %s" % screen["dir"]) s.send_commands(screen["shell_cmd"]) s.detach() info("Screen %s restarted" % screen["name"]) if "request" in screen and screen["request"]: restarted = check_screen(screen) print(next(s.logs)) s.disable_logs()
def screen_manager(screen_name, command): print 'Enter screen_manager,screen_name:%s,command:%s.' % (screen_name, command) s = Screen(screen_name) if not s.exists: print '[Error]Screen:%s is not exists!' % screen_name return s.enable_logs() if command is not None: s.send_commands(command) time.sleep(2) print next(s.logs) s.disable_logs() print 'Exit screen_manager,screen_name:%s,command:%s.' % (screen_name, command)
def start(self): steam_appid = self.gsconfig['steamcmd']['appid'] if self.gsconfig[steam_appid]['serverpassword'] != 'ignore': run_commands = '{gamedir}/ShooterGame/Binaries/Linux/ShooterGameServer ' \ 'TheIsland?Listen?SessionName={hostname}?ServerPassword={serverpassword}' \ '?ServerAdminPassword={serveradminpassowrd}' \ .format(gamedir=self.path['gamedir'], hostname=self.gsconfig[steam_appid]['hostname'], ServerPassowrd=self.gsconfig[steam_appid]['serverpassword'], serveradminpassword=self.gsconfig[steam_appid]['serveradminpassword'] ) else: run_commands = '{gamedir}/ShooterGame/Binaries/Linux/ShooterGameServer ' \ 'TheIsland?Listen?SessionName={hostname}?ServerAdminPassword={serveradminpassowrd}' \ .format(gamedir=self.path['gamedir'], hostname=self.gsconfig[steam_appid]['hostname'], serveradminpassowrd=self.gsconfig[steam_appid]['serveradminpassword'] ) s = Screen(steam_appid, True) s.send_commands(run_commands)
def screenutil(self): host = socket.gethostname() list_screens() s = Screen('session1', True) s.send_commands('bash') s.send_commands('ls') s.enable_logs() s.send_commands("df") s.expect('\@%s' % host) print((s.before)) print(next(s.logs))
def payload(): payload = request.json # print('*'*10) workstation = os.path.expanduser('~') + os.environ['REPOPATH'] repo = os.environ['GHREPO'] action = payload.get('action', '') label = payload.get('label', '') issue = payload.get('issue', '') # just create a new branch when the user assign # 'in progress' label into if ( action and label and issue and action == 'labeled' and label['name'] == 'in progress' ): # useful to implement the label at commits, # e.g: label/issue should be the name of the branch. labels = [l['name'] for l in issue['labels'] if l['name']] labels.remove('in progress') branch_label = '' if not labels else random.choice(labels) branch_format = '{label}/issue-{number}' if branch_label else '{number}' branch_info = { 'label': branch_label, 'number': issue['number'] } new_branch = branch_format.format(**branch_info) # screen name s_name = 'github-webhook' s = Screen(s_name) if not s.exists: s.initialize() s.send_commands( 'cd %s' % workstation ) data = { 'repository': repo, 'username': os.environ['GHUSER'], 'password': os.environ['GHPWD'], 'default_b': 'hml', 'new_branch': new_branch } s.send_commands( 'git pull https://{username}:{password}@{repository} {default_b}'.format(**data) ) s.send_commands( 'git checkout %s' % data['default_b'] ) s.send_commands( 'git branch -d %s' % new_branch ) s.send_commands( 'git checkout -b %s' % new_branch ) s.send_commands( 'git push https://{username}:{password}@{repository} {new_branch}'.format(**data) ) return 'ok'
def launch_screen(self, name, i, command): screen = Screen(name + '_%d' % (i + 1), True) self.screens.append(screen) screen.send_commands(command)
def start(self): """ Method to start the SRCDS gameserver. There is a lot of customization going on here for each game. """ steam_appid = self.gsconfig["steamcmd"]["appid"] # Figure out if there is a mapgroup to go with this launch. if not self.gsconfig[steam_appid]["mapgroup"] == "none": srcds_launch = ( "-game {game} " " -console -usercon -secure -autoupdate " "-steam_dir {steam_dir} " "-steamcmd_script {runscript} " "-maxplayers_override {maxplayers} " "-tickrate {tickrate} " "+port {port} " "+ip {ip} " "+map {map} " "+mapgroup {mapgroup}".format( game=GAME[steam_appid], steam_dir=self.path["steamcmd"], runscript="runscript.txt", maxplayers=self.gsconfig[steam_appid]["maxplayers"], tickrate=self.gsconfig[steam_appid]["tickrate"], port=self.gsconfig[steam_appid]["port"], ip=self.gsconfig[steam_appid]["ip"], map=self.gsconfig[steam_appid]["map"], mapgroup=self.gsconfig[steam_appid]["mapgroup"], steamaccount=self.gsconfig[steam_appid]["sv_setsteamaccount"], ) ) else: srcds_launch = ( "-game {game} " "-console -usercon -secure -autoupdate " "-steam_dir {steam_dir} " "-steamcmd_script {runscript} " "-maxplayers_override {maxplayers} " "-tickrate {tickrate} " "+port {port} " "+ip {ip} " "+map {map}".format( game=GAME[steam_appid], steam_dir=self.path["steamcmd"], runscript="runscript.txt", maxplayers=self.gsconfig[steam_appid]["maxplayers"], tickrate=self.gsconfig[steam_appid]["tickrate"], port=self.gsconfig[steam_appid]["port"], ip=self.gsconfig[steam_appid]["ip"], map=self.gsconfig[steam_appid]["map"], steamaccount=self.gsconfig[steam_appid]["sv_setsteamaccount"], ) ) # Catch the gamemode and throw it as an extra launch option if not self.gsconfig[steam_appid]["gamemode"] == "none": gamemode = self.gsconfig[steam_appid]["gamemode"] if gamemode == "casual": extra_parameters = "+game_type 0 +game_mode 0" elif gamemode == "competitive": extra_parameters = "+game_type 0 +game_mode 1" elif gamemode == "armsrace": extra_parameters = "+game_type 1 +game_mode 0" elif gamemode == "demolition": extra_parameters = "+game_type 1 +game_mode 1" elif gamemode == "deathmatch": extra_parameters = "+game_type 1 +game_mode 2" else: gamemode_launch = "" # Form up the SRCDS launch command srcds_run = "{path}/srcds_run {launch} {extra}".format( path=self.path["game"], launch=srcds_launch, extra=extra_parameters ) s = Screen(steam_appid, True) s.send_commands(srcds_run)
def start(self): """ Method to start the SRCDS gameserver. There is a lot of customization going on here for each game. """ steam_appid = self.gsconfig['steamcmd']['appid'] # Figure out if there is a mapgroup to go with this launch. if not self.gsconfig[steam_appid]['mapgroup'] == 'none': srcds_launch = '-game {game} ' \ ' -console -usercon -secure -autoupdate ' \ '-steam_dir {steam_dir} ' \ '-steamcmd_script {runscript} ' \ '-maxplayers_override {maxplayers} ' \ '-tickrate {tickrate} ' \ '+port {port} ' \ '+ip {ip} ' \ '+map {map} ' \ '+mapgroup {mapgroup}' \ .format(game=GAME[steam_appid], steam_dir=self.path['steamcmd'], runscript='runscript.txt', maxplayers=self.gsconfig[steam_appid]['maxplayers'], tickrate=self.gsconfig[steam_appid]['tickrate'], port=self.gsconfig[steam_appid]['port'], ip=self.gsconfig[steam_appid]['ip'], map=self.gsconfig[steam_appid]['map'], mapgroup=self.gsconfig[steam_appid]['mapgroup'], steamaccount=self.gsconfig[steam_appid]['sv_setsteamaccount'] ) else: srcds_launch = '-game {game} ' \ '-console -usercon -secure -autoupdate ' \ '-steam_dir {steam_dir} ' \ '-steamcmd_script {runscript} ' \ '-maxplayers_override {maxplayers} ' \ '-tickrate {tickrate} ' \ '+port {port} ' \ '+ip {ip} ' \ '+map {map}' \ .format(game=GAME[steam_appid], steam_dir=self.path['steamcmd'], runscript='runscript.txt', maxplayers=self.gsconfig[steam_appid]['maxplayers'], tickrate=self.gsconfig[steam_appid]['tickrate'], port=self.gsconfig[steam_appid]['port'], ip=self.gsconfig[steam_appid]['ip'], map=self.gsconfig[steam_appid]['map'], steamaccount=self.gsconfig[steam_appid]['sv_setsteamaccount'] ) # Catch the gamemode and throw it as an extra launch option if not self.gsconfig[steam_appid]['gamemode'] == 'none': gamemode = self.gsconfig[steam_appid]['gamemode'] if gamemode == 'casual': extra_parameters = "+game_type 0 +game_mode 0" elif gamemode == 'competitive': extra_parameters = "+game_type 0 +game_mode 1" elif gamemode == 'armsrace': extra_parameters = "+game_type 1 +game_mode 0" elif gamemode == 'demolition': extra_parameters = "+game_type 1 +game_mode 1" elif gamemode == 'deathmatch': extra_parameters = "+game_type 1 +game_mode 2" else: gamemode_launch = '' # Form up the SRCDS launch command srcds_run = '{path}/srcds_run {launch} {extra}' \ .format(path=self.path['game'], launch=srcds_launch, extra=extra_parameters ) s = Screen(steam_appid, True) s.send_commands(srcds_run)
print(screens) for screen in screens: print(screen.name) if screen.name in ['session1', 'session2']: screen.kill() # s1 session_Name = 'session1' s1 = Screen(session_Name, True) if not s1.exists: raise RuntimeError("ERROR: Session not started: %s" % session_Name) time.sleep(5000) # funky prompts could reduce log visibility. Use sh or bash for best results s1.send_commands('bash') s1.enable_logs() s1.send_commands("df") print(next(s1.logs)) s1.disable_logs() # s1 = None # s1 = Screen("session1") # s1.exists s1.kill() # s2 s2 = Screen("session2") s2.exists