From 5803635d5073b4fa3e81f43d99449f61f67a33ea Mon Sep 17 00:00:00 2001 From: martin Date: Mon, 30 May 2011 18:55:52 -0400 Subject: [PATCH] cc-2055: switch to init.d -disable daemon from starting twice --- python_apps/pypo/airtime-playout-start | 19 ------- python_apps/pypo/airtime-playout-stop | 42 --------------- python_apps/pypo/airtime-pypo | 17 +++++++ python_apps/pypo/airtime-pypo-init-d | 51 +++++++++++++++++++ .../install/pypo-daemontools-liquidsoap.sh | 4 +- python_apps/pypo/install/pypo-daemontools.sh | 3 +- python_apps/pypo/install/pypo-install.py | 39 +++++++------- 7 files changed, 91 insertions(+), 84 deletions(-) delete mode 100755 python_apps/pypo/airtime-playout-start delete mode 100755 python_apps/pypo/airtime-playout-stop create mode 100755 python_apps/pypo/airtime-pypo create mode 100755 python_apps/pypo/airtime-pypo-init-d diff --git a/python_apps/pypo/airtime-playout-start b/python_apps/pypo/airtime-playout-start deleted file mode 100755 index 9d5811638..000000000 --- a/python_apps/pypo/airtime-playout-start +++ /dev/null @@ -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) diff --git a/python_apps/pypo/airtime-playout-stop b/python_apps/pypo/airtime-playout-stop deleted file mode 100755 index 009be17fc..000000000 --- a/python_apps/pypo/airtime-playout-stop +++ /dev/null @@ -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) diff --git a/python_apps/pypo/airtime-pypo b/python_apps/pypo/airtime-pypo new file mode 100755 index 000000000..f20555474 --- /dev/null +++ b/python_apps/pypo/airtime-pypo @@ -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 diff --git a/python_apps/pypo/airtime-pypo-init-d b/python_apps/pypo/airtime-pypo-init-d new file mode 100755 index 000000000..1f5733857 --- /dev/null +++ b/python_apps/pypo/airtime-pypo-init-d @@ -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 diff --git a/python_apps/pypo/install/pypo-daemontools-liquidsoap.sh b/python_apps/pypo/install/pypo-daemontools-liquidsoap.sh index 6c4ebe65a..377ae9a3c 100755 --- a/python_apps/pypo/install/pypo-daemontools-liquidsoap.sh +++ b/python_apps/pypo/install/pypo-daemontools-liquidsoap.sh @@ -10,8 +10,6 @@ exec 2>&1 cd /usr/lib/airtime/pypo/bin/scripts export PYTHONPATH=${api_client_path} -#su ${ls_user} -c "${ls_path} ${ls_param}" 2>&1 - -setuidgid ${ls_user} ${ls_path} ${ls_param} +exec ${ls_path} ${ls_param} # EOF diff --git a/python_apps/pypo/install/pypo-daemontools.sh b/python_apps/pypo/install/pypo-daemontools.sh index 891c3b259..9ad0dd683 100755 --- a/python_apps/pypo/install/pypo-daemontools.sh +++ b/python_apps/pypo/install/pypo-daemontools.sh @@ -13,6 +13,5 @@ PYTHONPATH=${api_client_path}:$PYTHONPATH export PYTHONPATH # Note the -u when calling python! we need it to get unbuffered binary stdout and stderr -exec setuidgid ${pypo_user} \ - python -u ${pypo_path}${pypo_script} +exec python -u ${pypo_path}${pypo_script} # EOF diff --git a/python_apps/pypo/install/pypo-install.py b/python_apps/pypo/install/pypo-install.py index 3cddd3b71..0a0bbce2c 100755 --- a/python_apps/pypo/install/pypo-install.py +++ b/python_apps/pypo/install/pypo-install.py @@ -135,21 +135,35 @@ try: os.system("chmod -R 755 "+config["bin_dir"]) os.system("chown -R pypo:pypo "+config["bin_dir"]) os.system("chown -R pypo:pypo "+config["cache_base_dir"]) - + + """ print "Creating symbolic links" os.system("rm -f /usr/bin/airtime-playout-start") os.system("ln -s "+config["bin_dir"]+"/bin/airtime-playout-start /usr/bin/") os.system("rm -f /usr/bin/airtime-playout-stop") 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" + 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/log") 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") os.system("chmod -R 755 /etc/service/pypo") os.system("chown -R pypo:pypo /etc/service/pypo") + """ + + """ print "Installing liquidsoap daemon" create_path("/etc/service/pypo-liquidsoap") 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") os.system("chmod -R 755 /etc/service/pypo-liquidsoap") os.system("chown -R pypo:pypo /etc/service/pypo-liquidsoap") - + """ + print "Waiting for processes to start..." - time.sleep(5) - os.system("python /usr/bin/airtime-playout-start") - time.sleep(2) + os.system("service airtime-pypo start") + Popen("service airtime-pypo start".split(" ")) - 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: print "exception:" + str(e) sys.exit(1)