~thrrgilag/pantalaimon-ut

pantalaimon-ut/src/service.py -rw-r--r-- 1.2 KiB
cb1aa162Morgan McMillian updated links in README 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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)