Add PID file and Yunoception

This commit is contained in:
Kload 2013-10-24 16:29:07 +00:00
parent 1dc7e587d5
commit 15f85746cd
2 changed files with 48 additions and 1 deletions

View file

@ -64,6 +64,7 @@ def main():
admin_password_provided = False
json_print = False
no_ldap = False
for key, arg in enumerate(sys.argv):
if arg == '--admin-password':
@ -71,6 +72,11 @@ def main():
admin_password = sys.argv[key+1]
sys.argv.pop(key)
sys.argv.pop(key)
if arg == '--no-ldap':
no_ldap = True
sys.argv.pop(key)
if arg == '--json':
json_print = True
sys.argv.pop(key)
@ -90,9 +96,34 @@ def main():
args_dict[sanitized_key] = args_dict[key]
del args_dict[key]
del args_dict['func']
try:
with open('/etc/yunohost/passwd') as f:
admin_password = f.read()
admin_password_provided = True
except IOError: pass
if admin_password_provided:
with YunoHostLDAP(password=admin_password):
result = args.func(**args_dict)
elif os.isatty(1) and not no_ldap:
admin_password = getpass.getpass(colorize(_('Admin Password: '), 'yellow'))
with YunoHostLDAP(password=admin_password):
try:
with open('/var/run/yunohost.pid', 'r'):
raise YunoHostError(1, _("A YunoHost command is already running"))
except IOError:
with open('/var/run/yunohost.pid', 'w') as f:
f.write('ldap')
os.system('chmod 400 /var/run/yunohost.pid')
with open('/etc/yunohost/passwd', 'w') as f:
f.write(admin_password)
os.system('chmod 400 /etc/yunohost/passwd')
try:
result = args.func(**args_dict)
except KeyboardInterrupt, EOFError:
raise YunoHostError(125, _("Interrupted"))
finally:
os.remove('/etc/yunohost/passwd')
os.remove('/var/run/yunohost.pid')
else:
result = args.func(**args_dict)
#except TypeError, error:

View file

@ -115,7 +115,23 @@ def http_exec(request, **kwargs):
# Execute requested function
with YunoHostLDAP(password=request.getPassword()):
result = func(**validated_args)
try:
with open('/var/run/yunohost.pid', 'r'):
raise YunoHostError(1, _("A YunoHost command is already running"))
exceOError:
with open('/var/run/yunohost.pid', 'w') as f:
f.write('ldap')
os.system('chmod 400 /var/run/yunohost.pid')
with open('/etc/yunohost/passwd', 'w') as f:
f.write(admin_password)
os.system('chmod 400 /etc/yunohost/passwd')
try:
result = func(**validated_args)
except KeyboardInterrupt, EOFError:
raise YunoHostError(125, _("Interrupted"))
finally:
os.remove('/etc/yunohost/passwd')
os.remove('/var/run/yunohost.pid')
if result is None:
result = {}
if len(yunohost.win) > 0: