Tweaks to start/stop scripts

Several minor changes:
* Add mycroft-start and mycroft-stop, which can be used as commands anywhere
  if the user has added this to the PATH.  They are shortcuts to the
  start-mycroft.sh and stop-mycroft.sh scripts.
* Add to the mycroft-help command reference
* Add "reset" parameter for start-mycroft.sh, which forces a service restart.
  If a service is currently running, it will not restart by default anymore.
* Make the 'enclosure' service part of 'all' regardless of platform.  This
  makes sense not that it can handle a remote GUI connection.
* BUG: mycroft-stop would sometimes show odd messages if the skill process
  had active child processes.
pull/1935/head
Steve Penrod 2019-01-07 22:07:38 -06:00 committed by Åke Forslund
parent 8b71b89cf8
commit dd697cb765
5 changed files with 77 additions and 30 deletions

View File

@ -25,6 +25,8 @@ echo "Mycroft-specific commands you can use from the Linux command prompt:"
echo " mycroft-cli-client command line client, useful for debugging"
echo " mycroft-msm Mycroft Skills Manager, to manage your Skills"
echo " mycroft-msk Mycroft Skills Kit, create and share Skills"
echo " mycroft-start Launch/restart Mycroft services"
echo " mycroft-stop Stop Mycroft services"
echo
echo "Scripting Utilities:"
echo " mycroft-speak <phr> have Mycroft speak a phrase to the user"

21
bin/mycroft-start Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env bash
# Copyright 2019 Mycroft AI Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
SOURCE="${BASH_SOURCE[0]}"
cd -P "$( dirname "$SOURCE" )"/..
DIR="$( pwd )"
. "$DIR/start-mycroft.sh" $@

21
bin/mycroft-stop Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env bash
# Copyright 2019 Mycroft AI Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
SOURCE="${BASH_SOURCE[0]}"
cd -P "$( dirname "$SOURCE" )"/..
DIR="$( pwd )"
. "$DIR/stop-mycroft.sh" $@

View File

@ -24,13 +24,11 @@ VIRTUALENV_ROOT=${VIRTUALENV_ROOT:-"${DIR}/.venv"}
function help() {
echo "${script}: Mycroft command/service launcher"
echo "usage: ${script} [command] [params]"
echo "usage: ${script} [COMMAND] [restart] [params]"
echo
echo "Services:"
echo "Services COMMANDs:"
echo " all runs core services: bus, audio, skills, voice"
echo " debug runs core services, then starts the CLI"
echo
echo "Services:"
echo " audio the audio playback service"
echo " bus the messagebus service"
echo " skills the skill service"
@ -38,18 +36,22 @@ function help() {
# echo " wifi wifi setup service"
echo " enclosure mark_1 enclosure service"
echo
echo "Tools:"
echo "Tool COMMANDs:"
echo " cli the Command Line Interface"
echo " unittest run mycroft-core unit tests (requires pytest)"
echo " skillstest run the skill autotests for all skills (requires pytest)"
echo
echo "Utils:"
echo "Util COMMANDs:"
echo " audiotest attempt simple audio validation"
echo " audioaccuracytest more complex audio validation"
echo " sdkdoc generate sdk documentation"
echo
echo "Options:"
echo " restart (optional) Force the service to restart if running"
echo
echo "Examples:"
echo " ${script} all"
echo " ${script} all restart"
echo " ${script} cli"
echo " ${script} unittest"
@ -102,6 +104,7 @@ function launch-process() {
}
function require-process() {
# Launch process if not found
name-to-script-path ${1}
if ! pgrep -f "python3 -m ${_module}" > /dev/null ; then
# Start required process
@ -115,8 +118,13 @@ function launch-background() {
# Check if given module is running and start (or restart if running)
name-to-script-path ${1}
if pgrep -f "python3 -m ${_module}" > /dev/null ; then
echo "Restarting: ${1}"
"${DIR}/stop-mycroft.sh" ${1}
if ($_force_restart) ; then
echo "Restarting: ${1}"
"${DIR}/stop-mycroft.sh" ${1}
else
# Already running, no need to restart
return
fi
else
echo "Starting background service $1"
fi
@ -138,15 +146,7 @@ function launch-all() {
launch-background skills
launch-background audio
launch-background voice
# Determine platform type
if [[ -r /etc/mycroft/mycroft.conf ]] ; then
mycroft_platform=$( jq -r ".enclosure.platform" < /etc/mycroft/mycroft.conf )
if [[ $mycroft_platform = "mycroft_mark_1" ]] ; then
# running on a Mark 1, start enclosure service
launch-background enclosure
fi
fi
launch-background enclosure
}
function check-dependencies() {
@ -177,7 +177,16 @@ function check-dependencies() {
}
_opt=$1
_force_restart=false
shift
if [[ "${1}" == "restart" ]] || [[ "${_opt}" == "restart" ]] ; then
_force_restart=true
if [[ "${_opt}" == "restart" ]] ; then
# Support "start-mycroft.sh restart all" as well as "start-mycroft.sh all restart"
_opt=$1
fi
shift
fi
_params=$@
check-dependencies

View File

@ -31,7 +31,7 @@ function help() {
echo " audio stop the audio playback service"
echo " skills stop the skill service"
echo " voice stop voice capture service"
echo " enclosure stop mark_1 enclosure service"
echo " enclosure stop enclosure (hardware/gui interface) service"
echo
echo "Examples:"
echo " ${script}"
@ -50,8 +50,9 @@ function process-running() {
function end-process() {
if process-running $1 ; then
echo -n "Stopping $1..."
pid=$( pgrep -f "python3 -m mycroft.*${1}" )
# Find the process by name, only returning the oldest if it has children
pid=$( pgrep -o -f "python3 -m mycroft.*${1}" )
echo -n "Stopping $1 (${pid})..."
kill -SIGINT ${pid}
# Wait up to 5 seconds (50 * 0.1) for process to stop
@ -67,7 +68,8 @@ function end-process() {
if process-running $1 ; then
echo "failed to stop."
echo -n " Killing $1..."
pid=$( pgrep -o -f "python3 -m mycroft.*${1}" )
echo -n " Killing $1 (${pid})..."
kill -9 ${pid}
echo "killed."
result=120
@ -96,15 +98,7 @@ case ${OPT} in
end-process skills
end-process audio
end-process speech
# determine platform type
if [[ -r /etc/mycroft/mycroft.conf ]] ; then
mycroft_platform=$( jq -r ".enclosure.platform" < /etc/mycroft/mycroft.conf )
if [[ $mycroft_platform == "mycroft_mark_1" ]] ; then
# running on a Mark 1, stop enclosure service
end-process enclosure
fi
fi
end-process enclosure
;;
"bus")
end-process messagebus.service