Gentoo Archives: gentoo-commits

From: Austin English <wizardedit@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: dev-util/artifactory-bin/, dev-util/artifactory-bin/files/
Date: Tue, 01 Nov 2016 22:13:30
Message-Id: 1478038397.17134d9c4d4820234364e3f62467d612f96a616f.wizardedit@gentoo
1 commit: 17134d9c4d4820234364e3f62467d612f96a616f
2 Author: Austin English <wizardedit <AT> gentoo <DOT> org>
3 AuthorDate: Tue Nov 1 22:12:38 2016 +0000
4 Commit: Austin English <wizardedit <AT> gentoo <DOT> org>
5 CommitDate: Tue Nov 1 22:13:17 2016 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=17134d9c
7
8 dev-util/artifactory-bin: fix syntax error in initd
9
10 Package-Manager: portage-2.3.2
11
12 .../artifactory-bin-4.14.0-r1.ebuild | 97 ++++++++++++
13 dev-util/artifactory-bin/files/initd-r2 | 165 +++++++++++++++++++++
14 2 files changed, 262 insertions(+)
15
16 diff --git a/dev-util/artifactory-bin/artifactory-bin-4.14.0-r1.ebuild b/dev-util/artifactory-bin/artifactory-bin-4.14.0-r1.ebuild
17 new file mode 100644
18 index 00000000..9cea80c
19 --- /dev/null
20 +++ b/dev-util/artifactory-bin/artifactory-bin-4.14.0-r1.ebuild
21 @@ -0,0 +1,97 @@
22 +# Copyright 1999-2016 Gentoo Foundation
23 +# Distributed under the terms of the GNU General Public License v2
24 +# $Id$
25 +
26 +# Using a binary ebuild until a source ebuild is doable.
27 +# This was previously blocked by two major bugs upstream:
28 +# A lack of documented build instructions - https://www.jfrog.com/jira/browse/RTFACT-8960
29 +# A lack of source releases - https://www.jfrog.com/jira/browse/RTFACT-8961
30 +# Upstream now releases source and instructions (yay!), but most of artifactory's
31 +# dependencies are not in portage yet.
32 +
33 +EAPI=6
34 +
35 +inherit user
36 +
37 +MY_P="${P/-bin}"
38 +MY_PN="${PN/-bin}"
39 +MY_PV="${PV/-bin}"
40 +
41 +DESCRIPTION="The world's most advanced repository manager for maven"
42 +HOMEPAGE="http://www.jfrog.org/products.php"
43 +SRC_URI="https://bintray.com/artifact/download/jfrog/artifactory/jfrog-artifactory-oss-${MY_PV}.zip -> ${MY_P}.zip"
44 +
45 +LICENSE="AGPL-3+"
46 +SLOT="0"
47 +KEYWORDS="~x86 ~amd64"
48 +IUSE="ssl"
49 +
50 +RDEPEND=">=virtual/jre-1.8"
51 +DEPEND=">=virtual/jdk-1.8
52 + app-arch/unzip"
53 +
54 +S="${WORKDIR}/${MY_PN}-oss-${MY_PV}"
55 +
56 +pkg_setup() {
57 + enewgroup artifactory
58 + enewuser artifactory -1 /bin/sh -1 artifactory
59 +}
60 +
61 +src_prepare() {
62 + default
63 +
64 + if use ssl ; then
65 + cp "${FILESDIR}/artifactory.xml" tomcat/conf/Catalina/localhost/artifactory.xml || die
66 + cp "${FILESDIR}/server.xml" tomcat/conf/server.xml || die
67 + fi
68 +
69 + # Reverse https://www.jfrog.com/jira/browse/RTFACT-7123
70 + sed -i -e "s%artifactory.repo.global.disabled=true%artifactory.repo.global.disabled=false%g;" \
71 + etc/artifactory.system.properties || die
72 +
73 + # See FIXME in src_install(), this can probably go away,
74 + # but catalina.sh may need to be fixed for that:
75 + sed -i -e "s%/etc/opt/jfrog/artifactory/default%/etc/conf.d/${MY_PN}%g;" \
76 + misc/service/setenv.sh || die
77 +}
78 +
79 +src_install() {
80 + local ARTIFACTORY_HOME="/opt/artifactory"
81 + local TOMCAT_HOME="${ARTIFACTORY_HOME}/tomcat"
82 +
83 + insinto ${ARTIFACTORY_HOME}
84 + doins -r etc logs misc tomcat webapps
85 +
86 + dodir /etc/opt/jfrog
87 + dosym ${ARTIFACTORY_HOME}/etc /etc/opt/jfrog/artifactory
88 +
89 + dosym ${ARTIFACTORY_HOME}/logs /var/log/artifactory
90 +
91 + exeinto ${ARTIFACTORY_HOME}/bin
92 + doexe bin/*
93 +
94 + # FIXME: this is called by catalina.sh (it echoes the variables before starting
95 + # artifactory, as well as makes sure log dir, etc. exists). Those directories
96 + # could probably be moved to the ebuild and the script removed from catalina.sh
97 + # without consequence (and quieter starts). Would need to check if CATALINA_*
98 + # variables are actually used anywhere (from reading code don't appear to be
99 + # actually needed)
100 + exeinto ${TOMCAT_HOME}/bin
101 + doexe misc/service/setenv.sh
102 + doexe tomcat/bin/*
103 +
104 + keepdir ${ARTIFACTORY_HOME}/backup
105 + keepdir ${ARTIFACTORY_HOME}/data
106 + keepdir ${ARTIFACTORY_HOME}/run
107 + keepdir ${ARTIFACTORY_HOME}/work
108 + keepdir ${TOMCAT_HOME}/logs/catalina
109 + keepdir ${TOMCAT_HOME}/temp
110 + keepdir ${TOMCAT_HOME}/work
111 + keepdir /var/opt/jfrog/artifactory/run
112 +
113 + newconfd "${FILESDIR}/confd" ${MY_PN}
114 + newinitd "${FILESDIR}/initd-r2" ${MY_PN}
115 +
116 + fowners -R artifactory:artifactory ${ARTIFACTORY_HOME}
117 + fperms -R u+w ${TOMCAT_HOME}/work
118 +}
119
120 diff --git a/dev-util/artifactory-bin/files/initd-r2 b/dev-util/artifactory-bin/files/initd-r2
121 new file mode 100644
122 index 00000000..c9fbb05
123 --- /dev/null
124 +++ b/dev-util/artifactory-bin/files/initd-r2
125 @@ -0,0 +1,165 @@
126 +#!/sbin/openrc-run
127 +
128 +description="Manages the services needed to run Artifactory on a dedicated Tomcat"
129 +command="/opt/artifactory/tomcat/bin/catalina.sh"
130 +pidfile="/opt/artifactory/run/artifactory.pid"
131 +procname="artifactory"
132 +user=${ARTIFACTORY_USER:-artifactory}
133 +group=${group:-artifactory}
134 +
135 +# Artifactory can be very slow to start, and without locking,
136 +# restarting via runscript is very error prone
137 +CATALINA_LOCK_FILE="$(dirname $pidfile)/lock"
138 +
139 +CATALINA_MGMT_PORT=8015
140 +REQUIRED_JAVA_VERSION="1.8"
141 +START_TIMEOUT=300
142 +
143 +# Helper functions:
144 +is_mgmt_port_used() {
145 + mgmt_port_used=$(netstat -vatn | grep LISTEN | grep $CATALINA_MGMT_PORT | wc -l)
146 +}
147 +
148 +get_pid_info() {
149 + pidValue=""
150 + javaPs=""
151 + if [ -e "$pidfile" ]; then
152 + pidValue=$(cat $pidfile)
153 + if [ -n "$pidValue" ]; then
154 + javaPs="$(ps -p $pidValue | grep java)"
155 + fi
156 + fi
157 +}
158 +
159 +depend() {
160 + need net nginx
161 + use dns logger netmount
162 +}
163 +
164 +start_pre() {
165 + if [ -z "$ARTIFACTORY_HOME" ] || [ ! -d "$ARTIFACTORY_HOME" ]; then
166 + eerror "Artifactory home folder not defined or does not exists at $ARTIFACTORY_HOME"
167 + return 1
168 + fi
169 +
170 + if [ -z "$pidfile" ]; then
171 + eerror "Artifactory pid destination pidfile was not set!"
172 + return 1
173 + fi
174 +
175 + if [ -z "$TOMCAT_HOME" ] || [ ! -d "$TOMCAT_HOME" ]; then
176 + eerror "Tomcat Artifactory folder not defined or does not exists at $TOMCAT_HOME"
177 + return 1
178 + fi
179 +
180 + if [ -z "$ARTIFACTORY_USER" ]; then
181 + ARTIFACTORY_USER=$user
182 + fi
183 +
184 + current_open_file_limit=$(su -l $ARTIFACTORY_USER -c "ulimit -n")
185 + desired_open_file_limit=32000
186 + if [ "$current_open_file_limit" != "unlimited" ] && [ $current_open_file_limit -lt $desired_open_file_limit ]; then
187 + eerror "Maximum number of open files ($current_open_file_limit) is too small!"
188 + eerror "You should add:"
189 + eerror "artifactory soft nofile $desired_open_file_limit"
190 + eerror "artifactory hard nofile $desired_open_file_limit"
191 + eerror "to your /etc/security/limits.conf file."
192 + return 1
193 + fi
194 +
195 + current_max_process_limit=$(su -l $ARTIFACTORY_USER -c "ulimit -u")
196 + desired_max_process_limit=1024
197 + if [ "$current_max_process_limit" != "unlimited" ] && [ $current_max_process_limit -lt $desired_max_process_limit ]; then
198 + eerror "Number of processes $current_max_process_limit is too small!"
199 + eerror "You should add:"
200 + eerror "artifactory soft nproc $desired_max_process_limit"
201 + eerror "artifactory hard nproc $desired_max_process_limit"
202 + eerror "to your /etc/security/limits.conf file."
203 + return 1
204 + fi
205 +
206 + if [ -n "$JAVA_HOME" ] && [ -x "$JAVA_HOME/bin/java" ]; then
207 + einfo "Found java executable in $JAVA_HOME"
208 + _java="$JAVA_HOME/bin/java"
209 + elif command -v java > dev/null 2>&1 ; then
210 + _java=java
211 + else
212 + eerror "No Java Runtime Environment (jre) found! At least java-$REQUIRED_JAVA_VERSION is required."
213 + return 1
214 + fi
215 + if [ "$_java" ]; then
216 + java_version=$($_java -version 2>&1 | grep 'version' | cut -d ' ' -f3 | tr -d \")
217 + java_major=$(echo $java_version | cut -d . -f1-2)
218 + if [ "$java_major" != "$REQUIRED_JAVA_VERSION" ] ; then
219 + eerror "Java version $java_version is too old, java-$REQUIRED_JAVA_VERSION is required."
220 + return 1
221 + fi
222 + fi
223 +}
224 +
225 +# We have to pass start/stop through to catalina.sh, which doesn't understand restart (and restart can't be overridden in OpenRC):
226 +start() {
227 + get_pid_info
228 + is_mgmt_port_used
229 + if [ $mgmt_port_used -ne 0 ] || [ -n "$javaPs" ]; then
230 + eerror "$RC_SERVICE already started!"
231 + return 1
232 + else
233 + ebegin "Starting $RC_SERVICE"
234 + start-stop-daemon --exec $command --pidfile $pidfile --user $user:$group --wait $START_TIMEOUT start
235 + RETVAL=$?
236 + eend $RETVAL "start-stop-daemon failed to start $RC_SERVICE"
237 + fi
238 +
239 +
240 + is_mgmt_port_used
241 + seconds=1
242 + while [ $mgmt_port_used -eq 0 ] && [ $seconds -lt $START_TIMEOUT ]; do
243 + sleep 1
244 + ((seconds=seconds+1))
245 + is_mgmt_port_used
246 + done
247 + if [ $mgmt_port_used -eq 0 ]; then
248 + eerror "$RC_SERVICE did not start in $START_TIMEOUT seconds!"
249 + return 1
250 + elif [ $mgmt_port_used -eq 1 ]; then
251 + einfo "$RC_SERVICE started"
252 + [ $RETVAL=0 ] && touch $CATALINA_LOCK_FILE
253 + else
254 + eerror "Got unexpected result when checking port $CATALINA_MGMT_PORT"
255 + return 1
256 + fi
257 + return $RETVAL
258 +}
259 +
260 +stop() {
261 + ebegin "Stopping $RC_SERVICE"
262 + start-stop-daemon --stop --pidfile $pidfile --wait $START_TIMEOUT stop
263 + RETVAL=$?
264 + eend $RETVAL "Failed to stop $RC_SERVICE!"
265 +
266 + [ $RETVAL=0 ] && rm -f "$CATALINA_LOCK_FILE" "$pidfile"
267 + return $RETVAL
268 +}
269 +
270 +status() {
271 + is_mgmt_port_used
272 + if [ $mgmt_port_used -eq 0 ]; then
273 + if [ -e "$pidfile" ]; then
274 + eerror "$RC_SERVICE stopped but the pid file $pidfile still exists!"
275 + RETVAL=1
276 + else
277 + if [ -e "$CATALINA_LOCK_FILE" ]; then
278 + eerror "$RC_SERVICE is stopped but the lock file $CATALINA_LOCK_FILE still exists!"
279 + RETVAL=2
280 + else
281 + eerror "$RC_SERVICE is stopped"
282 + RETVAL=3
283 + fi
284 + fi
285 + else
286 + einfo "$RC_SERVICE is running"
287 + RETVAL=0
288 + fi
289 + return $RETVAL
290 +}