This repository has been archived by the owner on Nov 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·164 lines (134 loc) · 3.3 KB
/
build.sh
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
set -e
# Paths
cd $(dirname $0)
BASE_DIR=$(pwd -P)
TEMP="${PWD}/simple-service"
PACKAGE_DIR="${PWD}/package"
NGINX_DIR="/usr/share/nginx/html"
# Getting project from github
if [ ! -d ${TEMP} ]
then
git clone https://github.com/ewok/simple-service.git ${TEMP}
else
cd ${TEMP}
git fetch --all
git reset --hard origin/master
git pull
fi
cd ${TEMP}
# Variables for metapackage (indian code)
data=$(cat "pom.xml")
DESCRIPTION=$(grep -oPm1 "(?<=<description>)[^<]+" <<< "$data")
NAME=$(grep -oPm1 "(?<=<artifactId>)[^<]+" <<< "$data")
VERSION=$(grep -oPm1 "(?<=<version>)[^<]+" <<< "$data")
JAR_FILE="${TEMP}/target/${NAME}.jar"
# Building jar
mvn package
cd ${BASE_DIR}
# Making deb rpm
if [ ! -d "${PACKAGE_DIR}" ]; then
mkdir -p ${PACKAGE_DIR}/{etc/init.d,usr/share/${NAME}}
fi
# Service bin
cp -f "${JAR_FILE}" "${PACKAGE_DIR}/usr/share/${NAME}/${NAME}.jar"
# Init.d
cat <<EOF > ${PACKAGE_DIR}/etc/init.d/${NAME}
### BEGIN INIT INFO
# Provides: ${NAME}
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop ${NAME}
# Description: Start, stop and save ${NAME}
### END INIT INFO
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="${DESCRIPTION}"
SERVICE_NAME=${NAME}
PIDFILE=/var/run/${NAME}.pid
SCRIPTNAME=/etc/init.d/${NAME}
PATH_TO_JAR="/usr/share/${NAME}/${NAME}.jar"
EOF
cat <<'EOF' >> ${PACKAGE_DIR}/etc/init.d/${NAME}
do_start()
{
echo "Starting $SERVICE_NAME ..."
if [ ! -f $PIDFILE ]; then
nohup java -Dlogging.path=/var/log -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null &
echo $! > $PIDFILE
echo "$SERVICE_NAME started ..."
else
echo "$SERVICE_NAME is already running ..."
fi
}
do_stop()
{
if [ -f $PIDFILE ]; then
PID=$(cat $PIDFILE);
echo "$SERVICE_NAME stoping ..."
kill $PID;
echo "$SERVICE_NAME stopped ..."
rm $PIDFILE
else
echo "$SERVICE_NAME is not running ..."
fi
}
status()
{
if [ -f $PIDFILE ]; then
echo "$SERVICE_NAME running ..."
else
echo "$SERVICE_NAME is not running ..."
fi
}
case "$1" in
start)
do_start
;;
stop)
do_stop
;;
status)
status
;;
restart|force-reload)
do_stop
do_start
;;
*)
echo "Usage: $SERVICE_NAME {start|stop|status|restart}" >&2
exit 3
;;
esac
EOF
chmod +x ${PACKAGE_DIR}/etc/init.d/${NAME}
cat <<EOF > afterinstalldeb
#!/bin/bash
update-rc.d ${NAME} defaults || exit 0
service ${NAME} start
EOF
cat <<EOF > beforeremovedeb
#!/bin/bash
update-rc.d -f ${NAME} remove || exit 0
service ${NAME} stop
EOF
rm -f *.deb
rm -f *.rpm
fpm -n $NAME -v $VERSION -a all -C ${PACKAGE_DIR} \
--description "$DESCRIPTION" \
--before-remove beforeremovedeb \
--after-install afterinstalldeb \
-t "deb" -d "default-jre" \
-s dir etc usr
fpm -n $NAME -v $VERSION -a all -C ${PACKAGE_DIR} \
--description "$DESCRIPTION" \
-t "rpm" -d "java-1.7.0-openjdk" \
-s dir etc usr
for i in $(ls *.deb); do
cp -f $i ${NGINX_DIR}/package.deb
done
for i in $(ls *.rpm); do
cp -f $i ${NGINX_DIR}/package.rpm
done