CC-4114: use liquidsoap shutdown() command to restart liquidsoap
-moved liquidsoap into its own init.d script. Still need to do some testing.
This commit is contained in:
parent
a6d10d8378
commit
1dd1ba4420
|
@ -0,0 +1,70 @@
|
|||
#!/bin/bash
|
||||
|
||||
### BEGIN INIT INFO
|
||||
# Provides: airtime-playout
|
||||
# Required-Start: $local_fs $remote_fs $network $syslog
|
||||
# Required-Stop: $local_fs $remote_fs $network $syslog
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Liquidsoap daemon
|
||||
### END INIT INFO
|
||||
|
||||
USERID=pypo
|
||||
GROUPID=pypo
|
||||
NAME="Liquidsoap Playout Engine"
|
||||
|
||||
DAEMON=/usr/lib/airtime/pypo/bin/airtime-liquidsoap
|
||||
PIDFILE=/var/run/airtime-liquidsoap.pid
|
||||
|
||||
start () {
|
||||
start-stop-daemon --start --background --quiet --chuid $USERID:$GROUPID \
|
||||
--nicelevel -15 --make-pidfile --pidfile $PIDFILE --startas $DAEMON
|
||||
|
||||
monit monitor airtime-liquidsoap >/dev/null 2>&1
|
||||
}
|
||||
|
||||
stop () {
|
||||
monit unmonitor airtime-liquidsoap >/dev/null 2>&1
|
||||
/usr/lib/airtime/airtime_virtualenv/bin/python /usr/lib/airtime/pypo/bin/liquidsoap_scripts/liquidsoap_prepare_terminate.py
|
||||
|
||||
# Send TERM after 5 seconds, wait at most 30 seconds.
|
||||
start-stop-daemon --stop --oknodo --retry TERM/5/0/30 --quiet --pidfile $PIDFILE
|
||||
rm -f $PIDFILE
|
||||
}
|
||||
|
||||
start_no_monit() {
|
||||
start-stop-daemon --start --background --quiet --chuid $USERID:$USERID --make-pidfile --pidfile $PIDFILE --startas $DAEMON
|
||||
}
|
||||
|
||||
|
||||
case "${1:-''}" in
|
||||
'stop')
|
||||
echo -n "Stopping Liquidsoap: "
|
||||
stop
|
||||
echo "Done."
|
||||
;;
|
||||
'start')
|
||||
echo -n "Starting Liquidsoap: "
|
||||
start
|
||||
echo "Done."
|
||||
;;
|
||||
'restart')
|
||||
# restart commands here
|
||||
echo -n "Restarting Liquidsoap: "
|
||||
stop
|
||||
start
|
||||
echo "Done."
|
||||
;;
|
||||
'start-no-monit')
|
||||
# restart commands here
|
||||
echo -n "Starting $NAME: "
|
||||
start_no_monit
|
||||
echo "Done."
|
||||
;;
|
||||
|
||||
*) # no parameter specified
|
||||
echo "Usage: $SELF start|stop|restart"
|
||||
exit 1
|
||||
;;
|
||||
|
||||
esac
|
|
@ -9,80 +9,30 @@
|
|||
# Short-Description: Manage airtime-playout daemon
|
||||
### END INIT INFO
|
||||
|
||||
USERID=pypo
|
||||
ROOTUSERID=root
|
||||
GROUPID=pypo
|
||||
NAME=Airtime\ Playout
|
||||
USERID=root
|
||||
NAME="Airtime Scheduler Engine"
|
||||
|
||||
DAEMON0=/usr/lib/airtime/pypo/bin/airtime-playout
|
||||
PIDFILE0=/var/run/airtime-playout.pid
|
||||
|
||||
DAEMON1=/usr/lib/airtime/pypo/bin/airtime-liquidsoap
|
||||
PIDFILE1=/var/run/airtime-liquidsoap.pid
|
||||
|
||||
liquidsoap_start () {
|
||||
start-stop-daemon --start --background --quiet --chuid $USERID:$GROUPID \
|
||||
--nicelevel -15 --make-pidfile --pidfile $PIDFILE1 --startas $DAEMON1
|
||||
|
||||
monit monitor airtime-liquidsoap >/dev/null 2>&1
|
||||
}
|
||||
|
||||
liquidsoap_stop () {
|
||||
monit unmonitor airtime-liquidsoap >/dev/null 2>&1
|
||||
/usr/lib/airtime/airtime_virtualenv/bin/python /usr/lib/airtime/pypo/bin/liquidsoap_scripts/liquidsoap_prepare_terminate.py
|
||||
|
||||
# Send TERM after 5 seconds, wait at most 30 seconds.
|
||||
start-stop-daemon --stop --oknodo --retry TERM/5/0/30 --quiet --pidfile $PIDFILE1
|
||||
rm -f $PIDFILE1
|
||||
}
|
||||
|
||||
stop_pypo () {
|
||||
monit unmonitor airtime-playout >/dev/null 2>&1
|
||||
|
||||
# Send TERM after 5 seconds, wait at most 30 seconds.
|
||||
start-stop-daemon --stop --oknodo --retry TERM/5/0/30 --quiet --pidfile $PIDFILE0
|
||||
rm -f $PIDFILE0
|
||||
}
|
||||
DAEMON=/usr/lib/airtime/pypo/bin/airtime-playout
|
||||
PIDFILE=/var/run/airtime-playout.pid
|
||||
|
||||
start () {
|
||||
chown pypo:pypo /etc/airtime
|
||||
chown pypo:pypo /etc/airtime/liquidsoap.cfg
|
||||
|
||||
start-stop-daemon --start --background --quiet --chuid $ROOTUSERID:$ROOTUSERID --make-pidfile --pidfile $PIDFILE0 --startas $DAEMON0
|
||||
start-stop-daemon --start --background --quiet --chuid $USERID:$USERID --make-pidfile --pidfile $PIDFILE --startas $DAEMON
|
||||
monit monitor airtime-playout >/dev/null 2>&1
|
||||
|
||||
liquidsoap_start
|
||||
}
|
||||
|
||||
stop () {
|
||||
# Send TERM after 5 seconds, wait at most 30 seconds.
|
||||
|
||||
monit unmonitor airtime-playout >/dev/null 2>&1
|
||||
start-stop-daemon --stop --oknodo --retry TERM/5/0/30 --quiet --pidfile $PIDFILE0
|
||||
rm -f $PIDFILE0
|
||||
|
||||
liquidsoap_stop
|
||||
}
|
||||
|
||||
monit_restart() {
|
||||
|
||||
start-stop-daemon --stop --oknodo --retry TERM/5/0/30 --quiet --pidfile $PIDFILE0
|
||||
rm -f $PIDFILE0
|
||||
|
||||
/usr/lib/airtime/airtime_virtualenv/bin/python /usr/lib/airtime/pypo/bin/liquidsoap_scripts/liquidsoap_prepare_terminate.py
|
||||
start-stop-daemon --stop --oknodo --retry TERM/5/0/30 --quiet --pidfile $PIDFILE1
|
||||
rm -f $PIDFILE1
|
||||
|
||||
start-stop-daemon --start --background --quiet --chuid $ROOTUSERID:$ROOTUSERID --make-pidfile --pidfile $PIDFILE0 --startas $DAEMON0
|
||||
|
||||
start-stop-daemon --start --background --quiet --chuid $USERID:$GROUPID \
|
||||
--nicelevel -15 --make-pidfile --pidfile $PIDFILE1 --startas $DAEMON1
|
||||
|
||||
start-stop-daemon --stop --oknodo --retry TERM/5/0/30 --quiet --pidfile $PIDFILE
|
||||
rm -f $PIDFILE
|
||||
}
|
||||
|
||||
start_no_monit() {
|
||||
start-stop-daemon --start --background --quiet --chuid $ROOTUSERID:$ROOTUSERID --make-pidfile --pidfile $PIDFILE0 --startas $DAEMON0
|
||||
liquidsoap_start
|
||||
start-stop-daemon --start --background --quiet --chuid $USERID:$USERID --make-pidfile --pidfile $PIDFILE --startas $DAEMON
|
||||
}
|
||||
|
||||
case "${1:-''}" in
|
||||
|
@ -111,41 +61,13 @@ case "${1:-''}" in
|
|||
start_no_monit
|
||||
echo "Done."
|
||||
;;
|
||||
'monit-restart')
|
||||
# restart commands here
|
||||
echo -n "Monit Restarting $NAME: "
|
||||
monit_restart
|
||||
echo "Done."
|
||||
;;
|
||||
'status')
|
||||
# status commands here
|
||||
/usr/bin/airtime-check-system
|
||||
;;
|
||||
'stop-liquidsoap')
|
||||
echo -n "Stopping Liquidsoap: "
|
||||
liquidsoap_stop
|
||||
echo "Done."
|
||||
;;
|
||||
'start-liquidsoap')
|
||||
echo -n "Starting Liquidsoap: "
|
||||
liquidsoap_start
|
||||
echo "Done."
|
||||
;;
|
||||
'restart-liquidsoap')
|
||||
# restart commands here
|
||||
echo -n "Restarting Liquidsoap: "
|
||||
liquidsoap_stop
|
||||
liquidsoap_start
|
||||
echo "Done."
|
||||
;;
|
||||
'pypo-stop')
|
||||
# restart commands here
|
||||
echo -n "Restarting Pypo: "
|
||||
stop_pypo
|
||||
echo "Done."
|
||||
;;
|
||||
*) # no parameter specified
|
||||
echo "Usage: $SELF start|stop|restart|status"
|
||||
exit 1
|
||||
;;
|
||||
|
||||
esac
|
||||
|
|
|
@ -98,6 +98,7 @@ try:
|
|||
|
||||
#copy init.d script
|
||||
shutil.copy(config["bin_dir"]+"/bin/airtime-playout-init-d", "/etc/init.d/airtime-playout")
|
||||
shutil.copy(config["bin_dir"]+"/bin/airtime-liquidsoap-init-d", "/etc/init.d/airtime-liquidsoap")
|
||||
|
||||
#copy log rotate script
|
||||
shutil.copy(config["bin_dir"]+"/bin/liquidsoap_scripts/airtime-liquidsoap.logrotate", "/etc/logrotate.d/airtime-liquidsoap")
|
||||
|
|
|
@ -109,6 +109,7 @@ try:
|
|||
|
||||
if "airtime_service_start" in os.environ and os.environ["airtime_service_start"] == "t":
|
||||
print "* Waiting for pypo processes to start..."
|
||||
subprocess.call("invoke-rc.d airtime-liquidsoap start-no-monit > /dev/null 2>&1", shell=True)
|
||||
subprocess.call("invoke-rc.d airtime-playout start-no-monit > /dev/null 2>&1", shell=True)
|
||||
|
||||
except Exception, e:
|
||||
|
|
|
@ -76,6 +76,9 @@ server.register(namespace="streams",
|
|||
server.register(namespace="vars",
|
||||
"default_dj_fade",
|
||||
fun (s) -> begin default_dj_fade := float_of_string(s) s end)
|
||||
server.register(namespace="system",
|
||||
"shutdown",
|
||||
fun (s) -> begin shutdown() "Shutting Down" end)
|
||||
|
||||
server.register(namespace="dynamic_source",
|
||||
description="Enable webstream output",
|
||||
|
@ -105,7 +108,7 @@ server.register(namespace="dynamic_source",
|
|||
destroy_dynamic_source)
|
||||
|
||||
default = amplify(id="silence_src", 0.00001, noise())
|
||||
default = rewrite_metadata([("artist","Airtime"), ("title", "offline")],default)
|
||||
default = rewrite_metadata([("artist","Airtime"), ("title", "offline")], default)
|
||||
ignore(output.dummy(default, fallible=true))
|
||||
|
||||
master_dj_enabled = ref false
|
||||
|
|
|
@ -5,5 +5,5 @@
|
|||
|
||||
check process airtime-liquidsoap
|
||||
with pidfile "/var/run/airtime-liquidsoap.pid"
|
||||
start program = "/etc/init.d/airtime-playout monit-restart" with timeout 5 seconds
|
||||
start program = "/etc/init.d/airtime-liquidsoap start" with timeout 5 seconds
|
||||
stop program = "/etc/init.d/airtime-playout stop"
|
||||
|
|
|
@ -86,7 +86,7 @@ class PypoFetch(Thread):
|
|||
self.process_schedule(self.schedule_data)
|
||||
elif command == 'update_stream_setting':
|
||||
self.logger.info("Updating stream setting...")
|
||||
self.regenerateLiquidsoapConf(m['setting'])
|
||||
self.regenerate_liquidsoap_conf(m['setting'])
|
||||
elif command == 'update_stream_format':
|
||||
self.logger.info("Updating stream format...")
|
||||
self.update_liquidsoap_stream_format(m['stream_format'])
|
||||
|
@ -204,12 +204,25 @@ class PypoFetch(Thread):
|
|||
fh.write(api_client.encode_to(buffer_str))
|
||||
fh.write("log_file = \"/var/log/airtime/pypo-liquidsoap/<script>.log\"\n");
|
||||
fh.close()
|
||||
# restarting pypo.
|
||||
# we could just restart liquidsoap but it take more time somehow.
|
||||
self.logger.info("Restarting pypo...")
|
||||
sys.exit(0)
|
||||
|
||||
def regenerateLiquidsoapConf(self, setting):
|
||||
def stop_liquidsoap(self):
|
||||
self.telnet_lock.acquire()
|
||||
try:
|
||||
tn = telnetlib.Telnet(LS_HOST, LS_PORT)
|
||||
# update the boot up time of liquidsoap. Since liquidsoap is not restarting,
|
||||
# we are manually adjusting the bootup time variable so the status msg will get
|
||||
# updated.
|
||||
tn.write("system.shutdown\n")
|
||||
tn.write('exit\n')
|
||||
|
||||
output = tn.read_all()
|
||||
except Exception, e:
|
||||
self.logger.error(str(e))
|
||||
finally:
|
||||
self.telnet_lock.release()
|
||||
|
||||
|
||||
def regenerate_liquidsoap_conf(self, setting):
|
||||
existing = {}
|
||||
# create a temp file
|
||||
|
||||
|
@ -219,6 +232,7 @@ class PypoFetch(Thread):
|
|||
except IOError, e:
|
||||
#file does not exist
|
||||
self.write_liquidsoap_config(setting)
|
||||
self.stop_liquidsoap()
|
||||
|
||||
self.logger.info("Reading existing config...")
|
||||
# read existing conf file and build dict
|
||||
|
@ -299,6 +313,7 @@ class PypoFetch(Thread):
|
|||
# rewrite
|
||||
if restart:
|
||||
self.write_liquidsoap_config(setting)
|
||||
self.stop_liquidsoap()
|
||||
else:
|
||||
self.logger.info("No change detected in setting...")
|
||||
self.update_liquidsoap_connection_status()
|
||||
|
|
Loading…
Reference in New Issue