Browse Source

Adding up and down commands for standalone jar

Jim Barritt 11 months ago
parent
commit
605ba4c661

+ 2 - 0
apps/petitions/decode-app/.gitignore

@@ -8,3 +8,5 @@ pom.xml
8 8
 
9 9
 *.iml
10 10
 .idea/
11
+*.pid
12
+

+ 5 - 1
apps/petitions/decode-app/ops/local/_lib.sh

@@ -11,6 +11,10 @@ function lib/process_commands {
11 11
     ${CMD} $@
12 12
 }
13 13
 
14
+function lib/ps {
15
+    PROCESS_PATTERN=$1
16
+    echo $(ps aux | grep ${PROCESS_PATTERN} | grep -v grep)
17
+}
14 18
 
15 19
 # https://stackoverflow.com/questions/11231937/bash-ignoring-error-for-a-particular-command
16 20
 # -o makes the output disappear, -s means silent so it doesnt show you what download status
@@ -27,7 +31,7 @@ function lib/http_status_of {
27 31
 function lib/wait_for_service {
28 32
   HOST=$1
29 33
   ATTEMPTS=0
30
-  echo "\nWaiting for service to appear @ ${HOST} ...\n"
34
+  echo -e "\nWaiting for service to appear @ ${HOST} ...\n"
31 35
   while :
32 36
   do
33 37
     echo "Trying to reach ${HOST} [${ATTEMPTS}] ..."

+ 32 - 2
apps/petitions/decode-app/ops/local/decode-app.sh

@@ -26,11 +26,20 @@ function check_pre_requisites {
26 26
 
27 27
 
28 28
 function status {
29
-    
29
+
30 30
     HTTP_STATUS=$(lib/http_status_of ${DECODE_APP_URL})
31 31
 
32 32
 
33 33
     echo -e "\nStatus of decode-app @ ${DECODE_APP_URL}: ${HTTP_STATUS}\n"
34
+
35
+    PROCESS_LIST=$(lib/ps java.*decode-app)
36
+
37
+    if [[ ! ${PROCESS_LIST} == "" ]]; then
38
+        echo -e "Processes: \n${PROCESS_LIST}\n"
39
+    else
40
+        echo -e "No processes for decode-app found\n"
41
+    fi
42
+
34 43
 }
35 44
 
36 45
 function logs {
@@ -50,9 +59,30 @@ function package {
50 59
 }
51 60
 
52 61
 function up {
53
-    echo -e  "\nBringing up local decode-app in background, to access, type 'jobs' and 'fg <n>' where n is the job number. To kill 'do decode-app down'.\n"
62
+    echo -e  "\nBringing up local decode-app in background, to access. To kill 'do decode-app down'.\n"
54 63
 
55 64
     java -jar target/decode-app-0.1.0-SNAPSHOT-standalone.jar &> ${DECODE_APP_LOG_FILE} &
65
+
66
+    echo $! > .decode-app.pid
67
+
68
+    lib/wait_for_service ${DECODE_APP_URL}
69
+    status
70
+}
71
+
72
+# https://www.tecmint.com/how-to-kill-a-process-in-linux/
73
+function down {
74
+    echo -e "\nTaking down local decode-app...\n"
75
+
76
+
77
+    if [[ ! -e .decode-app.pid ]]; then
78
+        echo -e "No pid file [.decode-app.pid], cannot kill app - try 'status' and do it manually or ps yourself."
79
+    else
80
+        PID=$(cat .decode-app.pid)
81
+        kill -15 ${PID}
82
+        status
83
+    fi
84
+
85
+
56 86
 }
57 87
 function init-db {
58 88
     echo -e "\nCleaning and initialising a sample database in [${DECODE_APP_DB_NAME}]...\n"

+ 1 - 1
apps/petitions/decode-app/ops/local/mongo.sh

@@ -44,7 +44,7 @@ function logs {
44 44
 function up {
45 45
     echo -e "\nStarting local docker container with mongo (run [${SCRIPT_HOME}/mongo.sh docker-logs] to see details)\n"
46 46
     ${DOCKER_COMMAND}  up -d
47
-    lib/wait_for_service $MONGO_URL
47
+    lib/wait_for_service ${MONGO_URL}
48 48
     status
49 49
 }
50 50
 

+ 2 - 0
apps/petitions/decode-app/src/decode_app/handler.clj

@@ -44,6 +44,8 @@
44 44
 (defroutes app-routes
45 45
            (GET "/" [] (layout/application "Index" (contents/index)))
46 46
 
47
+           (GET "/status" [] (header (response (status/get-status)) "Access-Control-Allow-Origin" "*"))
48
+
47 49
            (GET "/petitions" [] (header (response (petitions/get-petitions)) "Access-Control-Allow-Origin" "*"))
48 50
 
49 51
            (GET "/petitions/:id" [id] (header (response (petitions/get-petition id)) "Access-Control-Allow-Origin" "*"))

+ 4 - 0
apps/petitions/decode-app/src/decode_app/status.clj

@@ -0,0 +1,4 @@
1
+(ns decode-app.status)
2
+
3
+(defn get-status []
4
+  {:mongo-connection "UP"})