2016-06-22 16:46:47 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
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-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"
|
|
|
|
echo " start -c starts mycroft-service, mycroft-skills and 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-18 20:47:46 +00:00
|
|
|
mkdir -p $DIR/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-18 20:47:46 +00:00
|
|
|
tail $DIR/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-18 20:47:46 +00:00
|
|
|
screen -mdS mycroft-$1$2 -c $DIR/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
|
|
|
|
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
|
|
|
|
start-mycroft skills
|
|
|
|
start-mycroft voice
|
|
|
|
start-mycroft cli --quiet
|
|
|
|
exit 0
|
|
|
|
elif [[ "$1" == "start" && "$2" == "-v" ]]
|
|
|
|
then
|
|
|
|
start-mycroft service
|
|
|
|
start-mycroft skills
|
|
|
|
start-mycroft voice
|
|
|
|
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
|
|
|
|
start-mycroft cli
|
2016-06-18 16:58:03 +00:00
|
|
|
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
|
|
|
|
stop-mycroft voice
|
|
|
|
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
|