-
Notifications
You must be signed in to change notification settings - Fork 60
/
graphical-app-launcher.py
executable file
·39 lines (32 loc) · 1.28 KB
/
graphical-app-launcher.py
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
#!/usr/bin/env python
import os
import subprocess
import time
import sys
import signal
if __name__ == '__main__':
if os.environ.has_key('APP'):
graphical_app = os.environ['APP']
if os.environ.has_key('ARGS'):
extra_args = os.environ['ARGS']
command = graphical_app + ' ' + extra_args
else:
command = graphical_app
process = subprocess.Popen(command, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
def print_return_code_and_shutdown(return_code):
for line in process.stdout.readlines():
sys.stdout.write(line)
with open('/tmp/graphical-app.return_code', 'w') as fp:
fp.write(str(return_code))
subprocess.call(['sudo', 'supervisorctl', 'shutdown'],
stdout=subprocess.PIPE)
sys.exit(return_code)
def signal_handler(signum, frame):
print_return_code_and_shutdown(128 + signum)
signal.signal(signal.SIGTERM, signal_handler)
while(process.poll() == None):
for line in process.stdout.readlines():
sys.stdout.write(line)
time.sleep(1)
print_return_code_and_shutdown(process.returncode)