Add service helper

This commit is contained in:
Kload 2013-12-05 15:51:07 +00:00
parent 3ee60eafd1
commit 2393c8ae2d
2 changed files with 46 additions and 0 deletions

View file

@ -339,6 +339,21 @@ app:
help: Delete the key
action: store_true
### app_service()
service:
action_help: Add or remove a YunoHost monitored service
api: POST /app/service/{service}
arguments:
service:
help: Service to add/remove
-s:
full: --status
help: Custom status command
-r:
full: --remove
help: Remove service
action: store_true
### app_checkport()
checkport:
action_help: Check availability of a local port

View file

@ -581,6 +581,37 @@ def app_setting(app, key, value=None, delete=False):
yaml.safe_dump(app_settings, f, default_flow_style=False)
def app_service(service, status=None, remove=False):
"""
Add or remove a YunoHost monitored service
Keyword argument:
service -- Service to add/remove
status -- Custom status command
remove -- Remove service
"""
service_file = '/etc/yunohost/services.yml'
try:
with open(service_file) as f:
services = yaml.load(f)
except IOError:
# Do not fail if service file is not there
services = {}
if remove and service in services:
del services[service]
else:
if status is None:
services[service] = { 'status': 'service' }
else:
services[service] = { 'status': status }
with open(service_file, 'w') as f:
yaml.safe_dump(services, f, default_flow_style=False)
def app_checkport(port):
"""
Check availability of a local port