Example #1
0
    try:
        __import__(module_name)
    except ImportError:
        return False
    else:
        return True

commands = [
    default.ManagerBaseController,
    version.VersionController,
    configure.ConfigureController,
    download.DownloadController,
    #download.DownloadWorkshopController,
]

config = Configuration()

supervisor_fs = FSCheck(config.get('supervisor', 'supervisor'))
supervisorctl_fs = FSCheck(config.get('supervisor', 'supervisorctl'))

if (
        supervisor_fs.exists(error=False) and supervisor_fs.access('x', error=False) and
        supervisorctl_fs.exists(error=False) and supervisorctl_fs.access('x', error=False)
   ):
    from qldsmanager.command import server
    from qldsmanager.command import supervisor

    commands.append(server.ServerController)
    commands.append(supervisor.SupervisorController)

Example #2
0
    def default(self):
        config = Configuration()

        if self.app.pargs.qldir is not None:
            config.set('dir', 'ql', os.path.expanduser(self.app.pargs.qldir))

        if self.app.pargs.steamdir is not None:
            config.set('dir', 'steamcmd',
                       os.path.expanduser(self.app.pargs.steamdir))

        if self.app.pargs.servers is not None:
            config.set('config', 'servers',
                       os.path.expanduser(self.app.pargs.servers))

        if self.app.pargs.supervisor is not None:
            config.set('supervisor', 'supervisor',
                       os.path.expanduser(self.app.pargs.supervisor))

        if self.app.pargs.supervisorctl is not None:
            config.set('supervisor', 'supervisorctl',
                       os.path.expanduser(self.app.pargs.supervisorctl))

        if self.app.pargs.rcon is not None:
            config.set('config', 'rcon',
                       os.path.expanduser(self.app.pargs.rcon))

        config.update()

        data = [('QLDS dir', config.get('dir', 'ql')),
                ('SteamCMD dir', config.get('dir', 'steamcmd')),
                ('Supervisor', config.get('supervisor', 'supervisor')),
                ('Supervisorctl', config.get('supervisor', 'supervisorctl')),
                ('Servers config', config.get('config', 'servers')),
                ('Rcon config', config.get('config', 'rcon'))]

        for d in data:
            print('%s:\n    %s' % d)

        print('Configuration updated')
Example #3
0
class Supervisor:
    def __init__(self):
        self.__config = Configuration()
        self.process_prefix = 'qlds_'

        self.__config_file = self.__config.get_config_dir() + '/supervisor.conf'

    def generate_config(self, servers):
        parser = ConfigParser()

        config_dir = self.__config.get_config_dir()

        parser.add_section('unix_http_server')
        parser.set('unix_http_server', 'file', config_dir + '/supervisor.sock')
        parser.set('unix_http_server', 'chmod', '0700')

        parser.add_section('supervisord')
        parser.set('supervisord', 'logfile', config_dir + '/supervisor_error.log')
        parser.set('supervisord', 'pidfile', config_dir + '/supervisor.pid')

        parser.add_section('rpcinterface:supervisor')
        parser.set('rpcinterface:supervisor', 'supervisor.rpcinterface_factory', 'supervisor.rpcinterface:make_main_rpcinterface')

        parser.add_section('supervisorctl')
        parser.set('supervisorctl', 'serverurl', 'unix://' + config_dir + '/supervisor.sock')

        ql_executable = self.get_ql_executable()

        for sid,data in servers.items():
            name = self.process_prefix + sid
            section = 'program:' + name
            parser.add_section(section)
            parser.set(section, 'command', self.build_command_line(sid, data, ql_executable))
            parser.set(section, 'process_name', name)
            parser.set(section, 'autorestart', 'true')

        if os.path.isfile(self.__config_file) and not os.access(self.__config_file, os.W_OK):
            raise IOError('Cannot write to file ' + self.__config_file)

        with (open(self.__config_file, 'w+')) as config_fp:
            parser.write(config_fp)

    def build_command_line(self, sid, server, executable):
        command_line = [
            executable,
            '+set fs_homepath %s/%s' % (os.path.expanduser('~/.quakelive/'), sid)
        ]

        for k,v in sorted(server.items()):
            command_line.append('+set %s %s' % (k, v))

        return ' '.join(command_line)

    def get_ql_executable(self):
        if platform.architecture()[0] == '64bit':
            executable = 'run_server_x64.sh'
        else:
            executable = 'run_server_x86.sh'

        return os.path.expanduser(self.__config.get('dir', 'ql')) + '/' + executable

    def get_config_location(self):
        return self.__config_file

    def start(self):
        supervisor_executable = self.__config.get('supervisor', 'supervisor')
        supervisor_executable_fs = FSCheck(supervisor_executable)

        supervisor_executable_fs.exists()
        supervisor_executable_fs.access('x')

        return call([supervisor_executable, '-c', self.__config_file])

    def ctl(self, args: list):
        args = list(args)

        ctl_executable = self.__config.get('supervisor', 'supervisorctl')
        ctl_executable_fs = FSCheck(ctl_executable)

        ctl_executable_fs.exists()
        ctl_executable_fs.access('x')

        call_args = [ctl_executable, '-c', self.__config_file] + args

        return call(call_args)
Example #4
0
        __import__(module_name)
    except ImportError:
        return False
    else:
        return True


commands = [
    default.ManagerBaseController,
    version.VersionController,
    configure.ConfigureController,
    download.DownloadController,
    #download.DownloadWorkshopController,
]

config = Configuration()

supervisor_fs = FSCheck(config.get('supervisor', 'supervisor'))
supervisorctl_fs = FSCheck(config.get('supervisor', 'supervisorctl'))

if (supervisor_fs.exists(error=False)
        and supervisor_fs.access('x', error=False)
        and supervisorctl_fs.exists(error=False)
        and supervisorctl_fs.access('x', error=False)):
    from qldsmanager.command import server
    from qldsmanager.command import supervisor

    commands.append(server.ServerController)
    commands.append(supervisor.SupervisorController)

if module_exists('zmq'):
Example #5
0
    def __init__(self):
        self.__config = Configuration()
        self.process_prefix = 'qlds_'

        self.__config_file = self.__config.get_config_dir() + '/supervisor.conf'
Example #6
0
class DownloadController(ManagerDefaultController):
    steamcmd_url = 'https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz'
    steamcmd_archive = '/steamcmd.tar.gz'
    ql_appid = 349090
    config = Configuration()

    class Meta:
        label = 'download'
        description = 'Allows to download/update SteamCMD and QL Dedicated Server files'
        arguments = [(['--items'],
                      dict(help='Workshop item ids (separated by space)',
                           nargs='*'))]

    @expose(hide=True)
    def default(self):
        self.app.args.parse_args(['--help'])

    @expose(help='Downloads and installs SteamCMD')
    def steamcmd(self):
        steamcmd_dir = os.path.expanduser(self.config.get('dir', 'steamcmd'))
        steamcmd_dir_fs = FSCheck(steamcmd_dir, 'SteamCMD dir')

        #check if steamcmd dir exists
        if steamcmd_dir_fs.exists(error=False):
            print(
                '% exists. Remove it or change SteamCMD location in settings' %
                steamcmd_dir)
            exit(21)

        os.makedirs(steamcmd_dir)

        steamcmd_dir_fs.access('w')  #check for write access in dir

        print('Downloading SteamCMD archive')
        urlretrieve(self.steamcmd_url, steamcmd_dir + self.steamcmd_archive)

        print('Extracting SteamCMD atchive to %s' % steamcmd_dir)
        archive = tarfile.open(steamcmd_dir + self.steamcmd_archive)
        archive.extractall(steamcmd_dir)

        steamcmd_stat = os.stat(steamcmd_dir + '/steamcmd.sh')
        os.chmod(
            steamcmd_dir + '/steamcmd.sh',
            steamcmd_stat.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)

        print('SteamCMD installed in %s' % steamcmd_dir)
        print('Remember that you need "lib32stdc++6" installed in your system')

    @expose(help='Downloads and updates QL Dedicated Server files')
    def ql(self):
        steamcmd = self.__steam_exists()

        print('Downloading QL Dedicated Server files using SteamCMD...')

        call([
            steamcmd, '+login', 'anonymous', '+force_install_dir',
            os.path.expanduser(self.config.get('dir', 'ql')), '+app_update',
            str(self.ql_appid), '+quit'
        ])

    @expose(help='Downloads or updates specified workshop items')
    def workshop(self):
        steamcmd = self.__steam_exists()

        if not self.app.pargs.items:
            print('You have to define items using "--items"')
        else:
            for item in self.app.pargs.items:
                call([
                    steamcmd, '+login', 'anonymous', '+workshop_download_item',
                    str(self.ql_appid), '+app_update', item, '+quit'
                ])

    def __steam_exists(self):
        steamcmd = os.path.expanduser(
            self.config.get('dir', 'steamcmd') + '/steamcmd.sh')

        steamcmd_fs = FSCheck(steamcmd, 'SteamCMD')

        steamcmd_fs.exists()
        steamcmd_fs.access('x')

        return steamcmd
Example #7
0
    def default(self):
        config = Configuration()

        if self.app.pargs.qldir is not None:
            config.set('dir', 'ql', os.path.expanduser(self.app.pargs.qldir))

        if self.app.pargs.steamdir is not None:
            config.set('dir', 'steamcmd', os.path.expanduser(self.app.pargs.steamdir))

        if self.app.pargs.servers is not None:
            config.set('config', 'servers', os.path.expanduser(self.app.pargs.servers))

        if self.app.pargs.supervisor is not None:
            config.set('supervisor', 'supervisor', os.path.expanduser(self.app.pargs.supervisor))

        if self.app.pargs.supervisorctl is not None:
            config.set('supervisor', 'supervisorctl', os.path.expanduser(self.app.pargs.supervisorctl))

        if self.app.pargs.rcon is not None:
            config.set('config', 'rcon', os.path.expanduser(self.app.pargs.rcon))

        config.update()

        data = [
            ('QLDS dir', config.get('dir', 'ql')),
            ('SteamCMD dir', config.get('dir', 'steamcmd')),

            ('Supervisor', config.get('supervisor', 'supervisor')),
            ('Supervisorctl', config.get('supervisor', 'supervisorctl')),

            ('Servers config', config.get('config', 'servers')),
            ('Rcon config', config.get('config', 'rcon'))
        ]

        for d in data:
            print('%s:\n    %s' % d)

        print('Configuration updated')
Example #8
0
class Supervisor:
    def __init__(self):
        self.__config = Configuration()
        self.process_prefix = 'qlds_'

        self.__config_file = self.__config.get_config_dir(
        ) + '/supervisor.conf'

    def generate_config(self, servers):
        parser = ConfigParser()

        config_dir = self.__config.get_config_dir()

        parser.add_section('unix_http_server')
        parser.set('unix_http_server', 'file', config_dir + '/supervisor.sock')
        parser.set('unix_http_server', 'chmod', '0700')

        parser.add_section('supervisord')
        parser.set('supervisord', 'logfile',
                   config_dir + '/supervisor_error.log')
        parser.set('supervisord', 'pidfile', config_dir + '/supervisor.pid')

        parser.add_section('rpcinterface:supervisor')
        parser.set('rpcinterface:supervisor',
                   'supervisor.rpcinterface_factory',
                   'supervisor.rpcinterface:make_main_rpcinterface')

        parser.add_section('supervisorctl')
        parser.set('supervisorctl', 'serverurl',
                   'unix://' + config_dir + '/supervisor.sock')

        ql_executable = self.get_ql_executable()

        for sid, data in servers.items():
            name = self.process_prefix + sid
            section = 'program:' + name
            parser.add_section(section)
            parser.set(section, 'command',
                       self.build_command_line(sid, data, ql_executable))
            parser.set(section, 'process_name', name)
            parser.set(section, 'autorestart', 'true')

        if os.path.isfile(self.__config_file) and not os.access(
                self.__config_file, os.W_OK):
            raise IOError('Cannot write to file ' + self.__config_file)

        with (open(self.__config_file, 'w+')) as config_fp:
            parser.write(config_fp)

    def build_command_line(self, sid, server, executable):
        command_line = [
            executable,
            '+set fs_homepath %s/%s' %
            (os.path.expanduser('~/.quakelive/'), sid)
        ]

        for k, v in sorted(server.items()):
            command_line.append('+set %s %s' % (k, v))

        return ' '.join(command_line)

    def get_ql_executable(self):
        if platform.architecture()[0] == '64bit':
            executable = 'run_server_x64.sh'
        else:
            executable = 'run_server_x86.sh'

        return os.path.expanduser(self.__config.get('dir',
                                                    'ql')) + '/' + executable

    def get_config_location(self):
        return self.__config_file

    def start(self):
        supervisor_executable = self.__config.get('supervisor', 'supervisor')
        supervisor_executable_fs = FSCheck(supervisor_executable)

        supervisor_executable_fs.exists()
        supervisor_executable_fs.access('x')

        return call([supervisor_executable, '-c', self.__config_file])

    def ctl(self, args: list):
        args = list(args)

        ctl_executable = self.__config.get('supervisor', 'supervisorctl')
        ctl_executable_fs = FSCheck(ctl_executable)

        ctl_executable_fs.exists()
        ctl_executable_fs.access('x')

        call_args = [ctl_executable, '-c', self.__config_file] + args

        return call(call_args)
Example #9
0
    def __init__(self):
        self.__config = Configuration()
        self.process_prefix = 'qlds_'

        self.__config_file = self.__config.get_config_dir(
        ) + '/supervisor.conf'