54 lines
1.2 KiB
Python
54 lines
1.2 KiB
Python
import subprocess
|
|
import logging
|
|
import os
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
UPSTARTFILE = '/home/phablet/.config/upstart/pantalaimon.conf'
|
|
|
|
def status():
|
|
statuscmd = ['status', 'pantalaimon']
|
|
r = subprocess.run(statuscmd, stdout=subprocess.PIPE)
|
|
logging.debug(r)
|
|
running = "running" in r.stdout.decode()
|
|
return (running, r.stdout)
|
|
|
|
def start():
|
|
success = False
|
|
statuscmd = ['start', 'pantalaimon']
|
|
r = subprocess.run(statuscmd)
|
|
logging.debug(r)
|
|
if r.returncode == 0:
|
|
success = True
|
|
return success
|
|
|
|
def stop():
|
|
success = False
|
|
statuscmd = ['stop', 'pantalaimon']
|
|
r = subprocess.run(statuscmd)
|
|
logging.debug(r)
|
|
if r.returncode == 0:
|
|
success = True
|
|
return success
|
|
|
|
def add():
|
|
logging.debug('adding service file')
|
|
script = """
|
|
start on started unity8
|
|
respawn
|
|
exec /opt/click.ubuntu.com/pantalaimon.thrrgilag/current/pantalaimon
|
|
"""
|
|
with open(UPSTARTFILE, 'w') as upstart_file:
|
|
print(script, file=upstart_file)
|
|
start()
|
|
|
|
def remove():
|
|
logging.debug('removing service file')
|
|
stop()
|
|
os.remove(UPSTARTFILE)
|
|
|
|
def check_upstart():
|
|
return os.path.exists(UPSTARTFILE)
|
|
|
|
def check_env():
|
|
logging.debug(os.environ)
|