Index: install.sh =================================================================== diff -u -r67dac68b5a26c29a1e15ab754977b3fe49ed05ff -r2daa7b178d54b1fa2ee6e8021c4940191b361dae --- install.sh (.../install.sh) (revision 67dac68b5a26c29a1e15ab754977b3fe49ed05ff) +++ install.sh (.../install.sh) (revision 2daa7b178d54b1fa2ee6e8021c4940191b361dae) @@ -1,5 +1,8 @@ #!/bin/bash +TRUE=0 +FALSE=1 + # ---------- Error definition ERR_DRT_SERVER_DIR_EXISTS=1 ERR_DRT_SERVER_ENV_INVALID=2 @@ -167,19 +170,62 @@ # TODO create a script to stop/start the service instead of a direct symlink local RUNSH="run.sh" cd $DRT_SERVER_DST - local is_running="-n \$(ps aux | grep \"node dist\" | grep -v grep)" echo -e "#!/bin/bash\n" \ "\n" \ - "if [[ $is_running ]]; then\n" \ - " echo \"--------------------------------------- DRT Server is running\"\n" \ - " exit 0\n"\ + "function is_running() {\n" \ + " if [[ -n \$(ps aux | grep \"node dist\" | grep -v grep) ]]\n" \ + " then return $TRUE; else return $FALSE; fi\n" \ + "}\n" \ + "\n" \ + "function is_kill() {\n" \ + " if [[ \"\$1\" == \"-k\" ]]\n" \ + " then return $TRUE; else return $FALSE; fi\n" \ + "}\n" \ + "\n" \ + "function is_status() {\n" \ + " if [[ \"\$1\" == \"-s\" ]]\n" \ + " then return $TRUE; else return $FALSE; fi\n" \ + "}\n" \ + "\n" \ + "function is_help() {\n" \ + " if [[ \"\$1\" == \"-h\" ]]\n" \ + " then\n" \ + " echo \"-h displays help\"\n" \ + " echo \"-s displays DRT Server status (optional)\"\n" \ + " echo \"-k kills DRT Server\"\n" \ + " exit 0\n" \ + " fi\n" \ + "}\n" \ + "\n" \ + "is_help \$1\n" \ + "\n" \ + "if is_running; then\n" \ + " if is_kill \$1; then\n" \ + " echo \"--------------------------------------- DRT Server is stopping\"\n" \ + " killall node\n" \ + " sleep 5\n" \ + " if is_running; then\n" \ + " echo \"--------------------------------------- DRT Server stop FAILED\"\n" \ + " else\n" \ + " echo \"--------------------------------------- DRT Server stopped\"\n" \ + " fi\n" \ + " exit 0\n" \ + " else\n" \ + " echo \"--------------------------------------- DRT Server is running\"\n" \ + " exit 0\n" \ + " fi\n" \ + "else\n" \ + " if is_kill \$1 || is_status \$1; then\n" \ + " echo \"--------------------------------------- DRT Server is NOT running\"\n" \ + " exit 0\n" \ + " fi\n" \ "fi\n" \ "\n" \ - " echo \"--------------------------------------- DRT Server starting ...\"\n" \ - "cd $DRT_SERVER_DST\n" \ + "echo \"--------------------------------------- DRT Server starting ...\"\n" \ + "cd /home/denali/drt-server\n" \ "node dist/apps/mt-api/main.js &\n" \ "sleep 10\n" \ - "if [[ $is_running ]]; then\n" \ + "if is_running; then\n" \ " echo \"--------------------------------------- DRT Server started\"\n" \ "else\n" \ " echo \"---------------------------------- ERR: DRT Server start FAILED\"\n" \