mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Add service helper
This commit is contained in:
parent
3ee60eafd1
commit
2393c8ae2d
2 changed files with 46 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue