| from charms.reactive import when, when_not, set_state | |
| from charmhelpers.fetch.archiveurl import ArchiveUrlFetchHandler | |
| from charmhelpers.core import hookenv | |
| from subprocess import check_call, CalledProcessError, call, check_output, Popen | |
| from charmhelpers.core.hookenv import status_set, log | |
| import os | |
| au = ArchiveUrlFetchHandler() | |
| os.environ["JOSHUA"] = "/opt/joshua-runtime-6.0.5/" | |
| @when_not('joshua-runtime.installed') | |
| def install_joshua_runtime(): | |
| status_set('maintenance', 'Joshua') | |
| download() | |
| unzip() | |
| set_state('joshua-runtime.installed') | |
| def download(): | |
| au.download("http://community.meteorite.bi/joshua-runtime.tgz", "/tmp/joshua-runtime.tgz") | |
| def unzip(): | |
| check_output(['tar', 'xvfz', "/tmp/joshua-runtime.tgz", '-C', '/opt']) | |
| @when_not('java.ready') | |
| def update_java_status(): | |
| status_set('blocked', 'Waiting for Java.') | |
| @when_not('languagepack.installed') | |
| def update_lp_status(); | |
| status_set('blocked', 'Waiting for Language Pack') | |
| @when('java.ready') | |
| @when('joshua-runtime.installed') | |
| @when('languagepack.installed') | |
| def start_joshua(java): | |
| try: | |
| check_call(['pgrep', '-f', 'joshua']) | |
| except CalledProcessError: | |
| check_call(['/opt/joshua-runtime-6.0.5/bin/joshua-decoder', '-m', '4g', '-c', 'joshua.config', '-server-port', '5674', '$*'], cwd='/opt/language-pack', env=dict(os.environ, JOSHUA="/opt/joshua-runtime-6.0.5/")) | |
| hookenv.open_port(5674) | |
| status_set('active', 'Joshua running') | |
| @when('joshua-runtime.install') | |
| @when_not('languagepack.installed') | |
| def stop_joshua(): | |
| call(['pkill', '-f', 'joshua-decoder']) | |
| status_set('stopped', 'Waiting for language pack') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment