-
Notifications
You must be signed in to change notification settings - Fork 2
/
run-bahmni.sh
executable file
·205 lines (164 loc) · 6.09 KB
/
run-bahmni.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/bin/bash
function checkDockerAndDockerComposeVersion {
# Check if docker is installed
if ! [ -x "$(command -v docker)" ]; then
echo 'Error: docker is not installed. Please install docker first!' >&2
exit 1
fi
DOCKER_SERVER_VERSION=$(docker version -f "{{.Server.Version}}")
DOCKER_SERVER_VERSION_MAJOR=$(echo "$DOCKER_SERVER_VERSION"| cut -d'.' -f 1)
DOCKER_SERVER_VERSION_MINOR=$(echo "$DOCKER_SERVER_VERSION"| cut -d'.' -f 2)
DOCKER_SERVER_VERSION_BUILD=$(echo "$DOCKER_SERVER_VERSION"| cut -d'.' -f 3)
if [ "${DOCKER_SERVER_VERSION_MAJOR}" -ge 20 ]; then
echo 'Docker version >= 20.10.13, using Docker Compose V2'
else
echo 'Docker versions < 20.x are not supported' >&2
exit 1
fi
# Check the version of Docker Compose
if ! [ -x "$(command -v docker compose version)" ]; then
echo 'Error: docker compose is not installed. Please install docker compose.' >&2
exit 1
fi
version=$(docker compose version)
echo "Docker Compose version: $version"
echo "---"
}
function checkIfDirectoryIsCorrect {
# Current subdirectory
current_subdir=$(basename $(pwd))
echo "$current_subdir"
if [ "$current_subdir" == "snomed-clinic" ] || [ "$current_subdir" == "snomed-standard" ] || [ "$current_subdir" == "snomed-clinic-with-snowstorm-lite" ] || [ "$current_subdir" == "snomed-standard-with-snowstorm-lite" ] ; then
return
else
echo "Error: This script should be run from either 'snomed-clinic' or 'snomed-standard' subfolder. Please cd to the appropriate sub-folder and then execute the run-bahmni.sh command."
exit 1
fi
}
function start {
echo "Executing command: 'docker compose up -d'"
echo "Starting Bahmni with default profile from .env file"
docker compose up -d
}
function stop {
echo "Executing command: 'docker compose down' with all profiles"
docker compose --profile emr --profile snomed-clinic --profile snomed-standard down
}
function sshIntoService {
# Using all profiles, so that we can status of all services
echo "Listing the running services..."
docker compose --profile snomed-clinic --profile snomed-standard ps
echo "Enter the SERVICE name which you wish to ssh into:"
read serviceName
docker compose exec $serviceName /bin/sh
}
function showLogsOfService {
# Using all profiles, so that we can status of all services
echo "Listing the running services..."
docker compose --profile snomed-clinic --profile snomed-standard ps
echo "Enter the SERVICE name whose logs you wish to see:"
read serviceName
docker compose logs $serviceName -f
}
function showOpenMRSlogs {
echo "Opening OpenMRS Logs..."
docker compose logs openmrs -f
}
function pullLatestImages {
echo "Pulling all latest images..."
docker compose pull
}
function showStatus {
echo "Listing status of running Services with command: 'docker compose ps'"
# Using all profiles, so that we can status of all services
docker compose --profile snomed-clinic --profile snomed-standard ps
}
# Function to prompt the user for a "Yes" or "No" answer
confirm() {
read -p "$1 [y/n]: " response
case $response in
[yY][eE][sS]|[yY])
return 0
;;
[nN][oO]|[nN])
return 1
;;
*)
echo "Invalid input"
return 1
esac
}
function resetAndEraseALLVolumes {
echo "Listing current volumes..."
docker volume ls
echo "---"
if confirm "WARNING: Are you sure you want to DELETE all Bahmni Data and Volumes??"; then
echo "Proceeding with a DELETE.... "
echo "1. Stopping all services, using all profiles.."
docker compose --profile emr --profile snomed-clinic --profile snomed-standard down
docker compose ps
echo "2. Deleting all volumes (-v) .."
docker compose --profile emr --profile snomed-clinic --profile snomed-standard down -v
RESULT=$?
if [ $RESULT -eq 0 ]; then
echo "Volumes deleted successfully."
else
echo "[ERROR] Command threw an error! Trying stopping all services, and then retry."
fi
echo "Volumes remaining on machine 'docker volume ls': "
docker volume ls
echo "-"
echo "Note:"
echo "-----"
echo "1. If you still wish to delete some other volumes you can use the 'docker volume rm' command."
echo "2. Alternatively, to delete all containers, networks, volumes you can look at the 'docker system prune --volumes' command. Read more here: https://docs.docker.com/config/pruning/"
echo "3. If you want the latest Bahmni images, then PULL them first and then start Bahmni."
else
echo "OK Aborting :)"
fi
}
function restartService {
# One can ONLY restart services in current profile (limitation of docker compose restart command).
echo "Listing the running services from current profile (.env file) that can be restarted..."
docker compose ps
echo "Enter the name of the SERVICE to restart:"
read serviceName
echo "Restarting SERVICE: $serviceName"
docker compose restart $serviceName
if confirm "Do you want to see the service logs?"; then
docker compose logs $serviceName -f
fi
}
#Function to shutdown the script
function shutdown {
exit 0
}
# Check Docker Compose versions first
checkDockerAndDockerComposeVersion
# Check Directory is correct
checkIfDirectoryIsCorrect
echo "Please select an option:"
echo "------------------------"
echo "1) START Bahmni services"
echo "2) STOP Bahmni services"
echo "3) LOGS: Show OpenMRS Logs"
echo "4) LOGS: Show LOGS of a service"
echo "5) SSH into a Container"
echo "6) PULL latest images from Docker hub for Bahmni"
echo "7) RESET and ERASE All Volumes/Databases from docker!"
echo "8) RESTART a service"
echo "9) STATUS of all services"
echo "-------------------------"
read option
case $option in
1) start;;
2) stop;;
3) showOpenMRSlogs;;
4) showLogsOfService;;
5) sshIntoService;;
6) pullLatestImages;;
7) resetAndEraseALLVolumes;;
8) restartService;;
9) showStatus;;
*) echo "Invalid option selected";;
esac