dubdiff/startup

60 lines
1.7 KiB
Bash
Executable File

#! /bin/bash
echo "* this script must be run as super user"
# Start a data container, an ssh server, a mongodb instance and a samba server
echo
# test if the data-db container has been created
if docker inspect -f {{.Name}} data-db
then
echo "* data-db exists"
else
echo "* creating data-db"
# The data container has a volume at /data/db, is named 'data' and is based on busybox
docker create -v /data/db --name data-db busybox echo "Data container - database"
fi
echo
# test if the mongo db server has been created
if docker inspect -f {{.Name}} mongodb
then
# make sure the server is running
if docker inspect -f {{.State.Running}} mongodb
then
echo "* mongodb exists and is running"
else
echo "* starting mongodb"
docker start mongodb
fi
else
echo "* creating new mongodb server"
# Start a mongo db server as a daemon
# The server will restart automatically on boot and will use the data-db container as a volume
docker run -p 27017 --restart=always --name=mongodb --volumes-from=data-db -d mongo
fi
echo
# test if the data-files container has been created
if docker inspect -f {{.Name}} data-files
then
echo "* data-files exists"
else
echo "* creating data-files"
# The data container has a volume at /data/db, is named 'data' and is based on busybox
docker create -v /data --name data-files busybox echo "Data container - files"
# To connect a client to this server we would:
# sudo docker run --link=mongodb:mongodb -i mongo mongo --host mongodb
fi
# create the samba server
echo "* creating samba server"
sudo docker run --rm -v $(which docker):/docker -v /var/run/docker.sock:/docker.sock svendowideit/samba data-files