Skip to content

Commit 2c572d6

Browse files
committed
Add command to restart a mongo-orchestration configuration
1 parent 40320c0 commit 2c572d6

File tree

1 file changed

+49
-23
lines changed
  • mongo-orchestration

1 file changed

+49
-23
lines changed

mongo-orchestration/mo

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,41 @@ function code {
5454
function usage {
5555
echo "usage: $0 <topology>/<configuration>.json action"
5656
echo "topology: standalone|replica_sets|sharded_clusters"
57-
echo "action: start|status|stop|url|mongo"
57+
echo "action: start|status|stop|restart|url|mongo"
5858
exit 1
5959
}
6060

61+
function start {
62+
LOGPATH=$WORKSPACE
63+
DBPATH=$WORKSPACE
64+
POST_DATA=$(eval_params $CONFIGURATION_DIR/$1)
65+
POST=$(post $BASE_URL/$R "$POST_DATA")
66+
67+
HTTP_CODE=$(code "$POST")
68+
if [ "$HTTP_CODE" != 200 ]
69+
then
70+
echo "Could not start server with configuration $R/$ID. Response below"
71+
echo $POST
72+
return 1
73+
else
74+
echo "Started configuration $R/$ID, connect using $(url "$POST")"
75+
fi
76+
}
77+
78+
function stop
79+
{
80+
DELETE=$(delete $BASE_URL/$R/$ID)
81+
HTTP_CODE=$(code "$DELETE")
82+
if [ "$HTTP_CODE" != 204 ]
83+
then
84+
echo "Could not stop configuration $R/$ID. Response below"
85+
echo $DELETE
86+
return 1
87+
else
88+
echo "Configuration $R/$ID stopped successfully."
89+
fi
90+
}
91+
6192
SSL_FILES=$(a ./ssl-files)
6293
BASE_URL=${MONGO_ORCHESTRATION:-'http://localhost:8889'}
6394
WORKSPACE=/tmp/orchestrations
@@ -83,36 +114,31 @@ case $2 in
83114
start)
84115
if [ "$HTTP_CODE" != "200" ]
85116
then
86-
LOGPATH=$WORKSPACE
87-
DBPATH=$WORKSPACE
88-
POST_DATA=$(eval_params $CONFIGURATION_DIR/$1)
89-
POST=$(post $BASE_URL/$R "$POST_DATA")
90-
91-
HTTP_CODE=$(code "$POST")
92-
if [ "$HTTP_CODE" != 200 ]
93-
then
94-
echo "Could not start server with configuration $R/$ID. Response below"
95-
echo $POST
96-
EXIT_CODE=1;
97-
else
98-
echo "Started configuration $R/$ID, connect using $(url "$POST")"
99-
fi
117+
start $1
118+
EXIT_CODE=$?
100119
else
101120
echo "Configuration $R/$ID already running! Connect using $(url "$GET")"
102121
fi
103122
;;
104123
stop)
105124
if [ "$HTTP_CODE" == "200" ]
106125
then
107-
DELETE=$(delete $BASE_URL/$R/$ID)
108-
HTTP_CODE=$(code "$DELETE")
109-
if [ "$HTTP_CODE" != 204 ]
126+
stop $1
127+
EXIT_CODE=$?
128+
else
129+
echo "Configuration $R/$ID is not running!"
130+
fi
131+
;;
132+
restart)
133+
if [ "$HTTP_CODE" == "200" ]
134+
then
135+
stop $1
136+
EXIT_CODE=$?
137+
138+
if [ "$EXIT_CODE" == "0" ]
110139
then
111-
echo "Could not stop configuration $R/$ID. Response below"
112-
echo $DELETE
113-
EXIT_CODE=1
114-
else
115-
echo "Configuration $R/$ID stopped successfully."
140+
start $1
141+
EXIT_CODE=$?
116142
fi
117143
else
118144
echo "Configuration $R/$ID is not running!"

0 commit comments

Comments
 (0)