Exemplo n.º 1
0
 def _memory(self):
     try:
         get_bytes = self.javaserver.getmemoryusage()
     except OSError as e:
         self.log.error(e)
     except Exception as ex:
         self.log.exception(
             "Something went wrong when trying to fetch"
             " memory usage! (%s)", ex)
     else:
         amount, units = format_bytes(get_bytes)
         self.log.info("Server Memory Usage: %s %s (%s bytes)" %
                       (amount, units, get_bytes))
Exemplo n.º 2
0
 def _memory(self):
     try:
         get_bytes = self.javaserver.getmemoryusage()
     except OSError as e:
         self.log.error(e)
     except Exception as ex:
         self.log.exception(
             "Something went wrong when trying to fetch"
             " memory usage! (%s)", ex)
     else:
         amount, units = format_bytes(get_bytes)
         self.log.info(
             "Server Memory Usage: %s %s (%s bytes)" % (
                 amount, units, get_bytes))
Exemplo n.º 3
0
    def command_wrapper(self, player, payload):
        if not self._superop(player):
            return False

        buildstring = self.wrapper.getbuildstring()
        if len(getargs(payload["args"], 0)) > 0:
            subcommand = getargs(payload["args"], 0)
            if subcommand == "update":
                player.message({"text": "Checking for new Wrapper.py updates...", "color": "yellow"})
                update = self.wrapper.get_wrapper_update_info()
                if update:
                    version, build, repotype = update
                    player.message("&bNew Wrapper.py Version %s (Build #%d) available!)" %
                                   (".".join([str(_) for _ in version]), build))
                    player.message("&bYou are currently on %s." % self.wrapper.getbuildstring())
                    player.message("&aPerforming update...")
                    if self.wrapper.performupdate(version, build, repotype):
                        player.message("&aUpdate completed! Version %s #%d (%s) is now installed. "
                                       "Please reboot Wrapper.py to apply changes." % (version, build, repotype))
                    else:
                        player.message("&cAn error occured while performing update.")
                        player.message("&cPlease check the Wrapper.py console as soon as possible "
                                       "for an explanation and traceback.")
                        player.message("&cIf you are unsure of the cause, please file a bug report "
                                       "on http://github.com/benbaptist/minecraft-wrapper with the traceback.")
                else:
                    player.message("&cNo new Wrapper.py versions available.")
            elif subcommand == "halt":
                player.message("&cHalting Wrapper.py... goodbye!")
                self.wrapper.shutdown()
            elif subcommand in ("mem", "memory"):
                server_bytes = self.wrapper.javaserver.getmemoryusage()
                if server_bytes:
                    amount, units = format_bytes(server_bytes)
                    player.message("&cServer Memory: %s %s (%s bytes)" % (amount, units, server_bytes))
                else:
                    player.message("&cError: Couldn't retrieve memory usage for an unknown reason")
            elif subcommand == "random":
                player.message("&cRandom number: &a%d" % random.randrange(0, 99999999))
        else:
            player.message({"text": "Wrapper.py Version %s" % buildstring, "color": "gray", "italic": True})
        return
Exemplo n.º 4
0
    def _performbackup(self):
        timestamp = int(time.time())

        # Turn off server saves...
        self.wrapper.javaserver.doserversaving(False)
        # give server time to save
        time.sleep(1)

        # Create tar arguments
        filename = "backup-%s.tar" % datetime.datetime.fromtimestamp(
            int(timestamp)).strftime("%Y-%m-%d_%H.%M.%S")
        if self.config["Backups"]["backup-compression"]:
            filename += ".gz"
            arguments = [
                "tar", "czf",
                "%s/%s" % (self.config["Backups"]["backup-location"].replace(
                    " ", "\\ "), filename)
            ]
        else:
            arguments = [
                "tar", "cfpv",
                "%s/%s" % (self.config["Backups"]["backup-location"], filename)
            ]

        # Process begin Events
        if not self.wrapper.events.callevent("wrapper.backupBegin",
                                             {"file": filename}):  # noqa
            self.log.warning(
                "A backup was scheduled, but was cancelled by a plugin!")
            """ eventdoc
                <group> Backups <group>

                <description> Indicates a backup is being initiated.
                <description>

                <abortable> Yes, return False to abort. <abortable>

                <comments>
                A console warning will be issued if a plugin cancels the backup.
                <comments>
                <payload>
                "file": Name of backup file.
                <payload>

            """
            self.wrapper.javaserver.doserversaving(True)
            # give server time to save
            time.sleep(1)
            return

        if self.config["Backups"]["backup-notification"]:
            self.api.minecraft.broadcast("&cBacking up... lag may occur!",
                                         irc=False)

        # Do backups
        serverpath = self.config["General"]["server-directory"]
        for backupfile in self.config["Backups"]["backup-folders"]:
            backup_file_and_path = "%s/%s" % (serverpath, backupfile)
            if os.path.exists(backup_file_and_path):
                arguments.append(backup_file_and_path)
            else:
                self.log.warning(
                    "Backup file '%s' does not exist - canceling backup",
                    backup_file_and_path)
                self.wrapper.events.callevent("wrapper.backupFailure", {
                    "reasonCode":
                    3,
                    "reasonText":
                    "Backup file '%s' does not "
                    "exist." % backup_file_and_path
                },
                                              abortable=False)
                """ eventdoc
                                <description> internalfunction <description>

                            """
                return
        # perform TAR backup
        statuscode = os.system(" ".join(arguments))

        # TODO add a wrapper properties config item to set save mode of server
        # restart saves, call finish Events
        self.wrapper.javaserver.doserversaving(True)
        self.backups.append((timestamp, filename))

        # Prune backups
        self.pruneoldbackups(filename)

        # Check for success
        finalbackup = "%s/%s" % (self.config["Backups"]["backup-location"],
                                 filename)

        if not os.path.exists(finalbackup):
            self.wrapper.events.callevent("wrapper.backupFailure", {
                "reasonCode":
                2,
                "reasonText":
                "Backup file didn't exist after the tar "
                "command executed - assuming failure."
            },
                                          abortable=False)
            """ eventdoc
                <description> internalfunction <description>

            """
            summary = "backup failed"
        else:
            # find size of completed backup file
            backupsize = os.path.getsize(finalbackup)
            size_of, units = format_bytes(backupsize)
            timetook = _secondstohuman(int(time.time()) - timestamp)
            desc = "were backed up.  The operation took"
            summary = "%s %s %s %s" % (size_of, units, desc, timetook)

        self.wrapper.events.callevent("wrapper.backupEnd", {
            "file": filename,
            "status": statuscode,
            "summary": summary
        },
                                      abortable=False)
        """ eventdoc
            <group> Backups <group>

            <description> Indicates a backup is complete.
            <description>

            <abortable> No - informational only <abortable>

            <comments>
            <comments>
            <payload>
            "file": Name of backup file.
            "status": Status code from TAR
            "summary": string summary of operation 
            <payload>

        """
        if self.config["Backups"]["backup-notification"]:
            self.api.minecraft.broadcast("&aBackup cycle complete!", irc=False)
            self.api.minecraft.broadcast("&a%s" % summary, irc=False)
Exemplo n.º 5
0
    def _performbackup(self):
        timestamp = int(time.time())

        # Turn off server saves...
        self.wrapper.javaserver.doserversaving(False)
        # give server time to save
        time.sleep(1)

        # Create tar arguments
        filename = "backup-%s.tar" % datetime.datetime.fromtimestamp(
            int(timestamp)).strftime("%Y-%m-%d_%H.%M.%S")
        if self.config["Backups"]["backup-compression"]:
            filename += ".gz"
            arguments = ["tar", "czf", "%s/%s" % (
                self.config["Backups"]["backup-location"].replace(" ", "\\ "),
                filename)]
        else:
            arguments = ["tar", "cfpv", "%s/%s" % (
                self.config["Backups"]["backup-location"], filename)]

        # Process begin Events
        if not self.wrapper.events.callevent("wrapper.backupBegin", {"file": filename}):  # noqa
            self.log.warning(
                "A backup was scheduled, but was cancelled by a plugin!"
            )
            """ eventdoc
                <group> Backups <group>

                <description> Indicates a backup is being initiated.
                <description>

                <abortable> Yes, return False to abort. <abortable>

                <comments>
                A console warning will be issued if a plugin cancels the backup.
                <comments>
                <payload>
                "file": Name of backup file.
                <payload>

            """
            self.wrapper.javaserver.doserversaving(True)
            # give server time to save
            time.sleep(1)
            return

        if self.config["Backups"]["backup-notification"]:
            self.api.minecraft.broadcast(
                "&cBacking up... lag may occur!", irc=False)

        # Do backups
        serverpath = self.config["General"]["server-directory"]
        for backupfile in self.config["Backups"]["backup-folders"]:
            backup_file_and_path = "%s/%s" % (serverpath, backupfile)
            if os.path.exists(backup_file_and_path):
                arguments.append(backup_file_and_path)
            else:
                self.log.warning(
                    "Backup file '%s' does not exist - canceling backup",
                    backup_file_and_path
                )
                self.wrapper.events.callevent(
                    "wrapper.backupFailure",
                    {"reasonCode": 3,
                     "reasonText": "Backup file '%s' does not "
                                   "exist." % backup_file_and_path},
                    abortable=False
                )
                """ eventdoc
                                <description> internalfunction <description>

                            """
                return
        # perform TAR backup
        statuscode = os.system(" ".join(arguments))

        # TODO add a wrapper properties config item to set save mode of server
        # restart saves, call finish Events
        self.wrapper.javaserver.doserversaving(True)
        self.backups.append((timestamp, filename))

        # Prune backups
        self.pruneoldbackups(filename)

        # Check for success
        finalbackup = "%s/%s" % (self.config["Backups"]["backup-location"],
                                 filename)

        if not os.path.exists(finalbackup):
            self.wrapper.events.callevent(
                "wrapper.backupFailure",
                {"reasonCode": 2,
                 "reasonText": "Backup file didn't exist after the tar "
                               "command executed - assuming failure."},
                abortable=False
            )
            """ eventdoc
                <description> internalfunction <description>

            """
            summary = "backup failed"
        else:
            # find size of completed backup file
            backupsize = os.path.getsize(finalbackup)
            size_of, units = format_bytes(backupsize)
            timetook = _secondstohuman(int(time.time()) - timestamp)
            desc = "were backed up.  The operation took"
            summary = "%s %s %s %s" % (size_of, units, desc, timetook)

        self.wrapper.events.callevent(
            "wrapper.backupEnd",
            {"file": filename, "status": statuscode, "summary": summary},
            abortable=False
        )
        """ eventdoc
            <group> Backups <group>

            <description> Indicates a backup is complete.
            <description>

            <abortable> No - informational only <abortable>

            <comments>
            <comments>
            <payload>
            "file": Name of backup file.
            "status": Status code from TAR
            "summary": string summary of operation 
            <payload>

        """
        if self.config["Backups"]["backup-notification"]:
            self.api.minecraft.broadcast("&aBackup cycle complete!", irc=False)
            self.api.minecraft.broadcast("&a%s" % summary, irc=False)