first run implemented with Popen

This commit is contained in:
Mathew Guest 2020-02-23 08:14:18 -07:00
parent edb0f70e2e
commit 7b2643cf45
3 changed files with 40 additions and 16 deletions

@ -0,0 +1,9 @@
#!/usr/bin/bash
# Edit local site config on Linux.
CONFIG_FILE="$HOME"/.config/smileyface-ut4/hub-config.ini
[ -z "$EDITOR" ] && export EDITOR=vim
"$EDITOR" "$CONFIG_FILE"

@ -30,15 +30,13 @@ class SmileyFace(app_skellington.ApplicationContainer):
""" """
if config_file is None: if config_file is None:
config_file = self._get_config_filepath( config_file = self._get_config_filepath(
'app_name', 'smileyface-ut4',
'app_author', 'app_author',
'app_config_filename' 'hub-config.ini'
) )
rc = self.ctx.config.load_config_from_file(config_file) rc = self.ctx.config.load_config_from_file(config_file)
def _cli_options(self): def _cli_options(self):
pass pass

@ -1,14 +1,15 @@
from app_skellington import _util from app_skellington import _util
from functools import partial from functools import partial
import collections import collections
import configobj
import configparser import configparser
import glob import glob
import hashlib import hashlib
import os import os
import subprocess
import pathlib import pathlib
import configobj import subprocess
import sys import sys
import time
class UT4ServerMachine: class UT4ServerMachine:
def __init__(self, ctx): def __init__(self, ctx):
@ -127,7 +128,8 @@ ssh {remote_game_host} rm {remote_game_dir}/LinuxServer/UnrealTournament/Saved/L
}) })
self._invoke_command(cmd) self._invoke_command(cmd)
# self._first_run() if self._needs_first_run():
self._first_run()
self._install_config() self._install_config()
self._install_paks() self._install_paks()
self._install_redirect_lines() self._install_redirect_lines()
@ -219,14 +221,26 @@ ssh {remote_game_host} chown ut4.ut4 {remote_game_dir} -R
self.ctx.log['ut4'].info('Starting instance once to get UID.') self.ctx.log['ut4'].info('Starting instance once to get UID.')
self.ctx.log['ut4'].info('Unfortunately, this takes 20 seconds. Just wait.') self.ctx.log['ut4'].info('Unfortunately, this takes 20 seconds. Just wait.')
# cd "$PROJECT_DIR"/instance/LinuxServer/Engine/Binaries/Linux # Make binary executable:
# chmod 770 UE4Server-Linux-Shipping bin_name = 'UE4Server-Linux-Shipping'
# ./UE4Server-Linux-Shipping UnrealTournament UT-Entry?Game=Lobby -log &>/dev/null & project_dir = self.ctx.config['app']['project_dir']
# cd - >/dev/null
cwd = '{project_dir}/instance/LinuxServer/Engine/Binaries/Linux'\
.format(project_dir=project_dir)
target_file = '{cwd}/{bin_name}'.format(cwd=cwd, bin_name=bin_name)
cmd = ['chmod', '770', target_file]
p = subprocess.run(cmd)
cmd = ['./'+bin_name, 'UnrealTournament', 'UT-Entry?Game=Lobby', '-log']
p = subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE)
try:
stdout, stsderr = p.communicate(timeout=20)
except subprocess.TimeoutExpired:
p.kill()
stdout, stderr = p.communicate()
self.ctx.log['ut4'].info('sleeping 20 seconds and then we\'ll kill the server we started just now.') self.ctx.log['ut4'].info('sleeping 20 seconds and then we\'ll kill the server we started just now.')
# sleep 20
# stop_server
# # TODO(MG) get uid and export # # TODO(MG) get uid and export
def _install_config(self): def _install_config(self):
@ -338,10 +352,10 @@ PackageChecksum="{md5sum}")'\
self.ctx.log['ut4'].info('out filename=%s', out_filename) self.ctx.log['ut4'].info('out filename=%s', out_filename)
# echo {\"rules\":[ > "$OUT_FILENAME" # echo {\"rules\":[ > "$OUT_FILENAME"
cmd = 'echo {\"rules\":[ > "{out_filename}"' cmd = 'echo {{\"rules\":[ > "{out_filename}"'.format(out_filename=out_filename)
self._invoke_command(cmd) self._invoke_command(cmd)
cmd = 'for f in "{src_dir}"/*.json ; do ; cat "$f" >> "{out_filename}" ; done'.format( cmd = 'for f in "{src_dir}"/*.json ; do cat "$f" >> "{out_filename}" ; done'.format(
**{ **{
'src_dir': src_dir, 'src_dir': src_dir,
'out_filename': out_filename 'out_filename': out_filename
@ -362,7 +376,7 @@ PackageChecksum="{md5sum}")'\
print(msg) print(msg)
self.ctx.log['ut4'].info('running cmd: %s', cmd) self.ctx.log['ut4'].info('running cmd: %s', cmd)
cwd = None # todo(mg) ? cwd = None # todo(mg) ?
# os.system(cmd) os.system(cmd)
def _md5sum_file(self, filename): def _md5sum_file(self, filename):
with open(filename, mode='rb') as f: with open(filename, mode='rb') as f:
@ -372,6 +386,9 @@ PackageChecksum="{md5sum}")'\
h = d.hexdigest() h = d.hexdigest()
return h return h
def _needs_first_run(self):
return False # TODO(MG): Hard-coded
def _validate_env_vars(self): def _validate_env_vars(self):
variable_names = ( variable_names = (
'project_dir', 'project_dir',