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
|
|
|
|
echo "usage: $0 [-h] (start|stop|restart)"
|
|
|
|
echo " -h this help message"
|
|
|
|
echo " start starts mycroft-service, mycroft-skills and mycroft-voice"
|
|
|
|
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-06-22 16:46:47 +00:00
|
|
|
function verify-start() {
|
|
|
|
# check if screen for service was started
|
|
|
|
if ! screen -list | grep -q "$1";
|
|
|
|
then
|
|
|
|
:
|
|
|
|
else
|
|
|
|
# else echo tail logs/mycroft-service.log
|
|
|
|
echo "$1 failed to start. The log is below:"
|
|
|
|
echo
|
|
|
|
tail $DIR/logs/$1.log
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-18 16:58:03 +00:00
|
|
|
function start-mycroft {
|
2016-06-22 16:07:17 +00:00
|
|
|
mkdir -p $DIR/logs
|
|
|
|
screen -mdS mycroft-service -c $DIR/mycroft-service.screen $DIR/start.sh service
|
2016-06-22 16:46:47 +00:00
|
|
|
verify-start mycroft-service
|
2016-06-22 16:07:17 +00:00
|
|
|
screen -mdS mycroft-skills -c $DIR/mycroft-skills.screen $DIR/start.sh skills
|
2016-06-22 16:46:47 +00:00
|
|
|
verify-start mycroft-skills
|
2016-06-22 16:07:17 +00:00
|
|
|
screen -mdS mycroft-voice -c $DIR/mycroft-voice.screen $DIR/start.sh voice
|
2016-06-22 16:46:47 +00:00
|
|
|
verify-start mycroft-voice
|
2016-06-18 16:58:03 +00:00
|
|
|
}
|
|
|
|
function stop-mycroft {
|
|
|
|
screen -XS mycroft-service quit
|
|
|
|
screen -XS mycroft-skills quit
|
|
|
|
screen -XS mycroft-voice quit
|
|
|
|
}
|
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
|
|
|
|
elif [ "$1" == "start" ]
|
|
|
|
then
|
|
|
|
start-mycroft
|
|
|
|
echo "Mycroft Started"
|
|
|
|
exit 0
|
|
|
|
elif [ "$1" == "stop" ]
|
|
|
|
then
|
|
|
|
stop-mycroft
|
|
|
|
echo "Mycroft Stopped"
|
|
|
|
exit 0
|
|
|
|
elif [ "$1" == "restart" ]
|
|
|
|
then
|
|
|
|
stop-mycroft
|
|
|
|
echo "Stopping Mycroft"
|
|
|
|
start-mycroft
|
|
|
|
echo "Mycroft restarted"
|
|
|
|
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
|