diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..0d246182 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,23 @@ +# Changelog + +## 1.0.3 + +* Fixed occasions where the salt master couldn't communicate due to the + docker init system and salt +* Fixed error in `doil delete` where it couldn't find the docker image to + delete +* Fixed zombie process spawning +* Fixed version and build id +* Moved changelog to separate file + +## 1.0.2 + +* Made the salt master and minion comunication more solid +* Fixed minor issues + +## 1.0.1 + +* Fixed a bug in linux templates where the port 80 is blocked so no machine + could be started +* Added update script +* Changed readme (thanks @Rillke) \ No newline at end of file diff --git a/README.md b/README.md index 43021f2e..3ee6456c 100644 --- a/README.md +++ b/README.md @@ -143,18 +143,4 @@ users, so make sure to understand what you are doing. * `doil salt:restart` restarts the salt main server * `doil salt:update` updates the saltstack if you are using a custom saltstack * `doil salt:login` logs the user into the main salt server -* `doil salt:prune` prunes the main salt server - -## Changelog - -### 1.0.2 - -* Made the salt master and minion comunication more solid -* Fixed minor issues - -### 1.0.1 - -* Fixed a bug in linux templates where the port 80 is blocked so no machine - could be started -* Added update script -* Changed readme (thanks @Rillke) \ No newline at end of file +* `doil salt:prune` prunes the main salt server \ No newline at end of file diff --git a/src/lib/instances/create/create.sh b/src/lib/instances/create/create.sh index 921631e2..0910b869 100755 --- a/src/lib/instances/create/create.sh +++ b/src/lib/instances/create/create.sh @@ -262,8 +262,24 @@ until [[ ! -z ${DCMAINSALTSERVICE} ]] do echo "Master service not ready ..." doil salt:restart + sleep 5 DCMAINSALTSERVICE=$(docker top ${DCMAINHASH} | grep "salt-master") done + +# check if the salt main server is defunct +DCMAINSALTSERVICEDEFUNCT=$(docker exec -ti ${DCMAINHASH} bash -c "ps -u salt") +DCMAINSALTSERVICEDEFUNCT=$(echo ${DCMAINSALTSERVICEDEFUNCT} | grep "defunct") +until [[ -z ${DCMAINSALTSERVICEDEFUNCT} ]] +do + doil salt:restart + sleep 5 + + DCMAIN=$(docker ps | grep "saltmain") + DCMAINHASH=${DCMAIN:0:12} + + DCMAINSALTSERVICEDEFUNCT=$(docker exec -ti ${DCMAINHASH} bash -c "ps -u salt") + DCMAINSALTSERVICEDEFUNCT=$(echo ${DCMAINSALTSERVICEDEFUNCT} | grep "defunct") +done echo "Master service ready." # set the saltmain again because we maybe did restart the service @@ -308,6 +324,11 @@ then sleep 5 fi +############## +# checking key +NOW=$(date +'%d.%m.%Y %I:%M:%S') +echo "[${NOW}] Checking key" + # check if the new key is registered SALTKEYS=$(docker exec -t -i ${DCMAINHASH} /bin/bash -c "salt-key -L" | grep "${NAME}.local") until [[ ! -z ${SALTKEYS} ]] diff --git a/src/lib/instances/delete/delete.sh b/src/lib/instances/delete/delete.sh index f4e9b3a6..73e34789 100755 --- a/src/lib/instances/delete/delete.sh +++ b/src/lib/instances/delete/delete.sh @@ -51,7 +51,7 @@ then fi # docker - $(docker rmi $(docker images "doil/${INSTANCE}" -a -q)) + DELETE=$(docker rmi $(docker images "doil/${INSTANCE}" -a -q)) NOW=$(date +'%d.%m.%Y %I:%M:%S') echo "[$NOW] Instance deleted" diff --git a/src/lib/instances/repair/repair.sh b/src/lib/instances/repair/repair.sh index 0bb0425a..2e8950ad 100755 --- a/src/lib/instances/repair/repair.sh +++ b/src/lib/instances/repair/repair.sh @@ -9,7 +9,7 @@ shift # check if command is just plain help # if we don't have any command we load the help -POSITIONAL=() +INSTANCE="" while [[ $# -gt 0 ]] do key="$1" @@ -29,6 +29,7 @@ done if [ -z "${INSTANCE}" ] then # if the instance is empty we are working with the current directory + INSTANCE=${PWD##*/} # check if docker-compose.yml exists and bail if not if [ ! -f "docker-compose.yml" ] @@ -44,21 +45,49 @@ then NOW=$(date +'%d.%m.%Y %I:%M:%S') echo "[$NOW] Rapairing instance" - # get the salt server ready - $(doil salt:restart) - sleep 5 + docker-compose down + + # get main salt server ready + DCMAIN=$(docker ps | grep "saltmain") + DCMAINHASH=${DCMAIN:0:12} + + # check if the salt main server is defunct + DCMAINSALTSERVICEDEFUNCT=$(docker exec -ti ${DCMAINHASH} bash -c "ps -u salt") + DCMAINSALTSERVICEDEFUNCT=$(echo ${DCMAINSALTSERVICEDEFUNCT} | grep "defunct") + until [[ -z ${DCMAINSALTSERVICEDEFUNCT} ]] + do + doil salt:restart + sleep 5 + + DCMAIN=$(docker ps | grep "saltmain") + DCMAINHASH=${DCMAIN:0:12} + + DCMAINSALTSERVICEDEFUNCT=$(docker exec -ti ${DCMAINHASH} bash -c "ps -u salt") + DCMAINSALTSERVICEDEFUNCT=$(echo ${DCMAINSALTSERVICEDEFUNCT} | grep "defunct") + done DCMAINSALTSERVICE=$(docker exec -ti ${DCMAINHASH} bash -c "ps -aux | grep salt-master") until [[ ! -z ${DCMAINSALTSERVICE} ]] do echo "Master service not ready ..." + doil salt:restart + sleep 5 DCMAINSALTSERVICE=$(docker exec -ti ${DCMAINHASH} bash -c "ps -aux | grep salt-master") + DCMAIN=$(docker ps | grep "saltmain") + DCMAINHASH=${DCMAIN:0:12} done echo "Master service ready." # prune system - $(docker exec -t -i ${DCMAINHASH} /bin/bash -c 'echo "y" | salt-key -D') - $(docker rmi $(docker images "doil/${INSTANCE}" -a -q)) + DELETEKEY=$(docker exec -ti ${DCMAINHASH} bash -c 'echo "y" | salt-key -D') + DELETEKEY=$(docker exec -ti ${DCMAINHASH} bash -c 'rm /var/cache/salt/master/.*key') + sleep 3 + + DCIMAGE=$(docker images "doil/${INSTANCE}" -q) + if [ ! -z ${DCIMAGE} ] + then + DELETEIMAGE=$(docker rmi ${DCIMAGE} --force) + fi # Start the container docker-compose up -d @@ -71,6 +100,18 @@ then DCHOSTNAME=$(doil_get_data $DCHASH "hostname") DCDOMAIN=$(doil_get_data $DCHASH "domainname") + # remove salt public key + PUBKEY=$(docker exec -ti ${DCHASH} bash -c "rm /var/lib/salt/pki/minion/minion_master.pub") + docker-compose down + docker-compose up -d + sleep 5 + + DCFOLDER=${PWD##*/} + DCHASH=$(doil_get_hash $DCFOLDER) + DCIP=$(doil_get_data $DCHASH "ip") + DCHOSTNAME=$(doil_get_data $DCHASH "hostname") + DCDOMAIN=$(doil_get_data $DCHASH "domainname") + DCMINIONSALTSERVICE=$(docker container top ${DCHASH} | grep "salt-minion") # wait until the service is there if [[ -z ${DCMINIONSALTSERVICE} ]] @@ -81,12 +122,12 @@ then fi # check if the new key is registered - SALTKEYS=$(docker exec -t -i ${DCMAINHASH} /bin/bash -c "salt-key -L" | grep "${NAME}.local") - until [[ -z ${SALTKEYS} ]] + SALTKEYS=$(docker exec -t -i ${DCMAINHASH} /bin/bash -c "salt-key -L" | grep "${INSTANCE}.local") + until [[ ! -z ${SALTKEYS} ]] do echo "Key not ready yet ... waiting" sleep 5 - SALTKEYS=$(docker exec -t -i ${DCMAINHASH} /bin/bash -c "salt-key -L" | grep "${NAME}.local") + SALTKEYS=$(docker exec -t -i ${DCMAINHASH} /bin/bash -c "salt-key -L" | grep "${INSTANCE}.local") done echo "Key ready" diff --git a/src/lib/instances/update/update.sh b/src/lib/instances/update/update.sh index 5733d017..a6a0d29c 100755 --- a/src/lib/instances/update/update.sh +++ b/src/lib/instances/update/update.sh @@ -74,6 +74,8 @@ then docker exec -t -i ${DCMAINHASH} /bin/bash -c "salt '${PROJECT_NAME}.local' state.highstate saltenv=dev --state-output=terse" docker exec -t -i ${DCMAINHASH} /bin/bash -c "salt '${PROJECT_NAME}.local' state.highstate saltenv=php${PROJECT_PHP_VERSION} --state-output=terse" + docker commit ${DCHASH} doil/${PROJECT_NAME}:stable + NOW=$(date +'%d.%m.%Y %I:%M:%S') echo "[$NOW] Instance updated" else diff --git a/src/lib/system/version/version.sh b/src/lib/system/version/version.sh index 567076dd..d9ccc6bb 100755 --- a/src/lib/system/version/version.sh +++ b/src/lib/system/version/version.sh @@ -1,3 +1,3 @@ #!/bin/bash -echo "doil version 1.0 - build 2021-03-xx" \ No newline at end of file +echo "doil version 1.0.3 - build 2021-05-02" \ No newline at end of file diff --git a/src/tpl/main/Dockerfile b/src/tpl/main/Dockerfile index c7f4de50..454da368 100644 --- a/src/tpl/main/Dockerfile +++ b/src/tpl/main/Dockerfile @@ -1,8 +1,6 @@ FROM debian:stable RUN apt-get update -RUN apt-get install -y vim less procps supervisor salt-master +RUN apt-get install -y vim less virt-what net-tools procps salt-master -COPY run-supervisor.sh /usr/local/bin/run-supervisor.sh -RUN chmod a+x /usr/local/bin/run-supervisor.sh -CMD ["/usr/local/bin/run-supervisor.sh"] +ENTRYPOINT ["salt-master", "-l", "debug"] \ No newline at end of file diff --git a/src/tpl/main/docker-compose.yml b/src/tpl/main/docker-compose.yml index 257cf9c3..802a3730 100644 --- a/src/tpl/main/docker-compose.yml +++ b/src/tpl/main/docker-compose.yml @@ -4,14 +4,13 @@ services: build: context: . dockerfile: Dockerfile - image: debian:stable + image: saltmain container_name: saltmain hostname: saltmain domainname: local volumes: - ./../stack/states:/srv/salt/states - ./../stack/config/master.cnf:/etc/salt/master - - ./salt-main.conf:/etc/supervisor/conf.d/salt-main.conf networks: saltnet: ipv4_address: 172.100.0.2 diff --git a/src/tpl/main/run-supervisor.sh b/src/tpl/main/run-supervisor.sh deleted file mode 100755 index 1cdef391..00000000 --- a/src/tpl/main/run-supervisor.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -/usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf diff --git a/src/tpl/main/salt-main.conf b/src/tpl/main/salt-main.conf deleted file mode 100644 index ea71dd41..00000000 --- a/src/tpl/main/salt-main.conf +++ /dev/null @@ -1,5 +0,0 @@ -[program:salt-master] -command=/bin/bash -c "salt-master -d" -autostart=true -autorestart=false -user=root diff --git a/src/tpl/minion/Dockerfile b/src/tpl/minion/Dockerfile index ddd70f85..3440f099 100644 --- a/src/tpl/minion/Dockerfile +++ b/src/tpl/minion/Dockerfile @@ -1,7 +1,7 @@ FROM debian:stable RUN apt-get update -RUN apt-get install -y supervisor salt-minion +RUN apt-get install -y salt-minion supervisor COPY conf/run-supervisor.sh /usr/local/bin/ RUN chmod +x /usr/local/bin/run-supervisor.sh diff --git a/update.sh b/update.sh index 69628d0f..133e513c 100755 --- a/update.sh +++ b/update.sh @@ -126,9 +126,17 @@ if [ ! -d "/usr/local/lib/doil" ] then mkdir /usr/local/lib/doil fi + +# copy the files cp -r src/lib /usr/local/lib/doil/lib chmod -R a+x /usr/local/lib/doil/lib +rm -rf /usr/local/lib/doil/tpl/main +cp -r src/tpl/main /usr/local/lib/doil/tpl/main + +rm -rf /usr/local/lib/doil/tpl/minion +cp -r src/tpl/minion /usr/local/lib/doil/tpl/minion + ################# # Everything done NOW=$(date +'%d.%m.%Y %I:%M:%S')