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