From 27b73844d4084057f420fc90f731d12aa22b7bfa Mon Sep 17 00:00:00 2001 From: Jason Hines Date: Thu, 23 Jun 2016 13:13:45 -0400 Subject: [PATCH] =?UTF-8?q?Noticed=20that=20FAQ/Common=20Errors=20section?= =?UTF-8?q?=20of=20README.md=20said=20that=20mycroft.=E2=80=A6=20(#221)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Noticed that FAQ/Common Errors section of README.md said that mycroft.sh would start the cli, so I added it. * changed three to four for FAQ since four processes are listed. * added --quiet option to start.sh cli to prevent echo when using the cli * per @the7erm sugestion: changed the log flush to 1 second for screen. * modified mycroft.sh to support starting in three modes: - service, skills, voice, cli --quiet - service skills, voice - service skills, cli * Added changes to quick start to reflect changes to mycroft.sh --- README.md | 6 ++- mycroft-cli.screen | 4 ++ mycroft-service.screen | 1 + mycroft-skills.screen | 2 + mycroft-voice.screen | 2 + mycroft.sh | 94 ++++++++++++++++++++++++++++-------------- 6 files changed, 75 insertions(+), 34 deletions(-) create mode 100644 mycroft-cli.screen diff --git a/README.md b/README.md index fb2007c701..5003cf28c9 100644 --- a/README.md +++ b/README.md @@ -75,9 +75,11 @@ Mycroft configuration consists of 3 possible config files. When the configuration loader starts, it looks in those locations in that order, and loads ALL configuration. Keys that exist in multiple config files will be overridden by the last file to contain that config value. This results in a minimal amount of config being written for a specific device/user, without modifying the distribution files. # Running Mycroft Quick Start -To start the essential tasks run `./mycroft.sh start`. Which will start the service, skills and voice in a detched screen and log the output of the screens to the their respective log files (e.g. ./log/mycroft-service.log). +To start the essential tasks run `./mycroft.sh start`. Which will start the service, skills, voice and cli (using --quiet mode) in a detched screen and log the output of the screens to the their respective log files (e.g. ./log/mycroft-service.log). +Optionally you can run `./mycroft.sh start -v` Which will start the service, skills and voice. Or `./mycroft.sh start -c` Which will start the service, skills and cli. To stop Mycroft run `./mycroft.sh stop`. This will quit all of the detached screens. +To restart Mycroft run './mycroft.sh restart`. Quick screen tips - run `screen -list` to see all running screens @@ -120,4 +122,4 @@ source ~/.virtualenvs/mycroft/bin/activate #### When running mycroft, I get the error `mycroft.messagebus.client.ws - ERROR - Exception("Uncaught 'error' event.",)` -This means that you are not running the `./start.sh service` process. In order to fully run Mycroft, you must run `./start.sh service`, `./start.sh skills`, and `./start.sh voice`/`./start.sh cli` all at the same time. This can be done using different terminal windows, or by using the included `./mycroft.sh start`, which runs all three process using `screen`. +This means that you are not running the `./start.sh service` process. In order to fully run Mycroft, you must run `./start.sh service`, `./start.sh skills`, and `./start.sh voice`/`./start.sh cli` all at the same time. This can be done using different terminal windows, or by using the included `./mycroft.sh start`, which runs all four process using `screen`. diff --git a/mycroft-cli.screen b/mycroft-cli.screen new file mode 100644 index 0000000000..1f451d034e --- /dev/null +++ b/mycroft-cli.screen @@ -0,0 +1,4 @@ +deflog on +logfile logs/mycroft-cli.log +logfile flush 1 + diff --git a/mycroft-service.screen b/mycroft-service.screen index 3546cef475..87bd417fc0 100644 --- a/mycroft-service.screen +++ b/mycroft-service.screen @@ -1,2 +1,3 @@ deflog on logfile logs/mycroft-service.log +logfile flush 1 diff --git a/mycroft-skills.screen b/mycroft-skills.screen index a95651f228..7ae29f0a10 100644 --- a/mycroft-skills.screen +++ b/mycroft-skills.screen @@ -1,2 +1,4 @@ deflog on logfile logs/mycroft-skills.log +logfile flush 1 + diff --git a/mycroft-voice.screen b/mycroft-voice.screen index c8f0ff7668..5c39562734 100644 --- a/mycroft-voice.screen +++ b/mycroft-voice.screen @@ -1,2 +1,4 @@ deflog on logfile logs/mycroft-voice.log +logfile flush 1 + diff --git a/mycroft.sh b/mycroft.sh index a646f6adc4..3fa2220216 100755 --- a/mycroft.sh +++ b/mycroft.sh @@ -12,9 +12,11 @@ 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 "usage: $0 [-h] (start [-v|-c]|stop|restart)" echo " -h this help message" - echo " start starts mycroft-service, mycroft-skills and mycroft-voice" + 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 @@ -26,13 +28,11 @@ function usage { echo } -function verify-start() { - # check if screen for service was started - if screen -list | grep -q "$1"; +mkdir -p $DIR/logs + +function verify-start { + 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 @@ -40,23 +40,40 @@ function verify-start() { fi } - function start-mycroft { - mkdir -p $DIR/logs - screen -mdS mycroft-service -c $DIR/mycroft-service.screen $DIR/start.sh service + screen -mdS mycroft-$1$2 -c $DIR/mycroft-$1.screen $DIR/start.sh $1 $2 sleep 1 - verify-start mycroft-service - screen -mdS mycroft-skills -c $DIR/mycroft-skills.screen $DIR/start.sh skills - sleep 1 - verify-start mycroft-skills - screen -mdS mycroft-voice -c $DIR/mycroft-voice.screen $DIR/start.sh voice - sleep 1 - verify-start mycroft-voice + verify-start mycroft-$1$2 + echo "Mycroft $1$2 started" } + function stop-mycroft { - screen -XS mycroft-service quit - screen -XS mycroft-skills quit - screen -XS mycroft-voice quit + 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 @@ -65,22 +82,35 @@ if [[ -z "$1" || "$1" == "-h" ]] then usage exit 1 -elif [ "$1" == "start" ] +elif [[ "$1" == "start" && -z "$2" ]] then - start-mycroft - echo "Mycroft Started" + start-mycroft service + start-mycroft skills + start-mycroft voice + start-mycroft cli --quiet exit 0 -elif [ "$1" == "stop" ] +elif [[ "$1" == "start" && "$2" == "-v" ]] then - stop-mycroft - echo "Mycroft Stopped" + start-mycroft service + start-mycroft skills + start-mycroft voice exit 0 -elif [ "$1" == "restart" ] +elif [[ "$1" == "start" && "$2" == "-c" ]] then - stop-mycroft - echo "Stopping Mycroft" - start-mycroft - echo "Mycroft restarted" + 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