Using systemd to mount volumes and start containers at boot.
This commit is contained in:
parent
859bdf07f6
commit
d21acb90f4
17
create.sh
Executable file
17
create.sh
Executable file
@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
#Absolute path to this script
|
||||
SCRIPT=$(readlink -f $0)
|
||||
#Absolute path this script is in
|
||||
SCRIPTPATH=$(dirname $SCRIPT)
|
||||
|
||||
cd $SCRIPTPATH
|
||||
unset VERSION_ELASTICSEARCH
|
||||
export VERSION_ELASTICSEARCH=$(git ls-remote https://git.scimetis.net/yohan/docker-elasticsearch.git| head -1 | cut -f 1|cut -c -10)
|
||||
|
||||
mkdir -p ~/build
|
||||
git clone https://git.scimetis.net/yohan/docker-elasticsearch.git ~/build/docker-elasticsearch
|
||||
sudo docker build -t elasticsearch:$VERSION_ELASTICSEARCH ~/build/docker-elasticsearch
|
||||
|
||||
sudo -E bash -c 'docker-compose up --no-start'
|
||||
|
||||
rm -rf ~/build
|
@ -9,7 +9,6 @@ services:
|
||||
environment:
|
||||
- discovery.type=single-node
|
||||
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
|
||||
restart: always
|
||||
expose:
|
||||
- '9200'
|
||||
- '9300'
|
||||
|
42
install.sh
Executable file
42
install.sh
Executable 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 $(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
|
||||
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 ${STACK}.service
|
8
start.sh
Executable file
8
start.sh
Executable 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
|
@ -1,23 +0,0 @@
|
||||
#!/bin/bash
|
||||
# --force-recreate is used to recreate container when crontab file has changed
|
||||
source ~/openrc.sh
|
||||
INSTANCE=$(/home/yohan/env_py3/bin/openstack server show -c id --format value $(hostname))
|
||||
sudo mkdir -p /mnt/volumes/elasticsearch_data
|
||||
if ! mountpoint -q /mnt/volumes/elasticsearch_data
|
||||
then
|
||||
VOLUME_ID=$(/home/yohan/env_py3/bin/openstack volume show elasticsearch_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/elasticsearch_data
|
||||
fi
|
||||
|
||||
unset VERSION_ELASTICSEARCH
|
||||
export VERSION_ELASTICSEARCH=$(git ls-remote https://git.scimetis.net/yohan/docker-elasticsearch.git| head -1 | cut -f 1|cut -c -10)
|
||||
|
||||
mkdir -p ~/build
|
||||
git clone https://git.scimetis.net/yohan/docker-elasticsearch.git ~/build/docker-elasticsearch
|
||||
sudo docker build -t elasticsearch:$VERSION_ELASTICSEARCH ~/build/docker-elasticsearch
|
||||
|
||||
sudo -E bash -c 'docker-compose up -d --force-recreate'
|
||||
|
||||
rm -rf ~/build
|
1
volume_list
Normal file
1
volume_list
Normal file
@ -0,0 +1 @@
|
||||
elasticsearch_data
|
Loading…
Reference in New Issue
Block a user