From c1af8b11ab37fa048eeec1979bf3e4a2f0b59a58 Mon Sep 17 00:00:00 2001 From: yohan <783b8c87@scimetis.net> Date: Tue, 31 Mar 2020 14:32:17 +0200 Subject: [PATCH] Using systemd to mount volumes and start containers at boot. --- create_and_start.sh | 8 ++++++++ docker-compose.yml | 1 - install.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ start.sh | 25 ++++++------------------- 4 files changed, 56 insertions(+), 20 deletions(-) create mode 100755 create_and_start.sh create mode 100755 install.sh diff --git a/create_and_start.sh b/create_and_start.sh new file mode 100755 index 0000000..576230c --- /dev/null +++ b/create_and_start.sh @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index 9bae496..a6a081d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,6 @@ services: onlyoffice-document-server: container_name: onlyoffice-document-server image: onlyoffice/documentserver:latest - restart: always networks: - reverse-proxy expose: diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..1c88d49 --- /dev/null +++ b/install.sh @@ -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 diff --git a/start.sh b/start.sh index 1bb921e..1f4bfdf 100755 --- a/start.sh +++ b/start.sh @@ -1,21 +1,8 @@ #!/bin/bash -source ~/openrc.sh -INSTANCE=$(/home/yohan/env_py3/bin/openstack server show -c id --format value $(hostname)) -sudo mkdir -p /mnt/volumes/onlyoffice_data -if ! mountpoint -q /mnt/volumes/onlyoffice_data -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 +#Absolute path to this script +SCRIPT=$(readlink -f $0) +#Absolute path this script is in +SCRIPTPATH=$(dirname $SCRIPT) -sudo docker-compose up -d +cd $SCRIPTPATH +sudo docker-compose start