forked from MycroftAI/mycroft-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmycroft.sh
executable file
·119 lines (110 loc) · 2.89 KB
/
mycroft.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env bash
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SCRIPTS="$DIR/scripts"
function usage {
echo
echo "Quickly start, stop or restart Mycroft's esential services in detached screens"
echo
echo "usage: $0 [-h] (start [-v|-c]|stop|restart)"
echo " -h this help message"
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"
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
}
mkdir -p $SCRIPTS/logs
function verify-start {
if ! screen -list | grep -q "$1";
then
echo "$1 failed to start. The log is below:"
echo
tail $SCRIPTS/logs/$1.log
exit 1
fi
}
function start-mycroft {
screen -mdS mycroft-$1$2 -c $SCRIPTS/mycroft-$1.screen $DIR/start.sh $1 $2
sleep 1
verify-start mycroft-$1$2
echo "Mycroft $1$2 started"
}
function stop-mycroft {
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
}
set -e
if [[ -z "$1" || "$1" == "-h" ]]
then
usage
exit 1
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" ]]
then
start-mycroft service
start-mycroft skills
start-mycroft cli
exit 0
elif [[ "$1" == "stop" && -z "$2" ]]
then
stop-mycroft service
stop-mycroft skills
stop-mycroft voice
stop-mycroft cli
exit 0
elif [[ "$1" == "restart" && -z "$2" ]]
then
restart-mycroft
exit 0
else
usage
exit 1
fi