kopia lustrzana https://github.com/piku/piku
Sorted commands
rodzic
231783b2ee
commit
069e4dc20e
87
piku.py
87
piku.py
|
|
@ -9,6 +9,7 @@ from os.path import abspath, basename, dirname, exists, getmtime, join, realpath
|
||||||
from subprocess import call, check_output
|
from subprocess import call, check_output
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
|
|
||||||
# === Globals - all tweakable settings are here ===
|
# === Globals - all tweakable settings are here ===
|
||||||
|
|
||||||
PIKU_ROOT = os.environ.get('PIKU_ROOT', join(os.environ['HOME'],'.piku'))
|
PIKU_ROOT = os.environ.get('PIKU_ROOT', join(os.environ['HOME'],'.piku'))
|
||||||
|
|
@ -25,7 +26,6 @@ UWSGI_LOG_MAXSIZE = '1048576'
|
||||||
|
|
||||||
# === Utility functions ===
|
# === Utility functions ===
|
||||||
|
|
||||||
|
|
||||||
def sanitize_app_name(app):
|
def sanitize_app_name(app):
|
||||||
"""Sanitize the app name and build matching path"""
|
"""Sanitize the app name and build matching path"""
|
||||||
|
|
||||||
|
|
@ -72,7 +72,6 @@ def setup_authorized_keys(ssh_fingerprint, script_path, pubkey):
|
||||||
h.write("""command="FINGERPRINT=%(ssh_fingerprint)s NAME=default %(script_path)s $SSH_ORIGINAL_COMMAND",no-agent-forwarding,no-user-rc,no-X11-forwarding,no-port-forwarding %(pubkey)s\n""" % locals())
|
h.write("""command="FINGERPRINT=%(ssh_fingerprint)s NAME=default %(script_path)s $SSH_ORIGINAL_COMMAND",no-agent-forwarding,no-user-rc,no-X11-forwarding,no-port-forwarding %(pubkey)s\n""" % locals())
|
||||||
os.chmod(authorized_keys, stat.S_IRUSR | stat.S_IWUSR)
|
os.chmod(authorized_keys, stat.S_IRUSR | stat.S_IWUSR)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def parse_procfile(filename):
|
def parse_procfile(filename):
|
||||||
"""Parses a Procfile and returns the worker types. Only one worker of each type is allowed."""
|
"""Parses a Procfile and returns the worker types. Only one worker of each type is allowed."""
|
||||||
|
|
@ -350,14 +349,20 @@ def piku():
|
||||||
|
|
||||||
@piku.resultcallback()
|
@piku.resultcallback()
|
||||||
def cleanup(ctx):
|
def cleanup(ctx):
|
||||||
"""Callback from command execution -- currently used for debugging"""
|
"""Callback from command execution -- add debugging to taste"""
|
||||||
pass
|
pass
|
||||||
#print sys.argv[1:]
|
|
||||||
#print os.environ
|
|
||||||
|
|
||||||
|
|
||||||
# --- User commands ---
|
# --- User commands ---
|
||||||
|
|
||||||
|
@piku.command("apps")
|
||||||
|
def list_apps():
|
||||||
|
"""List applications"""
|
||||||
|
|
||||||
|
for a in os.listdir(APP_ROOT):
|
||||||
|
echo(a, fg='green')
|
||||||
|
|
||||||
|
|
||||||
@piku.command("config")
|
@piku.command("config")
|
||||||
@argument('app')
|
@argument('app')
|
||||||
def deploy_app(app):
|
def deploy_app(app):
|
||||||
|
|
@ -385,7 +390,8 @@ def deploy_app(app, setting):
|
||||||
env = parse_settings(config_file)
|
env = parse_settings(config_file)
|
||||||
if setting in env:
|
if setting in env:
|
||||||
echo("%s" % env[setting], fg='white')
|
echo("%s" % env[setting], fg='white')
|
||||||
# no output if file or setting is missing, for scripting purposes
|
else:
|
||||||
|
echo("Warning: no active configuration for '%s'" % app)
|
||||||
|
|
||||||
|
|
||||||
@piku.command("config:set")
|
@piku.command("config:set")
|
||||||
|
|
@ -453,31 +459,20 @@ def destroy_app(app):
|
||||||
echo("Removing file '%s'" % f, fg='yellow')
|
echo("Removing file '%s'" % f, fg='yellow')
|
||||||
os.remove(f)
|
os.remove(f)
|
||||||
|
|
||||||
|
|
||||||
@piku.command("apps")
|
|
||||||
def list_apps():
|
|
||||||
"""List applications"""
|
|
||||||
|
|
||||||
for a in os.listdir(APP_ROOT):
|
@piku.command("logs")
|
||||||
echo(a, fg='green')
|
|
||||||
|
|
||||||
|
|
||||||
@piku.command("restart")
|
|
||||||
@argument('app')
|
@argument('app')
|
||||||
def restart_app(app):
|
def tail_logs(app):
|
||||||
"""Restart an application"""
|
"""Tail an application log"""
|
||||||
|
|
||||||
app = exit_if_invalid(app)
|
app = exit_if_invalid(app)
|
||||||
|
|
||||||
config = glob(join(UWSGI_ENABLED, '%s*.ini' % app))
|
|
||||||
|
|
||||||
if len(config):
|
logfiles = glob(join(LOG_ROOT, app, '*.log'))
|
||||||
echo("Restarting app '%s'..." % app, fg='yellow')
|
if len(logfiles):
|
||||||
for c in config:
|
for line in multi_tail(app, logfiles):
|
||||||
os.remove(c)
|
echo(line.strip(), fg='white')
|
||||||
do_deploy(app)
|
|
||||||
else:
|
else:
|
||||||
echo("Error: app '%s' not deployed!" % app, fg='red')
|
echo("No logs found for app '%s'." % app, fg='yellow')
|
||||||
|
|
||||||
|
|
||||||
@piku.command("ps")
|
@piku.command("ps")
|
||||||
|
|
@ -523,6 +518,24 @@ def deploy_app(app, settings):
|
||||||
do_deploy(app, deltas)
|
do_deploy(app, deltas)
|
||||||
|
|
||||||
|
|
||||||
|
@piku.command("restart")
|
||||||
|
@argument('app')
|
||||||
|
def restart_app(app):
|
||||||
|
"""Restart an application"""
|
||||||
|
|
||||||
|
app = exit_if_invalid(app)
|
||||||
|
|
||||||
|
config = glob(join(UWSGI_ENABLED, '%s*.ini' % app))
|
||||||
|
|
||||||
|
if len(config):
|
||||||
|
echo("Restarting app '%s'..." % app, fg='yellow')
|
||||||
|
for c in config:
|
||||||
|
os.remove(c)
|
||||||
|
do_deploy(app)
|
||||||
|
else:
|
||||||
|
echo("Error: app '%s' not deployed!" % app, fg='red')
|
||||||
|
|
||||||
|
|
||||||
@piku.command("setup")
|
@piku.command("setup")
|
||||||
def init_paths():
|
def init_paths():
|
||||||
"""Initialize environment"""
|
"""Initialize environment"""
|
||||||
|
|
@ -572,23 +585,25 @@ def add_key(public_key_file):
|
||||||
echo("Error: invalid public key file '%s'" % public_key_file, fg='red')
|
echo("Error: invalid public key file '%s'" % public_key_file, fg='red')
|
||||||
else:
|
else:
|
||||||
echo("Error: public key file '%s' not found." % public_key_file, fg='red')
|
echo("Error: public key file '%s' not found." % public_key_file, fg='red')
|
||||||
|
|
||||||
|
|
||||||
@piku.command("logs")
|
|
||||||
|
@piku.command("stop")
|
||||||
@argument('app')
|
@argument('app')
|
||||||
def tail_logs(app):
|
def stop_app(app):
|
||||||
"""Tail an application log"""
|
"""Stop an application"""
|
||||||
|
|
||||||
app = exit_if_invalid(app)
|
app = exit_if_invalid(app)
|
||||||
|
|
||||||
|
config = glob(join(UWSGI_ENABLED, '%s*.ini' % app))
|
||||||
|
|
||||||
logfiles = glob(join(LOG_ROOT, app, '*.log'))
|
if len(config):
|
||||||
if len(logfiles):
|
echo("Stopping app '%s'..." % app, fg='yellow')
|
||||||
for line in multi_tail(app, logfiles):
|
for c in config:
|
||||||
echo(line.strip(), fg='white')
|
os.remove(c)
|
||||||
else:
|
else:
|
||||||
echo("No logs found for app '%s'." % app, fg='yellow')
|
echo("Error: app '%s' not deployed!" % app, fg='red')
|
||||||
|
|
||||||
|
|
||||||
# --- Internal commands ---
|
# --- Internal commands ---
|
||||||
|
|
||||||
@piku.command("git-hook")
|
@piku.command("git-hook")
|
||||||
|
|
|
||||||
Ładowanie…
Reference in New Issue