mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Add PID file and Yunoception
This commit is contained in:
parent
1dc7e587d5
commit
15f85746cd
2 changed files with 48 additions and 1 deletions
31
yunohost
31
yunohost
|
@ -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:
|
||||
|
|
18
yunohost.tac
18
yunohost.tac
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue