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
|
# Short-Description: Manage airtime-playout daemon
|
||||||
### END INIT INFO
|
### END INIT INFO
|
||||||
|
|
||||||
USERID=pypo
|
USERID=root
|
||||||
ROOTUSERID=root
|
NAME="Airtime Scheduler Engine"
|
||||||
GROUPID=pypo
|
|
||||||
NAME=Airtime\ Playout
|
|
||||||
|
|
||||||
DAEMON0=/usr/lib/airtime/pypo/bin/airtime-playout
|
DAEMON=/usr/lib/airtime/pypo/bin/airtime-playout
|
||||||
PIDFILE0=/var/run/airtime-playout.pid
|
PIDFILE=/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
|
|
||||||
}
|
|
||||||
|
|
||||||
start () {
|
start () {
|
||||||
chown pypo:pypo /etc/airtime
|
chown pypo:pypo /etc/airtime
|
||||||
chown pypo:pypo /etc/airtime/liquidsoap.cfg
|
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
|
monit monitor airtime-playout >/dev/null 2>&1
|
||||||
|
|
||||||
liquidsoap_start
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stop () {
|
stop () {
|
||||||
# Send TERM after 5 seconds, wait at most 30 seconds.
|
# Send TERM after 5 seconds, wait at most 30 seconds.
|
||||||
|
|
||||||
monit unmonitor airtime-playout >/dev/null 2>&1
|
monit unmonitor airtime-playout >/dev/null 2>&1
|
||||||
start-stop-daemon --stop --oknodo --retry TERM/5/0/30 --quiet --pidfile $PIDFILE0
|
start-stop-daemon --stop --oknodo --retry TERM/5/0/30 --quiet --pidfile $PIDFILE
|
||||||
rm -f $PIDFILE0
|
rm -f $PIDFILE
|
||||||
|
|
||||||
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_no_monit() {
|
start_no_monit() {
|
||||||
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
|
||||||
liquidsoap_start
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case "${1:-''}" in
|
case "${1:-''}" in
|
||||||
|
@ -111,41 +61,13 @@ case "${1:-''}" in
|
||||||
start_no_monit
|
start_no_monit
|
||||||
echo "Done."
|
echo "Done."
|
||||||
;;
|
;;
|
||||||
'monit-restart')
|
|
||||||
# restart commands here
|
|
||||||
echo -n "Monit Restarting $NAME: "
|
|
||||||
monit_restart
|
|
||||||
echo "Done."
|
|
||||||
;;
|
|
||||||
'status')
|
'status')
|
||||||
# status commands here
|
# status commands here
|
||||||
/usr/bin/airtime-check-system
|
/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
|
*) # no parameter specified
|
||||||
echo "Usage: $SELF start|stop|restart|status"
|
echo "Usage: $SELF start|stop|restart|status"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
|
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -98,6 +98,7 @@ try:
|
||||||
|
|
||||||
#copy init.d script
|
#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-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
|
#copy log rotate script
|
||||||
shutil.copy(config["bin_dir"]+"/bin/liquidsoap_scripts/airtime-liquidsoap.logrotate", "/etc/logrotate.d/airtime-liquidsoap")
|
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":
|
if "airtime_service_start" in os.environ and os.environ["airtime_service_start"] == "t":
|
||||||
print "* Waiting for pypo processes to start..."
|
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)
|
subprocess.call("invoke-rc.d airtime-playout start-no-monit > /dev/null 2>&1", shell=True)
|
||||||
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
|
|
@ -76,6 +76,9 @@ server.register(namespace="streams",
|
||||||
server.register(namespace="vars",
|
server.register(namespace="vars",
|
||||||
"default_dj_fade",
|
"default_dj_fade",
|
||||||
fun (s) -> begin default_dj_fade := float_of_string(s) s end)
|
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",
|
server.register(namespace="dynamic_source",
|
||||||
description="Enable webstream output",
|
description="Enable webstream output",
|
||||||
|
@ -105,7 +108,7 @@ server.register(namespace="dynamic_source",
|
||||||
destroy_dynamic_source)
|
destroy_dynamic_source)
|
||||||
|
|
||||||
default = amplify(id="silence_src", 0.00001, noise())
|
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))
|
ignore(output.dummy(default, fallible=true))
|
||||||
|
|
||||||
master_dj_enabled = ref false
|
master_dj_enabled = ref false
|
||||||
|
|
|
@ -5,5 +5,5 @@
|
||||||
|
|
||||||
check process airtime-liquidsoap
|
check process airtime-liquidsoap
|
||||||
with pidfile "/var/run/airtime-liquidsoap.pid"
|
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"
|
stop program = "/etc/init.d/airtime-playout stop"
|
||||||
|
|
|
@ -86,7 +86,7 @@ class PypoFetch(Thread):
|
||||||
self.process_schedule(self.schedule_data)
|
self.process_schedule(self.schedule_data)
|
||||||
elif command == 'update_stream_setting':
|
elif command == 'update_stream_setting':
|
||||||
self.logger.info("Updating stream setting...")
|
self.logger.info("Updating stream setting...")
|
||||||
self.regenerateLiquidsoapConf(m['setting'])
|
self.regenerate_liquidsoap_conf(m['setting'])
|
||||||
elif command == 'update_stream_format':
|
elif command == 'update_stream_format':
|
||||||
self.logger.info("Updating stream format...")
|
self.logger.info("Updating stream format...")
|
||||||
self.update_liquidsoap_stream_format(m['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(api_client.encode_to(buffer_str))
|
||||||
fh.write("log_file = \"/var/log/airtime/pypo-liquidsoap/<script>.log\"\n");
|
fh.write("log_file = \"/var/log/airtime/pypo-liquidsoap/<script>.log\"\n");
|
||||||
fh.close()
|
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 = {}
|
existing = {}
|
||||||
# create a temp file
|
# create a temp file
|
||||||
|
|
||||||
|
@ -219,6 +232,7 @@ class PypoFetch(Thread):
|
||||||
except IOError, e:
|
except IOError, e:
|
||||||
#file does not exist
|
#file does not exist
|
||||||
self.write_liquidsoap_config(setting)
|
self.write_liquidsoap_config(setting)
|
||||||
|
self.stop_liquidsoap()
|
||||||
|
|
||||||
self.logger.info("Reading existing config...")
|
self.logger.info("Reading existing config...")
|
||||||
# read existing conf file and build dict
|
# read existing conf file and build dict
|
||||||
|
@ -299,6 +313,7 @@ class PypoFetch(Thread):
|
||||||
# rewrite
|
# rewrite
|
||||||
if restart:
|
if restart:
|
||||||
self.write_liquidsoap_config(setting)
|
self.write_liquidsoap_config(setting)
|
||||||
|
self.stop_liquidsoap()
|
||||||
else:
|
else:
|
||||||
self.logger.info("No change detected in setting...")
|
self.logger.info("No change detected in setting...")
|
||||||
self.update_liquidsoap_connection_status()
|
self.update_liquidsoap_connection_status()
|
||||||
|
|
Loading…
Reference in New Issue