-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
126 lines (92 loc) · 2.74 KB
/
deploy.sh
File metadata and controls
126 lines (92 loc) · 2.74 KB
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
#!/bin/bash
# COMMAND LINE VARIABLES
# deploy port SECOND ARGUMENT
# Ex: 8090 | 8091 | 8092
serverPort=$1
# THIRD ARGUMENT project name, deploy folder name and jar name
projectName=$2 #spring-boot
# FOURTH ARGUMENT external config file name
# Ex: application-localhost.yml
extraParams=$3
#### CONFIGURABLE VARIABLES ######
destAbsPath=/home/webadmin/bots/$projectName
configFolder=resources
##############################################################
#####
##### DONT CHANGE HERE ##############
#jar file
# $WORKSPACE is a jenkins var
sourFile=$WORKSPACE/build/libs/$projectName*.jar
destFile=$destAbsPath/$projectName.jar
#config files folder
sourConfigFolder=$WORKSPACE/$configFolder*
destConfigFolder=$destAbsPath/$configFolder
#CONSTANTS
logFile=server.log
dstLogFile=$destAbsPath/$logFile
#whatToFind="Started Application in"
whatToFind="Started "
msgLogFileCreated="$logFile created"
msgBuffer="Buffering: "
msgAppStarted="Application Started... exiting buffer!"
### FUNCTIONS
##############
function stopServer(){
echo " "
echo "Stoping process on port: $serverPort"
fuser -n tcp -k $serverPort > redirection &
echo " "
}
function deleteFiles(){
echo "Deleting $destFile"
rm -rf $destFile
# echo "Deleting $destConfigFolder"
# rm -rf $destConfigFolder
# echo "Deleting $dstLogFile"
# rm -rf $dstLogFile
echo " "
}
function copyFiles(){
echo "Copying files from $sourFile"
cp $sourFile $destFile
echo "Copying files from $sourConfigFolder"
cp -r $sourConfigFolder $destConfigFolder
echo " "
}
function run(){
#echo "java -jar $destFile --server.port=$serverPort $extraParams" | at now + 1 minutes
nohup nice java -jar $destFile --server.port=$serverPort $extraParams $> $dstLogFile 2>&1 &
echo "COMMAND: nohup nice java -jar $destFile --server.port=$serverPort $extraParams $> $dstLogFile 2>&1 &"
echo " "
}
function changeFilePermission(){
echo "Changing File Permission: chmod 777 $destFile"
chmod 777 $destFile
echo " "
}
function watch(){
tail -f $dstLogFile |
while IFS= read line
do
echo "$msgBuffer" "$line"
if [[ "$line" == *"$whatToFind"* ]]; then
echo $msgAppStarted
pkill tail
fi
done
}
### FUNCTIONS CALLS
#####################
# Use Example of this file. Args: port | project name | external resourcce
# BUILD_ID=dontKillMe /path/to/this/file/deploy.sh 9082 spring-boot application-prod.yml
# 1 - stop server on port ...
stopServer
# 2 - delete destinations folder content
deleteFiles
# 3 - copy files to deploy dir
copyFiles
changeFilePermission
# 4 - start server
run
# 5 - watch loading messages until ($whatToFind) message is found
watch