Using systemd to mount volumes and start containers at boot.

This commit is contained in:
yohan 2020-03-31 18:00:50 +02:00
parent a416ef63cb
commit 149302a745
6 changed files with 74 additions and 34 deletions

21
create.sh Executable file
View File

@ -0,0 +1,21 @@
#!/bin/bash
#Absolute path to this script
SCRIPT=$(readlink -f $0)
#Absolute path this script is in
SCRIPTPATH=$(dirname $SCRIPT)
cd $SCRIPTPATH
unset VERSION_APACHE_FPM VERSION_PHP_FPM
export VERSION_APACHE_FPM=$(git ls-remote https://git.scimetis.net/yohan/docker-apache-for-fpm.git| head -1 | cut -f 1|cut -c -10)
export VERSION_PHP_FPM=$(git ls-remote https://git.scimetis.net/yohan/docker-php5-fpm.git| head -1 | cut -f 1|cut -c -10)
mkdir -p ~/build
git clone https://git.scimetis.net/yohan/docker-apache-for-fpm.git ~/build/docker-apache-for-fpm
sudo docker build -t apache-scuttle:$VERSION_APACHE_FPM ~/build/docker-apache-for-fpm
git clone https://git.scimetis.net/yohan/docker-php5-fpm.git ~/build/docker-php5-fpm
sudo docker build -t php5-fpm:$VERSION_PHP_FPM ~/build/docker-php5-fpm
sudo -E bash -c 'docker-compose up --no-start'
rm -rf ~/build

View File

@ -6,7 +6,6 @@ services:
image: apache-scuttle:$VERSION_APACHE_FPM image: apache-scuttle:$VERSION_APACHE_FPM
#build: "https://git.scimetis.net/yohan/docker-apache-for-fpm.git" #build: "https://git.scimetis.net/yohan/docker-apache-for-fpm.git"
container_name: apache-scuttle container_name: apache-scuttle
restart: always
networks: networks:
- reverse-proxy - reverse-proxy
- php5-fpm - php5-fpm
@ -20,7 +19,6 @@ services:
image: php5-fpm:$VERSION_PHP_FPM image: php5-fpm:$VERSION_PHP_FPM
#build: "https://git.scimetis.net/yohan/docker-php5-fpm.git" #build: "https://git.scimetis.net/yohan/docker-php5-fpm.git"
container_name: php5-fpm container_name: php5-fpm
restart: always
networks: networks:
- php5-fpm - php5-fpm
- mysqlnet - mysqlnet

43
install.sh Executable file
View File

@ -0,0 +1,43 @@
#!/bin/bash
#Absolute path to this script
SCRIPT=$(readlink -f $0)
#Absolute path this script is in
SCRIPTPATH=$(dirname $SCRIPT)
STACK=$(basename "$SCRIPTPATH")
for VOLUME in $(awk NF $SCRIPTPATH/volume_list | tr -d "[:blank:]")
do
systemctl enable mnt-cinder-volume@${VOLUME}.service
done
cat << EOF > /etc/systemd/system/${STACK}.service
[Unit]
Description=Starting ${STACK}
After=network-online.target firewalld.service docker.service docker.socket
Wants=network-online.target docker.service
Requires=docker.socket
EOF
for VOLUME in $(awk NF $SCRIPTPATH/volume_list | tr -d "[:blank:]")
do
VOLUME_ESCAPED=$(systemd-escape ${VOLUME})
cat << EOF >> /etc/systemd/system/${STACK}.service
After=mnt-cinder-volume@${VOLUME_ESCAPED}.service
After=mnt-volumes-${VOLUME_ESCAPED}.mount
Wants=mnt-cinder-volume@${VOLUME_ESCAPED}.service
Requires=mnt-volumes-${VOLUME_ESCAPED}.mount
EOF
done
cat << EOF >> /etc/systemd/system/${STACK}.service
[Service]
Type=oneshot
User=$SUDO_USER
ExecStart=$SCRIPTPATH/start.sh
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable ${STACK}.service

8
start.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/bash
#Absolute path to this script
SCRIPT=$(readlink -f $0)
#Absolute path this script is in
SCRIPTPATH=$(dirname $SCRIPT)
cd $SCRIPTPATH
sudo docker-compose start

View File

@ -1,32 +0,0 @@
#!/bin/bash
source ~/openrc.sh
INSTANCE=$(/home/yohan/env_py3/bin/openstack server show -c id --format value $(hostname))
sudo mkdir -p /mnt/volumes/scuttle_code /mnt/volumes/scuttle_php5-fpm_conf
if ! mountpoint -q /mnt/volumes/scuttle_code
then
VOLUME_ID=$(/home/yohan/env_py3/bin/openstack volume show scuttle_code -c id --format value)
test -e /dev/disk/by-id/*${VOLUME_ID:0:20} || nova volume-attach $INSTANCE $VOLUME_ID auto
sleep 3
sudo mount /dev/disk/by-id/*${VOLUME_ID:0:20} /mnt/volumes/scuttle_code
fi
if ! mountpoint -q /mnt/volumes/scuttle_php5-fpm_conf
then
VOLUME_ID=$(/home/yohan/env_py3/bin/openstack volume show scuttle_php5-fpm_conf -c id --format value)
test -e /dev/disk/by-id/*${VOLUME_ID:0:20} || nova volume-attach $INSTANCE $VOLUME_ID auto
sleep 3
sudo mount /dev/disk/by-id/*${VOLUME_ID:0:20} /mnt/volumes/scuttle_php5-fpm_conf
fi
unset VERSION_APACHE_FPM VERSION_PHP_FPM
export VERSION_APACHE_FPM=$(git ls-remote https://git.scimetis.net/yohan/docker-apache-for-fpm.git| head -1 | cut -f 1|cut -c -10)
export VERSION_PHP_FPM=$(git ls-remote https://git.scimetis.net/yohan/docker-php5-fpm.git| head -1 | cut -f 1|cut -c -10)
mkdir -p ~/build
git clone https://git.scimetis.net/yohan/docker-apache-for-fpm.git ~/build/docker-apache-for-fpm
sudo docker build -t apache-scuttle:$VERSION_APACHE_FPM ~/build/docker-apache-for-fpm
git clone https://git.scimetis.net/yohan/docker-php5-fpm.git ~/build/docker-php5-fpm
sudo docker build -t php5-fpm:$VERSION_PHP_FPM ~/build/docker-php5-fpm
sudo -E bash -c 'docker-compose up -d'
rm -rf ~/build

2
volume_list Normal file
View File

@ -0,0 +1,2 @@
scuttle_code
scuttle_php5-fpm_conf