forked from JarbasAI/ZZZ-JarbasAI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jarbas.sh
executable file
·195 lines (163 loc) · 3.59 KB
/
jarbas.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/env bash
./scripts/prepare-msm.sh
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 screen-config {
echo "
# Generated
deflog on
logfile scripts/logs/$1.log
logfile flush 1
"
}
function usage-exit {
echo "
Quickly start, stop or restart Mycroft's essential services in detached screens
usage: $0 (start|stop|restart) [options]
start launch all necessary services to run mycroft
stop end all services
restart stop, then start all services
-h, --help this help message
start options:
[nothing] both cli and voice client
-v, --voice only voice client
-c, --cli only cli
-d, --debug only cli, in current terminal
-s, --server server mode
-cl, --client client mode
restart options:
(same as start)
screen tips:
run 'screen -list' to see all running screens
run 'screen -r <screen-name>' (e.g. 'screen -r mycroft-service') to reatach a screen
press ctrl + a, ctrl + d to detach the screen again
See the screen man page for more details
"
exit 1
}
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 screen-script {
SCREEN_NAME="$2"
if [ "$1" == "log" ]; then
SCREEN_FILE="$SCRIPTS/$SCREEN_NAME.screen"
if [ ! -f "$SCREEN_FILE" ]; then
echo "$(screen-config $SCREEN_NAME)" > "$SCREEN_FILE"
fi
args="$args -c $SCREEN_FILE"
elif [ "$1" != "no-log" ]; then
echo "Invalid argument $1"
exit 1
fi
shift
shift
screen -mdS $SCREEN_NAME $args $@
sleep 0.1
verify-start $SCREEN_NAME
echo "Started $SCREEN_NAME"
}
function start-mycroft-custom {
name="mycroft-$1"
shift
screen-script log "$name" $@
}
function start-mycroft {
start-mycroft-custom "$1" $DIR/start.sh $@
}
function start-mycroft-nolog {
screen-script no-log "mycroft-$1" $DIR/start.sh $@
}
function start-mycroft-debug {
$DIR/start.sh $@
}
function stop-screen {
for i in $(screen -ls "$1"); do
if echo $i | grep -q $1; then
screen -XS $i quit && echo "Stopped $1" || echo "Could not stop $1"
fi
done
}
function stop-mycroft {
stop-screen "mycroft-$1"
}
set -e
case "$1" in
"start")
$0 stop
start-mycroft service
start-mycroft skills
start-mycroft audio
start-mycroft display
case "$2" in
"")
start-mycroft voice
start-mycroft cli --quiet --simple
;;
"-w"|"--web")
start-mycroft webchat
;;
"-v"|"--voice")
start-mycroft voice
;;
"-c"|"--cli")
start-mycroft cli
;;
"-d"|"--debug")
start-mycroft-debug cli
;;
"-s"|"--server")
start-mycroft server
stop-mycroft display
stop-mycroft audio
;;
"-cl"|"--client")
start-mycroft client
start-mycroft cli
start-mycroft voice
;;
*)
echo "Usage"
usage-exit
;;
esac
;;
"stop")
if [[ -n "$2" ]]; then usage-exit; fi
stop-mycroft service
stop-mycroft skills
stop-mycroft voice
stop-mycroft cli
stop-mycroft client
stop-mycroft server
stop-mycroft audio
stop-mycroft display
;;
"restart")
case "$2" in
""|"-v"|"--voice"|"-c"|"--cli"|"-d"|"--debug")
$0 stop
$0 start $2
;;
*)
usage-exit
;;
esac
;;
*)
usage-exit
;;
esac