Commit 3469694ed16de06c22bae68639c045420a352efc
1 parent
c8831bc5
1
Showing
1 changed file
with
91 additions
and
0 deletions
bootstrap.sh
0 → 100644
| 1 | +#!/bin/bash | |
| 2 | + | |
| 3 | +###################################################### | |
| 4 | +# Copyright 2019 Pham Ngoc Hoai | |
| 5 | +# | |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); | |
| 7 | +# you may not use this file except in compliance with the License. | |
| 8 | +# You may obtain a copy of the License at | |
| 9 | +# | |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 | |
| 11 | +# | |
| 12 | +# Unless required by applicable law or agreed to in writing, software | |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, | |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 15 | +# See the License for the specific language governing permissions and | |
| 16 | +# limitations under the License. | |
| 17 | +# | |
| 18 | +# Repo: https://github.com/tyrion9/spring-boot-startup-script | |
| 19 | +# | |
| 20 | +######### PARAM ###################################### | |
| 21 | + | |
| 22 | +JAVA_OPT=-Xmx1024m | |
| 23 | +JARFILE=`ls -1r *.jar 2>/dev/null | head -n 1` | |
| 24 | +PID_FILE=pid.file | |
| 25 | +RUNNING=N | |
| 26 | +PWD=`pwd` | |
| 27 | + | |
| 28 | +######### DO NOT MODIFY ######## | |
| 29 | + | |
| 30 | +if [ -f $PID_FILE ]; then | |
| 31 | + PID=`cat $PID_FILE` | |
| 32 | + if [ ! -z "$PID" ] && kill -0 $PID 2>/dev/null; then | |
| 33 | + RUNNING=Y | |
| 34 | + fi | |
| 35 | +fi | |
| 36 | + | |
| 37 | +start() | |
| 38 | +{ | |
| 39 | + if [ $RUNNING == "Y" ]; then | |
| 40 | + echo "Application already started" | |
| 41 | + else | |
| 42 | + if [ -z "$JARFILE" ] | |
| 43 | + then | |
| 44 | + echo "ERROR: jar file not found" | |
| 45 | + else | |
| 46 | + nohup java $JAVA_OPT -Djava.security.egd=file:/dev/./urandom -jar $PWD/$JARFILE > nohup.out 2>&1 & | |
| 47 | + echo $! > $PID_FILE | |
| 48 | + echo "Application $JARFILE starting..." | |
| 49 | + tail -f nohup.out | |
| 50 | + fi | |
| 51 | + fi | |
| 52 | +} | |
| 53 | + | |
| 54 | +stop() | |
| 55 | +{ | |
| 56 | + if [ $RUNNING == "Y" ]; then | |
| 57 | + kill -9 $PID | |
| 58 | + rm -f $PID_FILE | |
| 59 | + echo "Application stopped" | |
| 60 | + else | |
| 61 | + echo "Application not running" | |
| 62 | + fi | |
| 63 | +} | |
| 64 | + | |
| 65 | +restart() | |
| 66 | +{ | |
| 67 | + stop | |
| 68 | + start | |
| 69 | +} | |
| 70 | + | |
| 71 | +case "$1" in | |
| 72 | + | |
| 73 | + 'start') | |
| 74 | + start | |
| 75 | + ;; | |
| 76 | + | |
| 77 | + 'stop') | |
| 78 | + stop | |
| 79 | + ;; | |
| 80 | + | |
| 81 | + 'restart') | |
| 82 | + restart | |
| 83 | + ;; | |
| 84 | + | |
| 85 | + *) | |
| 86 | + echo "Usage: $0 { start | stop | restart }" | |
| 87 | + exit 1 | |
| 88 | + ;; | |
| 89 | +esac | |
| 90 | +exit 0 | |
| 91 | + | ... | ... |