Last active
August 29, 2015 13:57
-
-
Save jmrunge/9599606 to your computer and use it in GitHub Desktop.
Script to start/stop/restart mbc-playout processes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/bash | |
check_running_screen() { | |
local command="screen -ls | grep $1" | |
if [ -n "$(eval $command)" ]; then | |
echo 1 | |
else | |
echo 0 | |
fi | |
} | |
start_screen() { | |
if [ $(check_running_screen $1) != 0 ]; then | |
printf "Screen %s already started\n" "$1" | |
else | |
screen -d -m -S $1 | |
printf "Starting screen %s\n" "$1" | |
fi | |
} | |
get_command() { | |
case "$1" in | |
caspa) | |
echo "cd mbc-caspa && make MBC_SCRAPE=1 serve_noweb" | |
;; | |
mosto) | |
echo "killall -9 melted && cd mbc-mosto && make NODE_CONFIG_DIR=~/mbc-caspa/node_modules/mbc-common/config serve" | |
;; | |
patero) | |
echo "cd mbc-patero && python patero.py" | |
;; | |
capture) | |
echo "melt -producer decklink buffer=25 -consumer posixshm" | |
;; | |
htop) | |
echo "htop" | |
;; | |
preview) | |
echo "export DISPLAY=:1 && melt -producer posixshm:output.mlt -consumer avformat:http://localhost:8000/publish/mbc?password=malbec real_time=1 terminate_on_pause=0 f=webm vcodec=libvpx b=1000k s=720x570 acodec=libvorbis ab=128k g=0 me_method=zero flags2=fast preset=ultrafast tune=zerolatency crf=40 qmin=5 mlt_profile=dv_pal" | |
;; | |
output) | |
echo "export DISPLAY=:1 && melt -producer posixshm:output.mlt -consumer decklink:1 mlt_profile=dv_pal -filter webvfx:http://localhost:3100/filter" | |
;; | |
etiquette) | |
echo "cd mbc-etiquette && make NODE_CONFIG_DIR=~/mbc-caspa/node_modules/mbc-common/config serve_noweb" | |
;; | |
stream) | |
echo "cd stream-m && make" | |
;; | |
melted) | |
echo "melted -test" | |
;; | |
melted2) | |
echo " echo 'uadd posixshm:output.mlt' | nc localhost 5250 " | |
;; | |
*) | |
echo "" | |
;; | |
esac | |
} | |
start_process() { | |
local command=$(get_command $1) | |
if [ -z "$command" ]; then | |
printf "Process %s not found\n" "$1" | |
exit 1 | |
fi | |
start_screen $1 | |
local cmd="$command `echo -ne '\015'`" | |
screen -S $1 -X stuff "cd ~ `echo -ne '\015'`" | |
screen -S $1 -X stuff "$cmd" | |
printf "Process %s started\n" "$1" | |
} | |
stop_process() { | |
local command=$(get_command $1) | |
if [ -z "$command" ]; then | |
printf "Process %s not found\n" "$1" | |
exit 1 | |
fi | |
start_screen $1 | |
screen -S $1 -X stuff "^C" | |
printf "Process %s stopped\n" "$1" | |
} | |
process=${2:-all} | |
if [ $process == "all" ]; then | |
processes=(melted htop capture stream patero caspa mosto etiquette output preview) | |
else | |
processes=($process) | |
fi | |
case "$1" in | |
start) | |
for proc in ${processes[*]} | |
do | |
start_process $proc | |
sleep 10 | |
done | |
;; | |
stop) | |
for (( idx=${#processes[@]}-1 ; idx>=0 ; idx-- )) ; | |
do | |
stop_process ${processes[idx]} | |
done | |
;; | |
restart) | |
for (( idx=${#processes[@]}-1 ; idx>=0 ; idx-- )) ; | |
do | |
stop_process ${processes[idx]} | |
sleep 10 | |
done | |
for proc in ${processes[*]} | |
do | |
start_process $proc | |
sleep 10 | |
done | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|restart} [proc name]" | |
exit 1 | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment