gitting closer, nginx working
[discourse_docker.git] / launcher
CommitLineData
7e738616
S
1#/bin/bash
2
3command=$1
4config=$2
5config_file=shared/config/"$config"/conf.yml
6cidfile=cids/"$config".cid
1acce9e4 7cidbootstrap=cids/"$config"_boostrap.cid
7e738616
S
8
9image=samsaffron/discourse
10
11[ $# -ne 2 ] && {
12 echo "Usage: launcher COMMAND CONFIG"
13 echo "Commands:"
1acce9e4
SS
14 echo " start: Start/initialize a container"
15 echo " stop: Stop a running container"
16 echo " restart: Restart a container"
17 echo " destroy: Stop and remove a container"
18 echo " shell: Start a bash shell in a running container"
19 echo " logs: Docker logs for container"
20 echo " bootstrap: Bootstrap a container for the config base on an image"
7e738616
S
21 exit 1
22}
23
24if [ ! -e $config_file ]
25 then
26 echo "Config file was not found, ensure $config_file exists"
27 exit 1
28fi
29
1acce9e4
SS
30if [ "$command" == "bootstrap" ]
31 then
32 docker run -cidfile $cidbootstrap -i -t -v `pwd`/shared:/shared samsaffron/discourse /shared/pups/bin/pups /$config_file
33 docker commit `cat $cidbootstrap` samsaffron/discourse $config
34 docker rm `cat $cidbootstrap`
35 rm $cidbootstrap
36fi
37
7e738616
S
38if [ "$command" == "shell" ]
39 then
40
41 if [ ! -e $cidfile ]
42 then
43 echo "No cid found"
44 exit 1
45 else
46 docker attach `cat $cidfile`
47 exit 0
48 fi
49fi
50
51if [ "$command" == "stop" ]
52 then
53
54 if [ ! -e $cidfile ]
55 then
56 echo "No cid found"
57 exit 1
58 else
59 docker stop -t 10 `cat $cidfile`
60 exit 0
61 fi
62fi
63
64if [ "$command" == "logs" ]
65 then
66
67 if [ ! -e $cidfile ]
68 then
69 echo "No cid found"
70 exit 1
71 else
72 docker logs `cat $cidfile`
73 exit 0
74 fi
75fi
76
77if [ "$command" == "start" ]
78 then
79
80 if [ ! -e $cidfile ]
81 then
82 echo "No cid found, creating a new container"
0cd4fb7d 83 docker run -cidfile $cidfile -p 22 -p 80 -p 3000 -d -v `pwd`/shared:/shared samsaffron/discourse:$config /usr/bin/runsvdir -P /etc/service
7e738616
S
84 exit 0
85 else
86 echo "cid found, ensuring container is started"
87 docker start `cat $cidfile`
88 exit 0
89 fi
90fi
91
92
93if [ "$command" == "destroy" ]
94 then
95 if [ -e $cidfile ]
96 then
97 echo "destroying container $cidfile"
98 docker stop -t 10 `cat $cidfile`
99 docker rm `cat $cidfile` && rm $cidfile
100 exit 0
101 else
102 echo "nothing to destroy cidfile does not exist"
103 exit 1
104 fi
105fi