libretime/python_apps/pypo/airtime-pypo-stop

41 lines
1.4 KiB
Python
Executable File

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import subprocess
if os.geteuid() != 0:
print "Please run this as root."
sys.exit(1)
try:
print "Stopping daemontool script pypo...",
p1 = subprocess.Popen(["ps", "aux"], stdout=subprocess.PIPE)
p2 = subprocess.Popen(["awk", "/pypo-cli.py/ && !/awk/ {print $2}"], stdin=p1.stdout, stdout=subprocess.PIPE)
pypo_pid = p2.communicate()[0].strip(" \n\r\t")
if (len(pypo_pid) > 0):
os.system("svc -d /etc/service/pypo 1>/dev/null 2>&1")
os.system("svc -d /etc/service/pypo/log 1>/dev/null 2>&1")
print "Success."
else:
print "Not Running."
print "Stopping daemontool script pypo-liquidsoap...",
p1 = subprocess.Popen(["ps", "aux"], stdout=subprocess.PIPE)
p2 = subprocess.Popen(["awk", "/ls_script.liq/ && !/awk/ {print $2}"], stdin=p1.stdout, stdout=subprocess.PIPE)
liquidsoap_pid = p2.communicate()[0].strip(" \n\r\t")
if (len(liquidsoap_pid) > 0):
os.system("svc -d /etc/service/pypo-liquidsoap 1>/dev/null 2>&1")
os.system("svc -d /etc/service/pypo-liquidsoap/log 1>/dev/null 2>&1")
pids = liquidsoap_pid.split("\n")
for pid in pids:
os.system("kill -2 %s" % pid)
print "Success."
else:
print "Not Running."
except Exception, e:
print "exception:" + str(e)