Created
January 9, 2019 18:31
-
-
Save shalomb/8b2451be6b24f8fe6a6b375a3628497b to your computer and use it in GitHub Desktop.
Improved artifactory systemd service manager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eu -o pipefail | |
ping_url='http://localhost:8081/artifactory/api/system/ping' | |
source /var/opt/jfrog/artifactory/etc/default | |
ARTIFACTORY_PIDFILE="$ARTIFACTORY_PID" | |
: ${START_TMO:=120} | |
function af-status { | |
ARTIFACTORY_PID=$(< $ARTIFACTORY_PIDFILE) | |
kill -0 "$ARTIFACTORY_PID" | |
env | grep -i -e java -e artifactory -e tomcat | |
pstree -als "$ARTIFACTORY_PID" | |
ready=0 | |
sleep=15 | |
until (( ready == 1 )); do | |
echo -n "Waiting for Artifactory Tomcat to accept connections .. " | |
status=$( curl -s -o /dev/null -w "%{http_code}" "$ping_url" ) | |
echo "pid: $ARTIFACTORY_PID, status: $status, sleep: $sleep" | |
if (( status != 503 )); then | |
ready=1 | |
else | |
sleep $(( sleep = sleep/2 + 1 )) | |
fi | |
done | |
echo | |
curl -fsSLi "$ping_url" | |
} | |
case "$1" in | |
restart|stop) | |
/opt/jfrog/artifactory/bin/artifactoryManage.sh stop || | |
pkill -f 'artifactory/tomcat' | |
;& | |
restart|start) | |
timeout -s15 -k$(( START_TMO * 2 )) "$START_TMO" \ | |
/opt/jfrog/artifactory/bin/artifactoryManage.sh "$@" | |
af-status || true | |
;; | |
status) | |
af-status | |
;; | |
logs) | |
cd "$ARTIFACTORY_HOME/logs" && tail -f $(find . -type f) | |
;; | |
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Setup Systemd script for Artifactory in Tomcat Servlet Engine | |
After=network.target | |
[Service] | |
Type=forking | |
GuessMainPID=yes | |
Restart=always | |
RestartSec=5 | |
PIDFile=/var/opt/jfrog/run/artifactory.pid | |
ExecStart=/usr/local/bin/artifactory-sm start | |
ExecStop=/usr/local/bin/artifactory-sm stop | |
[Install] | |
WantedBy=multi-user.target | |
Alias=artifactory.service |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A number of times now we've come across situations where the artifactory service starts (
systemctl start artifactory
succeeds) yet artifactory is unable to service requests (i.e. returningHTTP 503 - Service Unavailable
or similar) due toartifactory.config.latest.xml
).It turns out that the
/opt/jfrog/artifactory/bin/artifactoryManage.sh
script that comes part of the installation (debian package) does not perform enough checks to ensure artifactory is actually initialized.artifactory-sm
is a proof of concept script to wrap the/opt/jfrog/artifactory/bin/artifactoryManage.sh
and ensure theartifactory
tomcat application is fully bootstrapped, initialized and is able to serve HTTP requests before returning.This ensures the following
systemctl start artifactory.service
to fail fast.systemctl start artifactory.service
does not return unless the artifactory tomcat application is able to serve HTTP requests (as opposed to the default behaviour of startingtomcat
and returning early - with no guarantee that artifactory will start).