2016-06-22 16:46:47 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2017-04-17 18:27:07 +00:00
|
|
|
./scripts/prepare-msm.sh
|
|
|
|
|
2016-06-22 16:07:17 +00:00
|
|
|
SOURCE="${BASH_SOURCE[0]}"
|
2016-06-22 16:58:57 +00:00
|
|
|
while [ -h "$SOURCE" ]; do
|
2016-06-22 16:07:17 +00:00
|
|
|
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
|
|
|
SOURCE="$(readlink "$SOURCE")"
|
2016-06-22 16:58:57 +00:00
|
|
|
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
|
2016-06-22 16:07:17 +00:00
|
|
|
done
|
|
|
|
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
2016-07-27 14:36:47 +00:00
|
|
|
SCRIPTS="$DIR/scripts"
|
2016-06-22 16:07:17 +00:00
|
|
|
|
2016-06-18 16:58:03 +00:00
|
|
|
function usage {
|
|
|
|
echo
|
|
|
|
echo "Quickly start, stop or restart Mycroft's esential services in detached screens"
|
|
|
|
echo
|
2016-06-23 17:13:45 +00:00
|
|
|
echo "usage: $0 [-h] (start [-v|-c]|stop|restart)"
|
2016-06-18 16:58:03 +00:00
|
|
|
echo " -h this help message"
|
2016-06-23 17:13:45 +00:00
|
|
|
echo " start starts mycroft-service, mycroft-skills, mycroft-voice and mycroft-cli in quiet mode"
|
|
|
|
echo " start -v starts mycroft-service, mycroft-skills and mycroft-voice"
|
2017-02-17 23:30:20 +00:00
|
|
|
echo " start -c starts mycroft-service, mycroft-skills and mycroft-cli in background"
|
|
|
|
echo " start -d starts mycroft-service and mycroft skills in quiet mode and an active mycroft-cli"
|
2016-06-18 16:58:03 +00:00
|
|
|
echo " stop stops mycroft-service, mycroft-skills and mycroft-voice"
|
|
|
|
echo " restart restarts mycroft-service, mycroft-skills and mycroft-voice"
|
|
|
|
echo
|
|
|
|
echo "screen tips:"
|
|
|
|
echo " run 'screen -list' to see all running screens"
|
|
|
|
echo " run 'screen -r <screen-name>' (e.g. 'screen -r mycroft-service') to reatach a screen"
|
|
|
|
echo " press ctrl + a, ctrl + d to detace the screen again"
|
|
|
|
echo " See the screen man page for more details"
|
|
|
|
echo
|
|
|
|
}
|
2016-06-13 22:31:38 +00:00
|
|
|
|
2016-07-27 14:36:47 +00:00
|
|
|
mkdir -p $SCRIPTS/logs
|
2016-06-23 17:13:45 +00:00
|
|
|
|
|
|
|
function verify-start {
|
|
|
|
if ! screen -list | grep -q "$1";
|
2016-06-22 16:46:47 +00:00
|
|
|
then
|
|
|
|
echo "$1 failed to start. The log is below:"
|
|
|
|
echo
|
2016-07-27 14:36:47 +00:00
|
|
|
tail $SCRIPTS/logs/$1.log
|
2016-06-22 16:46:47 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-06-18 16:58:03 +00:00
|
|
|
function start-mycroft {
|
2016-07-27 14:36:47 +00:00
|
|
|
screen -mdS mycroft-$1$2 -c $SCRIPTS/mycroft-$1.screen $DIR/start.sh $1 $2
|
2016-06-22 17:25:18 +00:00
|
|
|
sleep 1
|
2016-06-23 17:13:45 +00:00
|
|
|
verify-start mycroft-$1$2
|
|
|
|
echo "Mycroft $1$2 started"
|
2016-06-18 16:58:03 +00:00
|
|
|
}
|
2016-06-23 17:13:45 +00:00
|
|
|
|
2017-04-12 07:15:37 +00:00
|
|
|
function start-mycroft-nolog {
|
|
|
|
screen -mdS mycroft-$1$2 $DIR/start.sh $1 $2 $3
|
2017-02-17 23:30:20 +00:00
|
|
|
sleep 1
|
|
|
|
verify-start mycroft-$1$2
|
|
|
|
echo "Mycroft $1$2 started"
|
|
|
|
}
|
|
|
|
|
2017-04-12 07:15:37 +00:00
|
|
|
function debug-start-mycroft {
|
|
|
|
$DIR/start.sh $1 $2
|
|
|
|
echo "Mycroft $1$2 started"
|
|
|
|
}
|
|
|
|
|
2016-06-18 16:58:03 +00:00
|
|
|
function stop-mycroft {
|
2016-06-23 17:13:45 +00:00
|
|
|
if screen -list | grep -q "$1";
|
|
|
|
then
|
|
|
|
screen -XS mycroft-$1 quit
|
|
|
|
echo "Mycroft $1 stopped"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function restart-mycroft {
|
|
|
|
if screen -list | grep -q "quiet";
|
|
|
|
then
|
|
|
|
$0 stop
|
|
|
|
sleep 1
|
|
|
|
$0 start
|
|
|
|
elif screen -list | grep -q "cli" && ! screen -list | grep -q "quiet";
|
|
|
|
then
|
|
|
|
$0 stop
|
|
|
|
sleep 1
|
|
|
|
$0 start -c
|
|
|
|
elif screen -list | grep -q "voice" && ! screen -list | grep -q "quiet";
|
|
|
|
then
|
|
|
|
$0 stop
|
|
|
|
sleep 1
|
|
|
|
$0 start -v
|
|
|
|
else
|
|
|
|
echo "An error occurred"
|
|
|
|
fi
|
2016-06-18 16:58:03 +00:00
|
|
|
}
|
2016-06-15 18:52:59 +00:00
|
|
|
|
2016-06-19 06:43:08 +00:00
|
|
|
set -e
|
|
|
|
|
2016-06-18 16:58:03 +00:00
|
|
|
if [[ -z "$1" || "$1" == "-h" ]]
|
|
|
|
then
|
|
|
|
usage
|
|
|
|
exit 1
|
2016-06-23 17:13:45 +00:00
|
|
|
elif [[ "$1" == "start" && -z "$2" ]]
|
|
|
|
then
|
|
|
|
start-mycroft service
|
2017-04-06 23:30:58 +00:00
|
|
|
start-mycroft skills
|
2017-04-12 07:15:37 +00:00
|
|
|
start-mycroft voice
|
|
|
|
start-mycroft-nolog cli --quiet --simple
|
2016-06-23 17:13:45 +00:00
|
|
|
exit 0
|
|
|
|
elif [[ "$1" == "start" && "$2" == "-v" ]]
|
|
|
|
then
|
|
|
|
start-mycroft service
|
2017-04-06 23:30:58 +00:00
|
|
|
start-mycroft skills
|
2017-04-12 07:15:37 +00:00
|
|
|
start-mycroft voice
|
2016-06-23 17:13:45 +00:00
|
|
|
exit 0
|
|
|
|
elif [[ "$1" == "start" && "$2" == "-c" ]]
|
2016-06-18 16:58:03 +00:00
|
|
|
then
|
2016-06-23 17:13:45 +00:00
|
|
|
start-mycroft service
|
|
|
|
start-mycroft skills
|
2017-04-12 07:15:37 +00:00
|
|
|
start-mycroft-nolog cli --simple
|
2016-06-18 16:58:03 +00:00
|
|
|
exit 0
|
2017-02-17 23:30:20 +00:00
|
|
|
elif [[ "$1" == "start" && "$2" == "-d" ]]
|
|
|
|
then
|
|
|
|
start-mycroft service
|
|
|
|
start-mycroft skills
|
|
|
|
debug-start-mycroft cli
|
|
|
|
exit 0
|
2016-06-23 17:13:45 +00:00
|
|
|
elif [[ "$1" == "stop" && -z "$2" ]]
|
2016-06-18 16:58:03 +00:00
|
|
|
then
|
2016-06-23 17:13:45 +00:00
|
|
|
stop-mycroft service
|
|
|
|
stop-mycroft skills
|
2017-04-12 07:15:37 +00:00
|
|
|
stop-mycroft voice
|
2016-06-23 17:13:45 +00:00
|
|
|
stop-mycroft cli
|
2016-06-18 16:58:03 +00:00
|
|
|
exit 0
|
2016-06-23 17:13:45 +00:00
|
|
|
elif [[ "$1" == "restart" && -z "$2" ]]
|
2016-06-18 16:58:03 +00:00
|
|
|
then
|
2016-06-23 17:13:45 +00:00
|
|
|
restart-mycroft
|
2016-06-18 16:58:03 +00:00
|
|
|
exit 0
|
2016-06-15 18:52:59 +00:00
|
|
|
else
|
2016-06-18 16:58:03 +00:00
|
|
|
usage
|
|
|
|
exit 1
|
2016-06-15 18:52:59 +00:00
|
|
|
fi
|