Using systemd to mount volumes and start containers at boot.

This commit is contained in:
yohan 2020-03-31 14:32:17 +02:00
parent 640163f4b3
commit c1af8b11ab
4 changed files with 56 additions and 20 deletions

8
create_and_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 up -d

View File

@ -5,7 +5,6 @@ services:
onlyoffice-document-server: onlyoffice-document-server:
container_name: onlyoffice-document-server container_name: onlyoffice-document-server
image: onlyoffice/documentserver:latest image: onlyoffice/documentserver:latest
restart: always
networks: networks:
- reverse-proxy - reverse-proxy
expose: expose:

42
install.sh Executable file
View File

@ -0,0 +1,42 @@
#!/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 onlyoffice_data onlyoffice_log
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 onlyoffice_data onlyoffice_log
do
cat << EOF >> /etc/systemd/system/${STACK}.service
After=mnt-cinder-volume@${VOLUME}.service
After=mnt-volumes-${VOLUME}.mount
Wants=mnt-cinder-volume@${VOLUME}.service
Requires=mnt-volumes-${VOLUME}.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 docker-onlyoffice-stack.service

View File

@ -1,21 +1,8 @@
#!/bin/bash #!/bin/bash
source ~/openrc.sh #Absolute path to this script
INSTANCE=$(/home/yohan/env_py3/bin/openstack server show -c id --format value $(hostname)) SCRIPT=$(readlink -f $0)
sudo mkdir -p /mnt/volumes/onlyoffice_data #Absolute path this script is in
if ! mountpoint -q /mnt/volumes/onlyoffice_data SCRIPTPATH=$(dirname $SCRIPT)
then
VOLUME_ID=$(/home/yohan/env_py3/bin/openstack volume show onlyoffice_data -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/onlyoffice_data
fi
sudo mkdir -p /mnt/volumes/onlyoffice_log
if ! mountpoint -q /mnt/volumes/onlyoffice_log
then
VOLUME_ID=$(/home/yohan/env_py3/bin/openstack volume show onlyoffice_log -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/onlyoffice_log
fi
sudo docker-compose up -d cd $SCRIPTPATH
sudo docker-compose start