Skip to content
This repository has been archived by the owner on Jun 3, 2023. It is now read-only.

Commit

Permalink
tested auto create database after container startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Li Lin committed Jan 29, 2015
1 parent 3cb7005 commit e97c924
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 23 deletions.
3 changes: 1 addition & 2 deletions atl-postgres/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FROM postgres:9.3
MAINTAINER Li Lin <[email protected]>

RUN mkdir -p /docker-entrypoint-initdb.d
ADD atl-dbinit.sh /docker-entrypoint-initdb.d
ADD dbinit.sh /docker-entrypoint-initdb.d/


14 changes: 0 additions & 14 deletions atl-postgres/atl-dbinit.sh

This file was deleted.

Empty file modified atl-postgres/build.sh
100644 → 100755
Empty file.
15 changes: 15 additions & 0 deletions atl-postgres/dbinit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

echo "******CREATING APPLICATIONS DATABASES ******"

gosu postgres postgres --single <<- EOSQL
CREATE DATABASE jira WITH ENCODING='UTF8' TEMPLATE=template0;
CREATE DATABASE stash WITH ENCODING='UTF8' TEMPLATE=template0;
CREATE DATABASE fisheye WITH ENCODING='UTF8' TEMPLATE=template0;
CREATE DATABASE bamboo WITH ENCODING='UTF8' TEMPLATE=template0;
EOSQL

echo "******APPLICATION DATABASES CREATED******"

19 changes: 12 additions & 7 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ echo "

is_container_running() {

if [ "`docker inspect -f '{{ .State.Running }}' $1 `" = "true" ]; then
if [ "`docker inspect -f '{{ .State.Running }}' $1 2> /dev/null `" = "true" ]; then
return 1
else
return 0
Expand All @@ -46,8 +46,8 @@ is_container_running() {

stop_and_rm_container() {

is_container_running $1 && docker stop $1
(docker ps -a | grep $1) || docker rm $1
is_container_running $1 || docker stop $1
(docker ps -a | grep $1 > /dev/null) && docker rm $1
}


Expand All @@ -59,8 +59,9 @@ start_app() {
RUN_MODE="-d"
fi

# start data container if it does not exist
(docker ps -a | grep atldata) && start_data
stop_and_rm_container $1

start_data

docker run $RUN_MODE --name $1 --link postgres:db \
--volumes-from="atldata" -e BASE_URL=$BASE_URL \
Expand All @@ -71,17 +72,20 @@ start_app() {
start_db() {

stop_and_rm_container postgres

start_data

docker run -d --name postgres -e POSTGRES_PASSWORD=password \
--volumes-from="atldata" ${DOCKER_HUB_USER}/atl-postgres
}


start_data() {
(docker ps -a | grep atldata) && \
(docker ps -a | grep atldata > /dev/null) || \
docker run --name atldata \
-v /opt/atlassian-home \
-v /var/lib/postgresql/data \
centos:7 echo "data container atldata started"
centos:7 echo atldata container
}


Expand Down Expand Up @@ -143,6 +147,7 @@ case "$ACTION" in
stop_and_rm_container $1
start_app $1 $2 $3 $4
test -z "$2" && start_web

;;

web)
Expand Down

0 comments on commit e97c924

Please sign in to comment.