Exemplo n.º 1
0
    def do_enable_autostart(self, line):
        if line == '':
            self.help_enable_autostart()
            return 0

        try:
            int(line)
        except ValueError:
            console.error("Server ID must be a string")
            self.help_enable_autostart()
            return 0

        try:
            server = MC_settings.get_by_id(line)

        except Exception as e:
            console.help("Unable to find a server with that ID: {}".format(e))
            return 0

        server = int(line)

        MC_settings.update({
            MC_settings.auto_start_server: True
        }).where(MC_settings.id == server).execute()

        logger.info(
            "Enabled Autostart for Server {} via the console".format(server))
        console.info("Enabled Autostart for Server {} ".format(server))
Exemplo n.º 2
0
    def do_restart(self, line):
        if line == '':
            self.help_start()
            return 0

        try:
            int(line)
        except ValueError:
            console.error("Server ID must be a number")
            self.help_start()
            return 0

        try:
            server = MC_settings.get_by_id(line)

        except Exception as e:
            console.help("Unable to find a server with that ID: {}".format(e))
            return 0

        server = int(line)

        Remote.insert({
            Remote.command: 'restart_mc_server',
            Remote.server_id: server,
            Remote.command_source: "localhost"
        }).execute()

        console.info("Restarting Minecraft Server in background")
Exemplo n.º 3
0
 def help_revert_server_jar(self):
     console.help("Reverts a Server Jar Update")
     console.help("Specify the server to revert by ID number")
     console.help(
         "Example: revert_server_jar 1 - this will revert the update for server ID 1"
     )
     console.help("You can get a server id by issuing list_servers")
Exemplo n.º 4
0
 def help_enable_autostart(self):
     console.help("Enables Server Autostarting on Crafty Launch")
     console.help("Specify the server to modify by ID number")
     console.help(
         "Example: enable_autostart 1 - this will enable auto-start for server 1"
     )
     console.help("You can get a server id by issuing list_servers")
Exemplo n.º 5
0
    def do_show_stats(self, line):
        multi.do_host_status()
        host_stats = multi.get_host_status()
        server_stats = multi.get_stats_for_servers()

        websettings = Webserver.get()

        port_number = websettings.port_number

        console.info("/" * 75)
        console.info("#\t\t Crafty Controller Server Stats \t\t\t#")
        console.info("/" * 75)

        console.info("Boot Time:\t {}".format(host_stats['boot_time']))
        console.info("Webconsole at:\t https://{}:{}".format(
            helper.get_local_ip(), port_number))
        console.info("-" * 75)

        console.info("CPU Usage:\t {}".format(host_stats['cpu_usage']))
        console.info("CPU Cores:\t {}".format(host_stats['cpu_cores']))
        console.info("Mem Percent:\t {}".format(host_stats['mem_percent']))
        console.info("Mem Usage: \t {} / {}".format(host_stats['mem_usage'],
                                                    host_stats['mem_total']))
        console.info("Disk Percent:\t {}".format(host_stats['disk_percent']))
        console.info("Disk Usage: \t {} / {}".format(host_stats['disk_usage'],
                                                     host_stats['disk_total']))

        console.info("-" * 75)
        console.info(" --- Minecraft Servers --- ")
        console.info("-" * 75)

        s = 1
        while s <= len(server_stats):
            data = server_stats[s]
            console.info("Server ID {}".format(data['server_id']))
            console.info("Running {}".format(data['server_running']))
            console.info("Players: {}/{}".format(data['online_players'],
                                                 data['max_players']))
            s += 1
        console.help("Use the list_servers command to get more detailed data")
Exemplo n.º 6
0
    def do_start(self, line):
        if line == '':
            self.help_start()
            return 0

        try:
            int(line)
        except ValueError:
            console.error("Server ID must be a number")
            self.help_start()
            return 0

        try:
            server = MC_settings.get_by_id(line)

        except Exception as e:
            console.help("Unable to find a server with that ID: {}".format(e))
            return 0

        server = int(line)

        if helper.is_setup_complete():

            srv_obj = multi.get_server_obj(server)

            if srv_obj.check_running():
                console.warning("Server already running")
            else:
                console.info("Starting Minecraft Server in background")

                Remote.insert({
                    Remote.command: 'start_mc_server',
                    Remote.server_id: server,
                    Remote.command_source: "localhost"
                }).execute()

        else:
            console.warning(
                "Unable to start server, please complete setup in the web GUI first"
            )
Exemplo n.º 7
0
    def do_stop(self, line):
        if line == '':
            self.help_stop()
            return 0

        try:
            int(line)
        except ValueError:
            console.error("Server ID must be a number")
            self.help_stop()
            return 0

        try:
            server = MC_settings.get_by_id(line)

        except Exception as e:
            console.help("Unable to find a server with that ID: {}".format(e))
            return 0

        server = int(line)

        if helper.is_setup_complete():

            srv_obj = multi.get_server_obj(server)

            if not srv_obj.check_running():
                console.warning("Server already stopped")
            else:
                console.info("Stopping Minecraft Server")
                multi.stop_server(server)
                '''
                Remote.insert({
                    Remote.command: 'stop_mc_server'
                }).execute()
                '''
        else:
            console.warning(
                "Unable to stop server, please complete setup in the web GUI first"
            )
Exemplo n.º 8
0
    def do_revert_server_jar(self, line):
        if line == '':
            self.help_update_server_jar()
            return 0

        try:
            int(line)
        except ValueError:
            console.error("Server ID must be a number")
            self.help_update_server_jar()
            return 0

        try:
            server = MC_settings.get_by_id(line)

        except Exception as e:
            console.help("Unable to find a server with that ID: {}".format(e))
            return 0

        server = int(line)

        if helper.is_setup_complete():

            srv_obj = multi.get_server_obj(server)

            console.info("Reverting updated Server Jar in background")

            Remote.insert({
                Remote.command: 'revert_server_jar_console',
                Remote.server_id: server,
                Remote.command_source: "localhost"
            }).execute()
        else:
            console.warning(
                "Unable to update server jar, please complete setup in the web GUI first"
            )
Exemplo n.º 9
0
 def help_list_users(self):
     console.help("Lists all users in the Crafty Controller")
Exemplo n.º 10
0
 def help_exit(self):
     console.help("Stops the server if running, Exits the program")
Exemplo n.º 11
0
 def help_stop(self):
     console.help("Stops a Server")
     console.help("Specify the server to stop by ID number")
     console.help("Example: stop 1 - this will stop server ID 1")
     console.help("You can get a server id by issuing list_servers")
Exemplo n.º 12
0
 def help_show_stats(self):
     console.help(
         "Shows system information such as CPU/Mem/Disk Usage and Server stats: Online / Max players etc"
     )
Exemplo n.º 13
0
 def help_update_server_jar(self):
     console.help("Updates a Server Jar")
     console.help("Specify the server to update by ID number")
     console.help(
         "Example: update_server_jar 1 - this will update server ID 1")
     console.help("You can get a server id by issuing list_servers")
Exemplo n.º 14
0
 def help_list_servers(self):
     console.help("Lists Servers Defined in the System")
Exemplo n.º 15
0
 def help_restart(self):
     console.help(
         "Stops then Starts the server if not running. Will also start the server if not already running"
     )
Exemplo n.º 16
0
    # do our scheduling
    multi.reload_scheduling()

    # schedule our stats
    schedule.every(10).seconds.do(multi.do_stats_for_servers).tag('server_stats')
    schedule.every(10).seconds.do(multi.do_host_status).tag('server_stats')

    multi.reload_user_schedules()

    # start the remote commands watcher thread
    remote_coms = remote_commands(tornado_srv)
    remote_coms_thread = threading.Thread(target=remote_coms.start_watcher, daemon=True, name="Remote_Coms")
    remote_coms_thread.start()

    console.info("Crafty Startup Procedure Complete")
    console.help("Type 'stop' or 'exit' to shutdown Crafty")

    if not daemon_mode:
        Crafty = MainPrompt(mc_server)
        Crafty.cmdloop()
    else:
        logger.info("Not starting crafty console due to daemonize mode")

    if daemon_mode:
        # Freeze the program in a loop
        logger.info("Freezing program due to daemonize mode")
        while True:
            # fixes a 100% CPU usage issue in daemonized mode - thanks ImMeta for finding this.
            time.sleep(1)

Exemplo n.º 17
0
 def help_change_web_port(self):
     console.help(
         "Sets the Tornado Webserver Port. Issue 'reload webserver' to apply the change."
     )
Exemplo n.º 18
0
 def help_reload_webserver(self):
     console.help(
         "Reloads the Tornado Webserver, takes 5 seconds to reload")
Exemplo n.º 19
0
 def help_set_passwd(self):
     console.help(
         "Sets a users password. Example set_password Admin. Use list_users to see defined users"
     )
Exemplo n.º 20
0
def show_help():
    console.help("-h: shows this message")
    console.help("-k: stops all crafty processes")
    console.help("--no-console: don't start the console")
    sys.exit(0)
Exemplo n.º 21
0
 def help_check_update(self):
     console.help(
         "Shows version information for you and what is in the repos to help you decide if you should "
         "update or not")