diff --git a/Docker/bootstrap b/Docker/bootstrap index 8697b868..ee55fcd2 100644 --- a/Docker/bootstrap +++ b/Docker/bootstrap @@ -1,86 +1,35 @@ #!/bin/sh +# Written by Netkas 14/01/2021 echo "### Initializing CoffeeHouse-Utils ###" -chmod a+x /usr/local/bin/update_server + if [ ! -f /firstrun.pass ]; then echo "(!) First run! Installing resources..." - update_server + + echo "Intellivoid Provisioning" + echo "Running on x86_64 (docker) [PRODUCTION]" + echo " " + echo " ## Authentication Required " + read -p 'Enter your 25-50 character PAT: ' GIT_API_KEY + + echo " #### Cloning CoffeeHousePy" + cd / + git clone https://${GIT_API_KEY}@github.com/Intellivoid/CoffeeHousePy.git + + echo " #### Checking out production branch" + cd /CoffeeHousePy + git checkout nsfw_detection + + echo " #### Setting permissions" + chmod a+x /CoffeeHousePy/Docker/coffeehouse + chmod a+x /CoffeeHousePy/Docker/installer + + echo " #### Running installer" + ./CoffeeHouse/Docker/installer + echo "(+) Setting boot flag..." touch /firstrun.pass echo "[...] Restarting server in detached mode..." else - cd /CoffeeHousePy - - echo "### Checking for updates ###" - git remote update - - UPSTREAM=${1:-'@{u}'} - LOCAL=$(git rev-parse @) - BASE=$(git merge-base @ "$UPSTREAM") - - if [ $LOCAL = $BASE ]; then - echo "### Applying update ###" - git pull - make clean install - fi - - echo "### Starting CoffeeHouse-LangDetect ###" - make start_langdetect & - echo "### Starting CoffeeHouse-SpamDetect ###" - make start_spamdetect & - echo "### Starting CoffeeHouse-CoreNLP ###" - make start_corenlp & - echo "### Starting CoffeeHouse-NSFW ###" - make start_nsfw & - - echo "### Checking Service Status ###" - - if ! python3 scripts/warmup.py; then - echo "ERROR: Some services failed to start successfully during the warmup process" - exit 1 - fi - - echo "### Starting Ping Service ###" - make start_ping & - - while sleep 60; do - - # If grep find anything, they exit with 0 status - # If they are not 0, then something is wrong - - ps aux | grep coffeehouse_languagedetection | grep -q -v grep - LANGDETECT_STATUS=$? - if [ $LANGDETECT_STATUS -ne 0 ]; then - echo "ERROR: coffeehouse_languagedetection has been terminated, terminating container." - exit 1 - fi - - ps aux | grep coffeehouse_spamdetection | grep -q -v grep - SPAMDETECT_STATUS=$? - if [ $SPAMDETECT_STATUS -ne 0 ]; then - echo "ERROR: coffeehouse_spamdetection has been terminated, terminating container." - exit 1 - fi - - ps aux | grep coffeehouse_nsfw | grep -q -v grep - NSFW_STATUS=$? - if [ $NSFW_STATUS -ne 0 ]; then - echo "ERROR: coffeehouse_nsfw has been terminated, terminating container." - exit 1 - fi - - ps aux | grep coffeehouse_ping | grep -q -v grep - PING_STATUS=$? - if [ $PING_STATUS -ne 0 ]; then - echo "ERROR: coffeehouse_ping has been terminated, terminating container." - exit 1 - fi - - ps aux | grep edu.stanford.nlp.pipeline.StanfordCoreNLPServer | grep -q -v grep - CORENLP_STATUS=$? - if [ $CORENLP_STATUS -ne 0 ]; then - echo "ERROR: coffeehouse_corenlp has been terminated, terminating container." - exit 1 - fi - - done + echo "### Starting main execution point" + ./CoffeeHouse/Docker/coffeehouse fi \ No newline at end of file diff --git a/Docker/coffeehouse b/Docker/coffeehouse new file mode 100644 index 00000000..0c4a5efa --- /dev/null +++ b/Docker/coffeehouse @@ -0,0 +1,77 @@ +#!/bin/sh +# Written by Netkas 14/01/2021 +cd /CoffeeHousePy + +echo "### Checking for updates ###" +git remote update + +UPSTREAM=${1:-'@{u}'} +LOCAL=$(git rev-parse @) +BASE=$(git merge-base @ "$UPSTREAM") + +if [ $LOCAL = $BASE ]; then + echo "### Applying update ###" + git pull + make clean install +fi + +echo "### Starting CoffeeHouse-LangDetect ###" +make start_langdetect & +echo "### Starting CoffeeHouse-SpamDetect ###" +make start_spamdetect & +echo "### Starting CoffeeHouse-CoreNLP ###" +make start_corenlp & +echo "### Starting CoffeeHouse-NSFW ###" +make start_nsfw & + +echo "### Checking Service Status ###" + +if ! python3 scripts/warmup.py; then + echo "ERROR: Some services failed to start successfully during the warmup process" + exit 1 +fi + +echo "### Starting Ping Service ###" +make start_ping & + +while sleep 60; do + + # If grep find anything, they exit with 0 status + # If they are not 0, then something is wrong + + ps aux | grep coffeehouse_languagedetection | grep -q -v grep + LANGDETECT_STATUS=$? + if [ $LANGDETECT_STATUS -ne 0 ]; then + echo "ERROR: coffeehouse_languagedetection has been terminated, terminating container." + exit 1 + fi + + ps aux | grep coffeehouse_spamdetection | grep -q -v grep + SPAMDETECT_STATUS=$? + if [ $SPAMDETECT_STATUS -ne 0 ]; then + echo "ERROR: coffeehouse_spamdetection has been terminated, terminating container." + exit 1 + fi + + ps aux | grep coffeehouse_nsfw | grep -q -v grep + NSFW_STATUS=$? + if [ $NSFW_STATUS -ne 0 ]; then + echo "ERROR: coffeehouse_nsfw has been terminated, terminating container." + exit 1 + fi + + ps aux | grep coffeehouse_ping | grep -q -v grep + PING_STATUS=$? + if [ $PING_STATUS -ne 0 ]; then + echo "ERROR: coffeehouse_ping has been terminated, terminating container." + exit 1 + fi + + ps aux | grep edu.stanford.nlp.pipeline.StanfordCoreNLPServer | grep -q -v grep + CORENLP_STATUS=$? + if [ $CORENLP_STATUS -ne 0 ]; then + echo "ERROR: coffeehouse_corenlp has been terminated, terminating container." + exit 1 + fi + +done \ No newline at end of file diff --git a/Docker/installer b/Docker/installer new file mode 100644 index 00000000..79061deb --- /dev/null +++ b/Docker/installer @@ -0,0 +1,18 @@ +#!/bin/bash +# Written by Netkas 14/01/2021 +cd /CoffeeHousePy + +echo " #### Preparing System for Python" +make system_prep_python + +echo " #### Preparing System for pip" +make system_prep_pip + +echo " #### Preparing System for GCC" +make system_prep_gcc + +echo " #### Preparing System for Java" +make system_prep_java + +echo " #### Building and Installing CoffeeHousePy" +make install_full \ No newline at end of file diff --git a/Docker/update_server b/Docker/update_server deleted file mode 100644 index 51974426..00000000 --- a/Docker/update_server +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -# Written by Netkas 3/01/2021 -echo "Intellivoid Provisioning" -echo "Running on x86_64 (docker) [PRODUCTION]" -echo " " -echo " ## Authentication Required " -read -p 'Enter your 25-50 character PAT: ' GIT_API_KEY - - -echo " #### Cloning CoffeeHousePy" -git clone https://${GIT_API_KEY}@github.com/Intellivoid/CoffeeHousePy.git -cd /CoffeeHousePy -git checkout nsfw_detection - -echo " #### Preparing System for Python" -make system_prep_python - -echo " #### Preparing System for pip" -make system_prep_pip - -echo " #### Preparing System for GCC" -make system_prep_gcc - -echo " #### Preparing System for Java" -make system_prep_java - -echo " #### Building and Installing CoffeeHousePy" -make install_full \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 113b4700..e6cce0b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,15 @@ -FROM ubuntu:18.04 -EXPOSE 5600 5601 5602 5603 5604 5606 -MAINTAINER Diederik Noordhuis (diederikn@intellivoid.net) - -ARG DEBIAN_FRONTEND=noninteractive -COPY Docker/bootstrap /usr/local/bin/bootstrap -COPY Docker/update_server /usr/local/bin/update_server - -RUN \ - apt-get update && \ - ln -fs /usr/share/zoneinfo/UTC /etc/localtime && \ - apt-get update && \ - apt-get install git make sudo nano vim wget curl unzip -y && \ - apt-get clean - +FROM ubuntu:18.04 +EXPOSE 5600 5601 5602 5603 5604 5606 +MAINTAINER Diederik Noordhuis (diederikn@intellivoid.net) + +ARG DEBIAN_FRONTEND=noninteractive +COPY Docker/bootstrap /usr/local/bin/bootstrap + +RUN \ + apt-get update && \ + ln -fs /usr/share/zoneinfo/UTC /etc/localtime && \ + apt-get update && \ + apt-get install git make sudo nano vim wget curl unzip -y && \ + apt-get clean + CMD ["/bin/bash", "/usr/local/bin/bootstrap"] \ No newline at end of file