#!/usr/bin/python3

import sys
import toml
import subprocess

config = toml.load(open("/etc/servicetray.toml"))

# only allow operating on configured services of type system
services = []
for service in config.get('services', []):
    if service.get('type', 'system') == 'system':
        services.append(service['name'])

action = sys.argv[1]
service = sys.argv[2]

# verify that action is allowed
assert action in ('start', 'stop', 'restart', 'kill', 'reload')
assert service in services

r = subprocess.run(['systemctl', action, service])
sys.exit(r.returncode)
