diff --git a/actions/actions.py b/actions/actions.py new file mode 100644 index 0000000..7d808e1 --- /dev/null +++ b/actions/actions.py @@ -0,0 +1,51 @@ +#!/usr/bin/python + +import os +import sys + +from charmhelpers.core.host import service_pause, service_resume +from charmhelpers.core.hookenv import action_fail, status_set + + +MYSQL_SERVICE = "mysql" + +def pause(): + """Pause the MySQL service. + + @raises Exception should the service fail to stop. + """ + if not service_pause(MYSQL_SERVICE): + raise Exception("Failed to pause MySQL service.") + status_set( + "maintenance", "Paused. Use 'resume' action to resume normal service.") + +def resume(): + """Resume the MySQL service. + + @raises Exception should the service fail to start.""" + if not service_resume(MYSQL_SERVICE): + raise Exception("Failed to resume MySQL service.") + status_set("active", "") + + +# A dictionary of all the defined actions to callables (which take +# parsed arguments). +ACTIONS = {"pause": pause, "resume": resume} + + +def main(args): + action_name = os.path.basename(args[0]) + try: + action = ACTIONS[action_name] + except KeyError: + return "Action %s undefined" % action_name + else: + try: + action(args) + except Exception as e: + action_fail(str(e)) + + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:])) + diff --git a/actions/pause b/actions/pause deleted file mode 100755 index ec4700b..0000000 --- a/actions/pause +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/python -import sys - -from charmhelpers.core import hookenv, host - -if __name__ == "__main__": - if not host.service_pause("mysql"): - hookenv.action_fail("Failed to pause MySQL service.") - sys.exit(-1) diff --git a/actions/pause b/actions/pause new file mode 120000 index 0000000..405a394 --- /dev/null +++ b/actions/pause @@ -0,0 +1 @@ +actions.py \ No newline at end of file diff --git a/actions/resume b/actions/resume deleted file mode 100755 index 81c90b3..0000000 --- a/actions/resume +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/python -import os -import sys - -from charmhelpers.core import hookenv, host - -if __name__ == "__main__": - if not host.service_resume("mysql"): - hookenv.action_fail("Failed to resume MySQL service.") - sys.exit(-1) - - diff --git a/actions/resume b/actions/resume new file mode 120000 index 0000000..405a394 --- /dev/null +++ b/actions/resume @@ -0,0 +1 @@ +actions.py \ No newline at end of file