Skip to content

Commit

Permalink
Merge pull request #43 from lauraquellmalz/systemd
Browse files Browse the repository at this point in the history
Fixed several issues with the init system for the salt master
  • Loading branch information
Laura authored Apr 29, 2021
2 parents c0fa72c + 12ceae0 commit d5663ea
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 40 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
16 changes: 1 addition & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
* `doil salt:prune` prunes the main salt server
21 changes: 21 additions & 0 deletions src/lib/instances/create/create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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} ]]
Expand Down
2 changes: 1 addition & 1 deletion src/lib/instances/delete/delete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
59 changes: 50 additions & 9 deletions src/lib/instances/repair/repair.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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" ]
Expand All @@ -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
Expand All @@ -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} ]]
Expand All @@ -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"

Expand Down
2 changes: 2 additions & 0 deletions src/lib/instances/update/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/lib/system/version/version.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

echo "doil version 1.0 - build 2021-03-xx"
echo "doil version 1.0.3 - build 2021-05-02"
6 changes: 2 additions & 4 deletions src/tpl/main/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
3 changes: 1 addition & 2 deletions src/tpl/main/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/tpl/main/run-supervisor.sh

This file was deleted.

5 changes: 0 additions & 5 deletions src/tpl/main/salt-main.conf

This file was deleted.

2 changes: 1 addition & 1 deletion src/tpl/minion/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 8 additions & 0 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit d5663ea

Please sign in to comment.