cc-2055: switch to init.d
-disable daemon from starting twice
This commit is contained in:
parent
b0befdff20
commit
5803635d50
7 changed files with 91 additions and 84 deletions
|
@ -1,19 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
if os.geteuid() != 0:
|
|
||||||
print "Please run this as root."
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
try:
|
|
||||||
print "Starting daemontool script pypo"
|
|
||||||
os.system("svc -u /etc/service/pypo")
|
|
||||||
|
|
||||||
print "Starting daemontool script pypo-liquidsoap"
|
|
||||||
os.system("svc -u /etc/service/pypo-liquidsoap")
|
|
||||||
|
|
||||||
except Exception, e:
|
|
||||||
print "exception:" + str(e)
|
|
|
@ -1,42 +0,0 @@
|
||||||
#!/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 "Shutting down process id %s" % pypo_pid
|
|
||||||
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 "Shutting down process id %s" % liquidsoap_pid
|
|
||||||
print "Success."
|
|
||||||
else:
|
|
||||||
print "Not Running."
|
|
||||||
|
|
||||||
except Exception, e:
|
|
||||||
print "exception:" + str(e)
|
|
17
python_apps/pypo/airtime-pypo
Executable file
17
python_apps/pypo/airtime-pypo
Executable file
|
@ -0,0 +1,17 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
pypo_user="pypo"
|
||||||
|
|
||||||
|
# Location of pypo_cli.py Python script
|
||||||
|
pypo_path="/usr/lib/airtime/pypo/bin/"
|
||||||
|
api_client_path="/usr/lib/airtime/pypo/"
|
||||||
|
pypo_script="pypo-cli.py"
|
||||||
|
cd ${pypo_path}
|
||||||
|
exec 2>&1
|
||||||
|
|
||||||
|
export HOME="/var/tmp/airtime/pypo/"
|
||||||
|
export PYTHONPATH=${api_client_path}:$PYTHONPATH
|
||||||
|
|
||||||
|
# Note the -u when calling python! we need it to get unbuffered binary stdout and stderr
|
||||||
|
exec python -u ${pypo_path}${pypo_script}
|
||||||
|
# EOF
|
51
python_apps/pypo/airtime-pypo-init-d
Executable file
51
python_apps/pypo/airtime-pypo-init-d
Executable file
|
@ -0,0 +1,51 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
USERID=pypo
|
||||||
|
GROUPID=pypo
|
||||||
|
ENABLE="false"
|
||||||
|
NAME=Airtime
|
||||||
|
ID=airtime
|
||||||
|
|
||||||
|
DAEMON=/usr/bin/airtime-pypo
|
||||||
|
PIDFILE=/var/run/$ID.pid
|
||||||
|
|
||||||
|
start () {
|
||||||
|
start-stop-daemon --start --background --quiet --chuid $USERID:$GROUPID --make-pidfile --pidfile $PIDFILE --startas $DAEMON
|
||||||
|
}
|
||||||
|
|
||||||
|
stop () {
|
||||||
|
# Send TERM after 5 seconds, wait at most 30 seconds.
|
||||||
|
start-stop-daemon --stop --oknodo --retry TERM/5/0/30 --quiet --pidfile $PIDFILE
|
||||||
|
rm $PIDFILE
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
case "${1:-''}" in
|
||||||
|
'start')
|
||||||
|
# start commands here
|
||||||
|
echo -n "Starting $NAME: "
|
||||||
|
start
|
||||||
|
echo "Done."
|
||||||
|
;;
|
||||||
|
'stop')
|
||||||
|
# stop commands here
|
||||||
|
echo -n "Stopping $NAME: "
|
||||||
|
stop
|
||||||
|
echo "Done."
|
||||||
|
;;
|
||||||
|
'restart')
|
||||||
|
# restart commands here
|
||||||
|
echo -n "Restarting $NAME: "
|
||||||
|
stop
|
||||||
|
start
|
||||||
|
echo "Done."
|
||||||
|
;;
|
||||||
|
'status')
|
||||||
|
# status commands here
|
||||||
|
/usr/bin/airtime-check-system
|
||||||
|
;;
|
||||||
|
*) # no parameter specified
|
||||||
|
echo "Usage: $SELF start|stop|restart|status"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
|
@ -10,8 +10,6 @@ exec 2>&1
|
||||||
cd /usr/lib/airtime/pypo/bin/scripts
|
cd /usr/lib/airtime/pypo/bin/scripts
|
||||||
|
|
||||||
export PYTHONPATH=${api_client_path}
|
export PYTHONPATH=${api_client_path}
|
||||||
#su ${ls_user} -c "${ls_path} ${ls_param}" 2>&1
|
exec ${ls_path} ${ls_param}
|
||||||
|
|
||||||
setuidgid ${ls_user} ${ls_path} ${ls_param}
|
|
||||||
|
|
||||||
# EOF
|
# EOF
|
||||||
|
|
|
@ -13,6 +13,5 @@ PYTHONPATH=${api_client_path}:$PYTHONPATH
|
||||||
export PYTHONPATH
|
export PYTHONPATH
|
||||||
|
|
||||||
# Note the -u when calling python! we need it to get unbuffered binary stdout and stderr
|
# Note the -u when calling python! we need it to get unbuffered binary stdout and stderr
|
||||||
exec setuidgid ${pypo_user} \
|
exec python -u ${pypo_path}${pypo_script}
|
||||||
python -u ${pypo_path}${pypo_script}
|
|
||||||
# EOF
|
# EOF
|
||||||
|
|
|
@ -136,20 +136,34 @@ try:
|
||||||
os.system("chown -R pypo:pypo "+config["bin_dir"])
|
os.system("chown -R pypo:pypo "+config["bin_dir"])
|
||||||
os.system("chown -R pypo:pypo "+config["cache_base_dir"])
|
os.system("chown -R pypo:pypo "+config["cache_base_dir"])
|
||||||
|
|
||||||
|
"""
|
||||||
print "Creating symbolic links"
|
print "Creating symbolic links"
|
||||||
os.system("rm -f /usr/bin/airtime-playout-start")
|
os.system("rm -f /usr/bin/airtime-playout-start")
|
||||||
os.system("ln -s "+config["bin_dir"]+"/bin/airtime-playout-start /usr/bin/")
|
os.system("ln -s "+config["bin_dir"]+"/bin/airtime-playout-start /usr/bin/")
|
||||||
os.system("rm -f /usr/bin/airtime-playout-stop")
|
os.system("rm -f /usr/bin/airtime-playout-stop")
|
||||||
os.system("ln -s "+config["bin_dir"]+"/bin/airtime-playout-stop /usr/bin/")
|
os.system("ln -s "+config["bin_dir"]+"/bin/airtime-playout-stop /usr/bin/")
|
||||||
|
"""
|
||||||
|
|
||||||
|
print "Creating symbolic links"
|
||||||
|
os.system("rm -f /usr/bin/airtime-pypo")
|
||||||
|
os.system("ln -s "+config["bin_dir"]+"/bin/airtime-pypo /usr/bin/")
|
||||||
|
|
||||||
|
|
||||||
print "Installing pypo daemon"
|
print "Installing pypo daemon"
|
||||||
|
shutil.copy(config["bin_dir"]+"/bin/airtime-pypo-init-d", "/etc/init.d/airtime-pypo")
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
create_path("/etc/service/pypo")
|
create_path("/etc/service/pypo")
|
||||||
create_path("/etc/service/pypo/log")
|
create_path("/etc/service/pypo/log")
|
||||||
shutil.copy("%s/pypo-daemontools.sh"%current_script_dir, "/etc/service/pypo/run")
|
shutil.copy("%s/pypo-daemontools.sh"%current_script_dir, "/etc/service/pypo/run")
|
||||||
shutil.copy("%s/pypo-daemontools-logger.sh"%current_script_dir, "/etc/service/pypo/log/run")
|
shutil.copy("%s/pypo-daemontools-logger.sh"%current_script_dir, "/etc/service/pypo/log/run")
|
||||||
os.system("chmod -R 755 /etc/service/pypo")
|
os.system("chmod -R 755 /etc/service/pypo")
|
||||||
os.system("chown -R pypo:pypo /etc/service/pypo")
|
os.system("chown -R pypo:pypo /etc/service/pypo")
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
print "Installing liquidsoap daemon"
|
print "Installing liquidsoap daemon"
|
||||||
create_path("/etc/service/pypo-liquidsoap")
|
create_path("/etc/service/pypo-liquidsoap")
|
||||||
create_path("/etc/service/pypo-liquidsoap/log")
|
create_path("/etc/service/pypo-liquidsoap/log")
|
||||||
|
@ -157,26 +171,15 @@ try:
|
||||||
shutil.copy("%s/pypo-liquidsoap-daemontools-logger.sh"%current_script_dir, "/etc/service/pypo-liquidsoap/log/run")
|
shutil.copy("%s/pypo-liquidsoap-daemontools-logger.sh"%current_script_dir, "/etc/service/pypo-liquidsoap/log/run")
|
||||||
os.system("chmod -R 755 /etc/service/pypo-liquidsoap")
|
os.system("chmod -R 755 /etc/service/pypo-liquidsoap")
|
||||||
os.system("chown -R pypo:pypo /etc/service/pypo-liquidsoap")
|
os.system("chown -R pypo:pypo /etc/service/pypo-liquidsoap")
|
||||||
|
"""
|
||||||
|
|
||||||
print "Waiting for processes to start..."
|
print "Waiting for processes to start..."
|
||||||
time.sleep(5)
|
os.system("service airtime-pypo start")
|
||||||
os.system("python /usr/bin/airtime-playout-start")
|
Popen("service airtime-pypo start".split(" "))
|
||||||
time.sleep(2)
|
|
||||||
|
|
||||||
found = True
|
print "sleeping"
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
p = Popen('svstat /etc/service/pypo', shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
|
|
||||||
output = p.stdout.read()
|
|
||||||
if (output.find("unable to open supervise/ok: file does not exist") >= 0):
|
|
||||||
found = False
|
|
||||||
print output
|
|
||||||
|
|
||||||
p = Popen('svstat /etc/service/pypo-liquidsoap', shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
|
|
||||||
output = p.stdout.read()
|
|
||||||
print output
|
|
||||||
|
|
||||||
if not found:
|
|
||||||
print "Pypo install has completed, but daemontools is not running, please make sure you have it installed and then reboot."
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print "exception:" + str(e)
|
print "exception:" + str(e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue