44# ## Also make sure that the locale it is activated in /etc/locale.gen
55# export LANG="en_US.UTF-8"
66
7+ # Read settings for this script
8+ source $HOME /src/mumble-ruby-pluginbot/scripts/manage.conf
9+
710function show_help() {
811 cat<< EOF
912USAGE
@@ -20,46 +23,8 @@ OPTIONS
2023EOF
2124}
2225
23- function stop_bots_and_mpds() {
24- # ## Kill running tmux bot "windows" (of the user botmaster) ###
25- echo " Killing tmux windows used by bots of user $USER "
26- tmux kill-window -t bot1 > /dev/null 2>&1
27- tmux kill-window -t bot2 > /dev/null 2>&1
28- tmux kill-window -t bot3 > /dev/null 2>&1
29- sleep 1
30- tmux kill-window -t bot1 > /dev/null 2>&1
31- tmux kill-window -t bot2 > /dev/null 2>&1
32- tmux kill-window -t bot3 > /dev/null 2>&1
33-
34- # ## Kill running mumble-ruby-pluginbots (of the user botmaster) ###
35- echo " Killing running ruby scripts of user $USER "
36- killall ruby > /dev/null 2>&1
37- sleep 1
38- killall ruby > /dev/null 2>&1
39-
40- # ## Kill all running mpd instances (of the user botmaster) ... ###
41- echo " Killing running mpd instances of user $USER "
42- killall mpd > /dev/null 2>&1
43- sleep 2
44- killall mpd > /dev/null 2>&1
45- }
46-
47- function update_youtubedl() {
48- # Do an update of youtube-dl on every start as there are very often updates.
49- if [ -f $HOME /src/youtube-dl ]; then
50- echo " Updating youtube-dl..."
51- $HOME /src/youtube-dl -U
52- fi
53- }
54-
55- function start_mpds() {
56- # ## Start needed mpd instances for botmaster ###
57- mpd $HOME /mpd1/mpd.conf
58- # mpd $HOME/mpd2/mpd.conf
59- # mpd $HOME/mpd3/mpd.conf
60- }
61-
62- function start_bots() {
26+ function start_bot_ruby() {
27+ local botid=${1}
6328 source ~ /.rvm/scripts/rvm
6429 rvm use @bots
6530
@@ -68,55 +33,98 @@ function start_bots() {
6833
6934 # ## Export enviroment variable for tmux
7035 export HOME=$HOME
36+ tmux new-session -d -s " bot${botid} " " while true; do LD_LIBRARY_PATH=$HOME /src/celt/lib/ ruby $HOME /src/mumble-ruby-pluginbot/core/pluginbot.rb --config=$HOME /src/bot${botid} _conf.yml >> $HOME /logs/bot${botid} .log 2>&1 ; sleep 10; done"
37+ }
7138
72- # ## Start Mumble-Ruby-Bots - MPD instances must already be running. ###
73- # Bot 1
74- tmux new-session -d -n bot1 " while true; do LD_LIBRARY_PATH=$HOME /src/celt/lib/ ruby $HOME /src/mumble-ruby-pluginbot/core/pluginbot.rb --config=$HOME /src/bot1_conf.yml >> $HOME /logs/bot1.log 2>&1 ; sleep 10; done"
39+ function stop_bot_ruby() {
40+ local botid=${1}
41+ tmux kill-session -t " bot${botid} " > /dev/null 2>&1
42+ }
7543
76- # Bot 2
77- # tmux new-session -d -n bot2 "while true; do LD_LIBRARY_PATH=$HOME/src/celt/lib/ ruby $HOME/src/mumble-ruby-pluginbot/core/pluginbot.rb --config=$HOME/src/bot2_conf.yml >> $HOME/logs/bot2.log 2>&1; sleep 10; done"
44+ function start_bot_mpd() {
45+ local botid=${1}
46+ mpd $HOME /mpd${botid} /mpd.conf > /dev/null 2>&1
47+ }
48+ function stop_bot_mpd() {
49+ local botid=${1}
50+ local mpdpid=$( ps aux | grep -i mpd | grep -v grep | grep -E " mpd.*mpd${botid} " | cut -d" " -f2)
51+ kill ${mpdpid} > /dev/null 2>&1
52+ }
7853
79- # Bot 3
80- # tmux new-session -d -n bot3 "while true; do LD_LIBRARY_PATH=$HOME/src/celt/lib/ ruby $HOME/src/mumble-ruby-pluginbot/core/pluginbot.rb --config=$HOME/src/bot3_conf.yml >> $HOME/logs/bot3.log 2>&1; sleep 10; done"
54+ function start_all_bots() {
55+ for botid in ${BOTS_ENABLED} ;
56+ do
57+ start_bot_ruby ${botid}
58+ start_bot_mpd ${botid}
59+ done
60+ }
8161
62+ function stop_all_bots() {
63+ for botid in ${BOTS_ENABLED} ;
64+ do
65+ stop_bot_ruby ${botid}
66+ stop_bot_mpd ${botid}
67+ done
8268}
8369
84- function show_disclaimer() {
85- cat << EOF
70+ function restart_all_bots() {
71+ stop_all_bots
72+ start_all_bots
73+ }
8674
75+ function status_bot() {
76+ local botid=${1}
77+ local _status=$( tmux list-sessions 2> /dev/null | sed -r -n -e " s/^(bot)${botid} .*/\1/p" )
8778
79+ if [ " ${_status} " == " bot" ]; then
80+ echo " Bot ${botid} is running"
81+ else
82+ echo " Bot ${botid} is not running"
83+ fi
84+ }
8885
89- Your bot(s) should now be connected to the configured Mumble server.
86+ function status_all_bots() {
87+ for botid in ${BOTS_ENABLED} ;
88+ do
89+ status_bot ${botid}
90+ done
91+ }
9092
93+ function update_youtubedl() {
94+ # Do an update of youtube-dl on every start as there are very often updates.
95+ if [ -f $HOME /src/youtube-dl ]; then
96+ echo " Updating youtube-dl..."
97+ $HOME /src/youtube-dl -U
98+ fi
99+ }
91100
92- _LOGGING/DEBUGGING_
93- If something doesn't work, activate the debug config option in the main configuration file and restart the bot.
101+ function show_disclaimer() {
102+ cat << EOF
94103
95- Then take a look into the logfile within $HOME /logs/ .
104+ Your bot(s) should now be connected to the configured Mumble server .
96105
106+ _LOGGING/DEBUGGING_
107+ If something doesn't work please read at
108+ http://mumble-ruby-pluginbot.rtfd.io/en/master/known_problems.html
97109
98110 _START AS APPROPRIATE USER_
99111 Make sure to run this script as user botmaster if you used the official
100112 installation documentation and DO NOT RUN THIS SCRIPT AS root.
101113 The official documentation can be found at http://mumble-ruby-pluginbot.readthedocs.io/
102114
103-
104115 _UPDATE THE BOT (AND ITS DEPENDENCIES)_
105116 If you want to update the Mumble-Ruby-Pluginbot (and its dependencies) please
106117 run ~/src/mumble-ruby-pluginbot/scripts/updater.sh
107118
108-
109119 _OFFICIAL DOCUMENTATION_
110- Also please reread the official documentation at http://mumble-ruby-pluginbot.readthedocs.io/
111- if you have further problems :)
112-
120+ Read the official documentation at http://mumble-ruby-pluginbot.readthedocs.io/
113121
114122 _BUGS/WISHES/IDEAS_
115123 If you think you found a bug, have a wish for the bot or some ideas please don't
116124 hesitate to create an issue at https://github.com/MusicGenerator/mumble-ruby-pluginbot/issues
117125
118-
119126 Have fun with the Mumble-Ruby-Pluginbot :)
127+
120128EOF
121129}
122130
@@ -128,18 +136,6 @@ function log() {
128136 " ${TAIL_BIN} " -f -n10 ~ /logs/* .log
129137}
130138
131- function status() {
132- local _status=$( tmux list-windows 2> /dev/null | sed -r -e " s/.*(bot)[123].*/\1/g" )
133-
134- if [ " ${_status} " == " bot" ]; then
135- echo " Bots are running"
136- return 0
137- else
138- echo " Bots are not running"
139- return 1
140- fi
141- }
142-
143139function parse() {
144140 if [ " $# " -le " 0" ]; then
145141 show_help
@@ -148,28 +144,24 @@ function parse() {
148144 while [ " $# " -gt " 0" ]; do
149145 case ${1} in
150146 status)
151- status
152- exit $?
147+ status_all_bots
148+ # exit $?
153149 shift
154150 ;;
155151 start)
156152 update_youtubedl
157- stop_bots_and_mpds
158- start_mpds
159- start_bots
153+ restart_all_bots
160154 show_disclaimer
161155 shift
162156 ;;
163157 restart)
164158 update_youtubedl
165- stop_bots_and_mpds
166- start_mpds
167- start_bots
159+ restart_all_bots
168160 show_disclaimer
169161 shift
170162 ;;
171163 stop)
172- stop_bots_and_mpds
164+ stop_all_bots
173165 shift
174166 ;;
175167 -h|--help)
0 commit comments