UNCLASSIFIED

You need to sign in or sign up before continuing.
Commit 07b5f6d0 authored by Al Fontaine's avatar Al Fontaine
Browse files

Merge branch 'development' into 'master'

Use registry1.dso.mil, remove serviceAccount example from values.yaml in helm...

See merge request !48
parents 85a7a747 bd70f7d8
Pipeline #469753 failed with stages
in 23 minutes and 45 seconds
ARG BASE_REGISTRY=registry1.dso.mil
ARG BASE_IMAGE=ironbank/redhat/ubi/ubi8
ARG BASE_TAG=8.4
ARG ARTIFACTORY_BASE_VERSION=7.21.7
FROM releases-docker.jfrog.io/jfrog/artifactory-oss:${ARTIFACTORY_BASE_VERSION} AS base
FROM ${BASE_REGISTRY}/${BASE_IMAGE}:${BASE_TAG}
USER root
# Set vars
ENV JF_ARTIFACTORY_USER=artifactory \
ARTIFACTORY_VERSION=${ARTIFACTORY_VERSION} \
ARTIFACTORY_BOOTSTRAP=/artifactory_bootstrap \
JF_PRODUCT_HOME=/opt/jfrog/artifactory \
JF_PRODUCT_DATA_INTERNAL=/var/opt/jfrog/artifactory \
RECOMMENDED_MAX_OPEN_FILES=32000 \
MIN_MAX_OPEN_FILES=10000 \
RECOMMENDED_MAX_OPEN_PROCESSES=1024 \
TOMCAT_HOME=/opt/jfrog/artifactory/app/artifactory/tomcat
COPY --from=base /opt/jfrog/artifactory/ /opt/jfrog/artifactory/
COPY --from=base /var/opt/jfrog/artifactory/ /var/opt/jfrog/artifactory/
COPY --from=base /opt/jfrog/artifactory/app/third-party /opt/jfrog/artifactory/app/third-party
COPY ./scripts/entrypoint-artifactory.sh /
COPY ./scripts/* /opt/jfrog/artifactory/app/bin/
COPY info/* /var/opt/jfrog/artifactory/etc/artifactory/info/
# Handle permissions and ownership in ${JF_PRODUCT_HOME}/app
# set artifactory home and data
# set docker as distribution for callhome
# Handle run with custom uid and gid with no volume mounted
# Handle bootstrap directory permissions
RUN groupadd -g 1030 ${JF_ARTIFACTORY_USER} && \
useradd -d "$JF_PRODUCT_HOME" -u 1030 -g 1030 -m -s /bin/bash ${JF_ARTIFACTORY_USER} && \
dnf upgrade -y --nodoc && \
dnf install -y procps-ng net-tools cronie hostname --setopt=tsflags=nodocs && \
dnf clean all && \
rm -rf /var/cache/dnf && \
chown -R ${JF_ARTIFACTORY_USER}:${JF_ARTIFACTORY_USER} ${JF_PRODUCT_HOME} && \
chmod 777 ${JF_PRODUCT_HOME}/app/run && \
chmod -R 755 ${JF_PRODUCT_HOME}/app/artifactory/tomcat && \
chmod -R 777 ${JF_PRODUCT_HOME}/app/artifactory/tomcat/webapps && \
chmod -R go+w ${JF_PRODUCT_HOME}/app ${JF_PRODUCT_HOME}/app/bin ${JF_PRODUCT_HOME}/app/artifactory/tomcat/conf && \
chmod +x ${JF_PRODUCT_HOME}/app/bin/* ${JF_PRODUCT_HOME}/app/artifactory/tomcat/bin/* && \
ln -s ${JF_PRODUCT_DATA_INTERNAL} ${JF_PRODUCT_HOME}/var && \
chown -R ${JF_ARTIFACTORY_USER}:${JF_ARTIFACTORY_USER} ${JF_PRODUCT_DATA_INTERNAL} /entrypoint-artifactory.sh && \
chmod +x /entrypoint-artifactory.sh && \
chown ${JF_ARTIFACTORY_USER}:${JF_ARTIFACTORY_USER} ${JF_PRODUCT_HOME}/app && \
chmod -R 777 ${JF_PRODUCT_DATA_INTERNAL} && \
mkdir -p ${ARTIFACTORY_BOOTSTRAP} && \
chmod -R 766 ${ARTIFACTORY_BOOTSTRAP} && \
chown -R ${JF_ARTIFACTORY_USER}:${JF_ARTIFACTORY_USER} ${ARTIFACTORY_BOOTSTRAP}
# Expose Router's port
EXPOSE 8081
# The user that will run the container and artifactory
USER ${JF_ARTIFACTORY_USER}
# Default mount for data directory
VOLUME ${JF_PRODUCT_DATA_INTERNAL}
# Change workdir to Artifactory Home
WORKDIR ${JF_PRODUCT_HOME}
HEALTHCHECK --interval=30s --timeout=5s --start-period=2m --retries=5 \
CMD curl -I -f http://localhost:8082/ui/ || exit 1
# Start the simple standalone mode of Artifactory
ENTRYPOINT ["/entrypoint-artifactory.sh"]
\ No newline at end of file
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
apiVersion: v1
# The repository name in registry1, excluding /ironbank/
name: "jfrog/artifactory/artifactory-oss"
# List of tags to push for the repository in registry1
# The most specific version should be the first tag and will be shown
# on ironbank.dsop.io
tags:
- "7.21.7"
- "latest"
# Build args passed to Dockerfile ARGs
args:
BASE_IMAGE: "redhat/ubi/ubi8"
BASE_TAG: "8.4"
ARTIFACTORY_BASE_VERSION: "7.21.7"
# Docker image labels
labels:
org.opencontainers.image.title: "artifactory-oss"
## Human-readable description of the software packaged in the image
org.opencontainers.image.description: "JFrog Artifactory OSS image based on the Red Hat Universal Base Image for DSOP."
## License(s) under which contained software is distributed
org.opencontainers.image.licenses: "https://jfrog.com/artifactory/eula/"
## URL to find more information on the image
org.opencontainers.image.url: "https://jfrog.com"
## Name of the distributing entity, organization or individual
org.opencontainers.image.vendor: "JFrog"
org.opencontainers.image.version: "7.21.7"
## Keywords to help with search (ex. "cicd,gitops,golang")
mil.dso.ironbank.image.keywords: "storage,devops,container,binary,docker,maven,gradle,ivy"
## This value can be "opensource" or "commercial"
mil.dso.ironbank.image.type: "opensource"
## Product the image belongs to for grouping multiple images
mil.dso.ironbank.product.name: "JFrog Artifactory OSS"
# List of resources to make available to the offline build context
resources:
- tag: releases-docker.jfrog.io/jfrog/artifactory-oss:7.21.7
url: docker://releases-docker.jfrog.io/jfrog/artifactory-oss@sha256:c640d194a61d155519067623d03e9094f7e062cc275b4d7e8ec70e3b8b7754c5
# List of project maintainers
maintainers:
- email: "danielmi@jfrog.com"
# # The name of the current container owner
name: "Daniel Miakotkin"
# # The gitlab username of the current container owner
username: "danielmi"
- email: "klepal_alexander@bah.com"
name: "Alexander Klepal"
username: "alexander.klepal"
cht_member: true
artifactory:
name: artifactory
# Note that by default we use appVersion from values.yaml to get image tag/version
image:
# Image is pending certification with Iron Bank
registry: registry1.dso.mil
repository: ironbank/jfrog/artifactory/artifactory-oss
tag: 7.21.7
global:
imagePullSecrets:
- regcred
installerInfo: '{"productId":"ironbank_helm_artifactory-oss/1.0.0","features":[{"featureId":"Partner/ACC-013116"}]}'
\ No newline at end of file
{
"productId": "ironbank_artifactory-oss/1.0.0",
"features": [
{
"featureId": "Partner/ACC-013116"
}
]
}
\ No newline at end of file
{
"assignees": [
"@matt.vasquez"
],
"baseBranches": [
"development"
],
"regexManagers": [
{
"fileMatch": [
"^Dockerfile$"
],
"matchStrings": [
"version=\"(?<currentValue>.*?)\""
],
"depNameTemplate": "jfrog/artifactory/artifactory-oss",
"datasourceTemplate": "docker"
},
{
"fileMatch": [
"^hardening_manifest.yaml$"
],
"matchStrings": [
"org\\.opencontainers\\.image\\.version:\\s+\"(?<currentValue>.+?)\""
],
"depNameTemplate": "jfrog/artifactory/artifactory-oss",
"datasourceTemplate": "docker"
},
{
"fileMatch": [
"^hardening_manifest.yaml$"
],
"matchStrings": [
"tags:\\s+-\\s+\"(?<currentValue>.+?)\""
],
"depNameTemplate": "jfrog/artifactory/artifactory-oss",
"datasourceTemplate": "docker"
}
]
}
\ No newline at end of file
#!/bin/bash
#
# Startup script for Artifactory in Tomcat Servlet Engine
#
ARTIFACTORY_NAME=artifactory
METADATA_NAME=metadata
REPLICATOR_NAME=replicator
ACCESS_NAME=access
ROUTER_NAME=router
FRONTEND_NAME=frontend
EVENT_NAME=event
# Map contains environment variable key from old version (<7.x) to key from 7.x version
# This info will be used to assign value from old key to new key
# Note : Allowed values in a environment key are upper case alphabet, number and underscore
ART_ENV_MAP="""
${REPLICATOR_NAME}.enabled=START_LOCAL_REPLICATOR
shared.node.primary=HA_IS_PRIMARY
shared.node.id=HA_NODE_ID
shared.node.ip=HA_HOST_IP
artifactory.node.membershipPort=HA_MEMBERSHIP_PORT
artifactory.node.haDataDir=HA_DATA_DIR
artifactory.node.haBackupDir=HA_BACKUP_DIR
artifactory.port=SERVER_XML_ARTIFACTORY_PORT
artifactory.tomcat.connector.maxThreads=SERVER_XML_ARTIFACTORY_MAX_THREADS
access.tomcat.connector.maxThreads=SERVER_XML_ACCESS_MAX_THREADS
artifactory.tomcat.connector.extraConfig=SERVER_XML_ARTIFACTORY_EXTRA_CONFIG
access.tomcat.connector.extraConfig=SERVER_XML_ACCESS_EXTRA_CONFIG
shared.tomcat.connector.extra=SERVER_XML_EXTRA_CONNECTOR
shared.extraJavaOpts=EXTRA_JAVA_OPTS
shared.extraJavaOpts=EXTRA_JAVA_OPTIONS
artifactory.ha.waitForMasterKey=HA_WAIT_FOR_MASTER_KEY
artifactory.extraConf=ARTIFACTORY_EXTRA_CONF
access.extraConf=ACCESS_EXTRA_CONF
replicator.extraConf=REPLICATOR_EXTRA_CONF
shared.database.type=DB_TYPE
shared.database.host=DB_HOST
shared.database.port=DB_PORT
shared.database.url=DB_URL
shared.database.user=DB_USER
shared.database.password=DB_PASSWORD
artifactory.database.maxOpenConnections=DB_POOL_MAX_ACTIVE
artifactory.database.maxIdleConnections=DB_POOL_MAX_IDLE
access.database.maxOpenConnections=DB_POOL_MAX_ACTIVE
access.database.maxIdleConnections=DB_POOL_MAX_IDLE
"""
createDirectory () {
[[ -d "$1" ]] || mkdir -p $1 || errorExit "Could not create dir $1"
}
errorArtHome() {
echo
echo -e "\033[31m** $1\033[0m"
echo
exit 1
}
checkArtHome() {
if [ -z "${JF_PRODUCT_HOME}/app" ] || [ ! -d "${JF_PRODUCT_HOME}/app" ]; then
errorArtHome "ERROR: Artifactory home folder not defined or does not exists at ${JF_PRODUCT_HOME}/app"
fi
}
checkTomcatHome() {
if [ -z "$TOMCAT_HOME" ] || [ ! -d "$TOMCAT_HOME" ]; then
errorArtHome "ERROR: Tomcat Artifactory folder not defined or does not exists at $TOMCAT_HOME"
fi
export CATALINA_HOME="$TOMCAT_HOME"
}
# Do the actual permission check and chown
checkOwner () {
local file_to_check=$1
# get current user id an group id
local user_id_to_check=$(id -u)
local group_id_to_check=$(id -g)
logger "Checking permissions on $file_to_check"
local stat=( $(stat -Lc "%u %g" ${file_to_check}) )
local user_id=${stat[0]}
local group_id=${stat[1]}
if [[ "${user_id}" != "${user_id_to_check}" ]] || [[ "${group_id}" != "${group_id_to_check}" ]] ; then
errorArtHome "${file_to_check} is not owned by ${user_to_check}"
else
logger "$file_to_check is already owned by $user_id_to_check:$group_id_to_check."
fi
}
createSymlink() {
local target=$1
local link=$2
[ ! -z "${target}" ] || errorArtHome "target is not provided to create a symlink"
[ ! -z "${link}" ] || errorArtHome "source is not provided to create a symlink"
if [[ -d "${link}" && ! -L "${link}" ]];
then
# Uncomment this to get debug logs
# if its a directory, create a copy and move its content back to symlink
# logger """The target symbolic link ${link} is a directory,
# performing the following operations to change this from directory to symlink,
# - move ${link} to ${link}.copy
# - create link ${link} to ${target}
# - copy content of ${link}.copy to ${link}"""
mv -f "${link}" "${link}.copy" || errorArtHome "Could not create ${link}.copy directory from ${link}"
ln -s "${target}" "${link}" || errorArtHome "Could not create link from ${link} to ${target}"
cp -fr "${link}.copy"/* "${link}" || errorArtHome "Could not copy content from ${link}.copy to ${link}"
rm -fr "${link}".copy;
elif [ ! -L "${link}" ];
then
ln -s "${target}" "${link}" || errorArtHome "Could not create link from ${link} to ${target}"
fi
}
findShutdownPort() {
SHUTDOWN_PORT=`netstat -vatn|grep LISTEN|grep $CATALINA_MGNT_PORT|wc -l`
}
isAlive() {
pidValue=""
javaPs=""
if [ -e "$JF_ARTIFACTORY_PID" ]; then
pidValue=`cat $JF_ARTIFACTORY_PID`
if [ -n "$pidValue" ]; then
javaPs="`ps -p $pidValue | grep java`"
fi
fi
}
testPermissions () {
# Create JF_PRODUCT_HOME/var directory - to handle zip installations
if [ ! -L "${JF_PRODUCT_HOME}/var" ]; then
createDirectory "${JF_PRODUCT_HOME}/var"
fi
testDirectoryPermissions "${JF_PRODUCT_HOME}/var"
}
# Set and configure DB type
setupHA () {
local isHaEnabled=
local transformedKey=
getSystemValue "shared.node.haEnabled" "NOT_SET"
isHaEnabled="${YAML_VALUE}"
if [[ "$isHaEnabled" != "NOT_SET" ]]; then
local haDataDirKey="artifactory.node.haDataDir"
getSystemValue "${haDataDirKey}" "NOT_SET"
local haDataDir="${YAML_VALUE}"
if [[ "${haDataDir}" != "NOT_SET" ]]; then
createDirectory "${haDataDir}"
testDirectoryPermissions "${haDataDir}"
fi
local haBakupDirKey="artifactory.node.haBackupDir"
getSystemValue "${haBakupDirKey}" "NOT_SET"
local haBackupDir="${YAML_VALUE}"
if [[ "${haBackupDir}" != "NOT_SET" ]]; then
createDirectory "${haBackupDir}"
testDirectoryPermissions "${haBackupDir}"
fi
# Install license file if exists in /tmp
if ls /tmp/art*.lic 1> /dev/null 2>&1; then
logger "Found /tmp/art*.lic. Using it..."
cp -v /tmp/art*.lic $ART_ETC/artifactory.lic
fi
fi
}
# Generate an artifactory.config.import.yml if parameters passed
# Only if artifactory.config.import.yml does not already exist!
# RETAINED for backward compatability only
prepareArtConfigYaml () {
local artifactory_config_import_yml=${ARTIFACTORY_DATA}/etc/artifactory.config.import.yml
if [ ! -f ${artifactory_config_import_yml} ]; then
if [ -n "$AUTO_GEN_REPOS" ] || [ -n "$ART_BASE_URL" ] || [ -n "$ART_LICENSE" ]; then
# Make sure license is provided (must be passed in Pro)
if [ -z "$ART_LICENSE" ]; then
errorExit "To use the feature of auto configuration, you must pass a valid Artifactory license as an ART_LICENSE environment variable!"
fi
logger "Generating ${artifactory_config_import_yml}"
[ -n "$ART_LICENSE" ] && LIC_STR="licenseKey: $ART_LICENSE"
[ -n "$ART_BASE_URL" ] && BASE_URL_STR="baseUrl: $ART_BASE_URL"
[ -n "$AUTO_GEN_REPOS" ] && GEN_REPOS_STR="repoTypes:"
cat <<EY1 > "$artifactory_config_import_yml"
version: 1
GeneralConfiguration:
${LIC_STR}
${BASE_URL_STR}
EY1
if [ -n "$GEN_REPOS_STR" ]; then
cat <<EY2 >> "$artifactory_config_import_yml"
OnboardingConfiguration:
${GEN_REPOS_STR}
EY2
for repo in $(echo ${AUTO_GEN_REPOS} | tr ',' ' '); do
cat <<EY3 >> "$artifactory_config_import_yml"
- ${repo}
EY3
done
fi
fi
fi
}
# Set and configure DB type
setDBType () {
logger "Checking DB_TYPE"
# TODO Will this be supported ?
# A decision has to be made on the design and flow for this
# if [ -f "${ART_ETC}/.secrets/.temp.db.properties" ]
# then
# SECRET_DB_PROPS_FILE="${ART_ETC}/.secrets/.temp.db.properties"
# logger "Detected secret db.properties file at ${SECRET_DB_PROPS_FILE}. Secret file will override default db.properties file as well as environment variables."
# DB_TYPE_FROM_SECRET=$(grep -E "(type).*" "$SECRET_DB_PROPS_FILE" | awk -F"=" '{ print $2 }')
# if [[ "$DB_TYPE_FROM_SECRET" =~ ^(postgresql|mysql|oracle|mssql|mariadb)$ ]]; then DB_TYPE=${DB_TYPE_FROM_SECRET} ; fi
# fi
# if [ ! -z "${DB_TYPE}" ] && [ "${DB_TYPE}" != derby ]; then
# logger "DB_TYPE is set to $DB_TYPE"
# DB_PROPS=${ART_ETC}/db.properties
# if [ ! -z "$SECRET_DB_PROPS_FILE" ]
# then
# DB_PROPS=${SECRET_DB_PROPS_FILE}
# logger "DB_PROPS set to: ${DB_PROPS}"
# fi
# fi
}
startReplicator() {
local action=${@:-"start"}
if runReplicator; then
chmod +x ${replicatorScript}
# TODO : Is this needed ?
JAVA_OPTIONS="$JAVA_OPTIONS -Dartifactory.start.local.replicator=true"
. ${replicatorScript} "${action}"
fi
}
stopReplicator() {
if runReplicator; then
chmod +x ${replicatorScript}
${replicatorScript} stop
fi
}
stop() {
# The default CATALINA_MGNT_PORT is 8015
# TODO[by Amith]: should this come from system yaml
CATALINA_MGNT_PORT=8015
echo "Using the default catalina management port ($CATALINA_MGNT_PORT) to test shutdown"
isAlive
findShutdownPort
if [ $SHUTDOWN_PORT -eq 0 ] && [ -z "$javaPs" ]; then
echo "Artifactory Tomcat already stopped"
RETVAL=0
else
echo "Stopping Artifactory Tomcat..."
if [ $SHUTDOWN_PORT -ne 0 ]; then
$TOMCAT_HOME/bin/shutdown.sh
RETVAL=$?
else
RETVAL=1
fi
hardKillTomcat
if [ $SHUTDOWN_PORT -eq 0 ] && [ -z "$javaPs" ]; then
echo "Artifactory Tomcat stopped"
else
echo "ERROR: Artifactory Tomcat did not stop"
RETVAL=1
fi
fi
[ $RETVAL=0 ] && rm -f "$JF_ARTIFACTORY_PID"
# This script is called when artifactory is started as docker container and when it is started in standalone mode
local confFile="${JF_PRODUCT_HOME}/var/etc/logrotate/logrotate.conf"
io_checkOwner "${confFile}" "$(id -un)" "$(id -gn)" "yes" && removeLogRotation "$JF_PRODUCT_HOME" "$(id -un)" || true
stopReplicator
for serviceScript in ${MANDATORY_JF_SERVICES_SCRIPT}; do
performActionOnScript "${serviceScript}" "stop"
done
}
addConfFiles(){
addExtraFiles "${ARTIFACTORY_NAME}.extraConf" "$ART_ETC" "/artifactory_extra_conf"
addExtraFiles "${REPLICATOR_NAME}.extraConf" "$REPLICATOR_ETC" "/replicator_extra_conf"
addExtraFiles "${ACCESS_NAME}.extraConf" "$ACCESS_ETC" "/access_extra_conf"
}
addLogRotation() {
local logRotateFolder="${JF_PRODUCT_HOME}/var/etc/logrotate"
if [ ! -d "$logRotateFolder" ]; then
mkdir -p "$logRotateFolder"
fi
local confFile="$logRotateFolder/logrotate.conf"
if [ ! -f "$confFile" ]; then
touch "$confFile"
fi
# This script is called when artifactory is started as docker container and when it is started in standalone mode
io_checkOwner "${confFile}" "$(id -un)" "$(id -gn)" "yes" || { return 0; }
configureLogRotation "artifactory" "${JF_PRODUCT_HOME}" "$(id -un)" "$(id -gn)" || true
}
startupActions () {
checkJavaVersion
checkULimits "${MIN_MAX_OPEN_FILES}" "${MIN_MAX_OPEN_PROCESSES}"
validateSystemYaml
validateDbconnection "${JF_PRODUCT_HOME}"
testPermissions
syncEtc
setupNodeDetails
setupHA
addConfFiles
addExtraJavaArgs
prepareArtConfigYaml
addLogRotation
addCertsToJavaKeystore
prepareTomcat
prioritizeCustomJoinKey
configureServerXml
exportEnv "shared"
exportEnv "${ARTIFACTORY_NAME}"
exportEnv "${ACCESS_NAME}"
setRouterToplogy
displayEnv
}
start() {
export JF_ARTIFACTORY_PID=${JF_PRODUCT_HOME}/app/run/${ARTIFACTORY_NAME}.pid
export CATALINA_PID="$JF_ARTIFACTORY_PID"
[ -x $TOMCAT_HOME/bin/catalina.sh ] || chmod +x $TOMCAT_HOME/bin/*.sh
#create ${JF_PRODUCT_HOME}/app/run
if [ -n "$JF_ARTIFACTORY_PID" ];
then
mkdir -p $(dirname "$JF_ARTIFACTORY_PID") || \
errorArtHome "Could not create dir for $JF_ARTIFACTORY_PID";
fi
if [ -z "$@" ];
then
startupActions
for serviceScript in ${MANDATORY_JF_SERVICES_SCRIPT}; do
performActionOnScript "${serviceScript}" "start"
done
startReplicator
#default to catalina.sh run
setCatalinaOpts
if $(isConsoleLogDisabled >/dev/null 2>&1); then
$TOMCAT_HOME/bin/catalina.sh run
else
$TOMCAT_HOME/bin/catalina.sh run > >(tee >(redirectServiceLogsToFile)) 2>&1
fi
else
if [ "$@" == "stop" ];
then
setCatalinaOpts
stop
else
startupActions
for serviceScript in ${MANDATORY_JF_SERVICES_SCRIPT}; do
performActionOnScript "${serviceScript}" "start"
done
startReplicator "start"
setCatalinaOpts
# Start tomcat
$TOMCAT_HOME/bin/catalina.sh "$@"
fi
fi
}
check() {
for serviceScript in ${MANDATORY_JF_SERVICES_SCRIPT}; do
performActionOnScript "${serviceScript}" "status"
done
startReplicator "status"
if [ -f $JF_ARTIFACTORY_PID ]; then
echo "Artifactory is running, on pid="`cat $JF_ARTIFACTORY_PID`
echo ""
exit 0
fi
echo "Checking arguments to Artifactory: "
echo "JF_PRODUCT_HOME = ${JF_PRODUCT_HOME}"
echo "TOMCAT_HOME = $TOMCAT_HOME"
echo "JF_ARTIFACTORY_PID = $JF_ARTIFACTORY_PID"
echo "JAVA_HOME = $JAVA_HOME"
echo "JAVA_OPTIONS = $JAVA_OPTIONS"
echo
exit 1
}
setCatalinaOpts() {
setupTomcatRedirection # This ensures catalina logs are redirected to the common log file
export CATALINA_OPTS="$JAVA_OPTIONS -Djruby.bytecode.version=1.8"
}
sourceScript(){
local fileName=$1
[ ! -z "${fileName}" ] || errorExit "Target file is not set"
[ -f "${fileName}" ] || errorExit "${fileName} file is not found"
source "${fileName}" || errorExit "Unable to source ${fileName}, please check if the $USER user has permissions to perform this action"
}
initHelpers(){
local systemYamlHelper="${ARTIFACTORY_BIN_FOLDER}"/systemYamlHelper.sh
local installerCommon="${ARTIFACTORY_BIN_FOLDER}"/installerCommon.sh
local artCommon="${ARTIFACTORY_BIN_FOLDER}"/artifactoryCommon.sh
export YQ_PATH="${ARTIFACTORY_BIN_FOLDER}/../third-party/yq"
sourceScript "${systemYamlHelper}"
sourceScript "${installerCommon}"
sourceScript "${artCommon}"
setupScriptLogsRedirection || true
# init at each service startup
export JF_SYSTEM_YAML="${JF_PRODUCT_HOME}/var/etc/system.yaml"
}
init() {
initHelpers
translateEnv "${ART_ENV_MAP}"
initJava
initNode
}
ARTIFACTORY_BIN_FOLDER="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
MIN_MAX_OPEN_FILES=32000
MIN_MAX_OPEN_PROCESSES=1024
replicatorScript=${ARTIFACTORY_BIN_FOLDER}/../replicator/bin/replicator.sh
metadataScript=${ARTIFACTORY_BIN_FOLDER}/../metadata/bin/metadata.sh
routerScript=${ARTIFACTORY_BIN_FOLDER}/../router/bin/router.sh
frontendScript=${ARTIFACTORY_BIN_FOLDER}/../frontend/bin/frontend.sh
eventScript=${ARTIFACTORY_BIN_FOLDER}/../event/bin/event.sh
# Any new mandatory service to be started or stopped can be added to this variable
MANDATORY_JF_SERVICES_SCRIPT="${routerScript} ${metadataScript} ${eventScript} ${frontendScript}"
export JF_PRODUCT_HOME="$(cd ${ARTIFACTORY_BIN_FOLDER}/../.. && pwd)"
export JF_ARTIFACTORY_PID="${JF_PRODUCT_HOME}/app/run/artifactory.pid"
artDefaultFile="${ARTIFACTORY_BIN_FOLDER}/artifactory.default"
. ${artDefaultFile} || errorArtHome "ERROR: $artDefaultFile does not exist or not executable"
PRODUCT_ETC=${JF_PRODUCT_HOME}/var/etc
ART_ETC=$PRODUCT_ETC/$ARTIFACTORY_NAME
ACCESS_ETC=$PRODUCT_ETC/$ACCESS_NAME
REPLICATOR_ETC=$PRODUCT_ETC/$REPLICATOR_NAME
init
if [ "x$1" = "xcheck" ]; then
checkJavaVersion
addExtraJavaArgs
check
fi
# Extra termination steps needed
terminate () {
echo "Caught termination signal"
for serviceScript in ${MANDATORY_JF_SERVICES_SCRIPT}; do
performActionOnScript "${serviceScript}" "stop"
done
stopReplicator
}
# Catch Ctrl+C and other termination signals to try graceful shutdown
trap terminate SIGINT SIGTERM SIGHUP
checkArtHome
checkTomcatHome
usage() {
cat << END_USAGE
./$0 - Script to manage ${ARTIFACTORY_NAME} services.
Usage: ./${0} <action>
action: start|stop|restart|status|check|run|help
Note : If no action is passed, the services will be run in foreground.
END_USAGE
}
# run application in the foreground if nothing is passed
if [[ $# == 0 ]]; then
start
exit 0
fi
case "$@" in
start|stop)
start "$@"
;;
restart)
start "stop"
start "start"
;;
status|check)
check
;;
help)
usage
;;
*)
usage
exit 1
esac
This diff is collapsed.
#!/bin/bash
#
# Init script for Artifactory service (currently systemd)
#
# chkconfig: 345 86 14
# description: Artifactory service
# processname: artifactory
# pidfile: /var/run/artifactory.pid
#
### BEGIN INIT INFO
# Provides: artifactory
# Required-Start: $remote_fs $syslog $network
# Required-Stop: $remote_fs $syslog $network
# Default-Start: 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start Artifactory on Tomcat
# Description: Manages the services needed to run Artifactory on a dedicated Tomcat
### END INIT INFO
#
# service names inline with service route path
ARTIFACTORY_NAME=artifactory
METADATA_NAME=metadata
REPLICATOR_NAME=replicator
ACCESS_NAME=access
ROUTER_NAME=router
FRONTEND_NAME=frontend
EVENT_NAME=event
# Map contains environment variable key from old version (<7.x) to key from 7.x version
# This info will be used to assign value from old key to new key
# Note : Allowed values in a environment key are upper case alphabet, number and underscore
ART_ENV_MAP="""
${REPLICATOR_NAME}.enabled=START_LOCAL_REPLICATOR
${ARTIFACTORY_NAME}.start.timeout=START_TMO
"""
errorArtHome() {
echo
echo -e "\033[31m** ERROR: $1\033[0m"
echo
exit 1
}
startReplicator() {
if runReplicator; then
chmod +x ${replicatorScript}
# TODO : Is this needed ?
JAVA_OPTIONS="$JAVA_OPTIONS -Dartifactory.start.local.replicator=true"
su -m -s "/bin/sh" ${JF_ARTIFACTORY_USER} -c "${replicatorScript} start"
fi
}
stopReplicator() {
if runReplicator; then
chmod +x ${replicatorScript}
su -m -s "/bin/sh" ${JF_ARTIFACTORY_USER} -c "${replicatorScript} stop"
fi
}
start() {
# Start Tomcat in normal mode
isAlive
findShutdownPort
if [ ${SHUTDOWN_PORT} -ne 0 ] || [ -n "$javaPs" ]; then
logger "Artifactory Tomcat already started"
else
logger "Starting Artifactory tomcat as user $JF_ARTIFACTORY_USER..."
rpmDebStartupActions
# Remove old tomcat.pid in case exists
rm -f ${CATALINA_PID}
local startupCmd="export JAVA_HOME='$JAVA_HOME'; \
source $JF_PRODUCT_HOME/app/bin/systemYamlHelper.sh; \
source $JF_PRODUCT_HOME/app/bin/installerCommon.sh; \
setupTomcatRedirection; \
/bin/bash $TOMCAT_HOME/bin/startup.sh"
if $(isConsoleLogDisabled >/dev/null 2>&1); then
su -s "/bin/bash" ${JF_ARTIFACTORY_USER} -c "${startupCmd}"
else
su -s "/bin/bash" ${JF_ARTIFACTORY_USER} -c "${startupCmd} > >(tee >(redirectServiceLogsToFile)) 2>&1"
fi
RETVAL=$?
if [ ${RETVAL} -ne 0 ]; then
errorArtHome "Artifactory Tomcat server did not start. Please check the logs"
fi
findShutdownPort
nbSeconds=1
getSystemValue "shared.script.serviceStartTimeout" "60"
START_TMO="${YAML_VALUE}"
while [ ${SHUTDOWN_PORT} -eq 0 ] && [ ${nbSeconds} -lt ${START_TMO} ]; do
sleep 1
let "nbSeconds = $nbSeconds + 1"
findShutdownPort
done
if [ ${SHUTDOWN_PORT} -eq 0 ]; then
# if artifactory does not come up within provided $START_TMO, stop tomcat
su -s "/bin/sh" ${JF_ARTIFACTORY_USER} -c "export CATALINA_PID='${CATALINA_PID}'; \
export JF_PRODUCT_HOME='${JF_PRODUCT_HOME}'; \
export JAVA_HOME='${JAVA_HOME}'; $TOMCAT_HOME/bin/shutdown.sh" >/dev/null 2>&1
errorArtHome "Artifactory Tomcat server did not start in $START_TMO seconds, tomcat will be stopped. This timeout can be modified by setting shared.script.serviceStartTimeout (default: 60) in ${JF_SYSTEM_YAML}. "
fi
logger "Artifactory Tomcat started in normal mode"
createArtSvcPid
for serviceScript in ${MANDATORY_JF_SERVICES_SCRIPT}; do
performActionOnScriptAsUser "${serviceScript}" "start"
done
startReplicator
fi
}
stop() {
isAlive
findShutdownPort
if [ ${SHUTDOWN_PORT} -eq 0 ] && [ -z "$javaPs" ]; then
logger "Artifactory Tomcat already stopped"
RETVAL=0
else
logger "Stopping Artifactory Tomcat..."
if [ ${SHUTDOWN_PORT} -ne 0 ]; then
su -s "/bin/sh" ${JF_ARTIFACTORY_USER} -c "export JAVA_HOME='$JAVA_HOME'; $TOMCAT_HOME/bin/shutdown.sh"
RETVAL=$?
else
RETVAL=1
fi
hardKillTomcat
if [ ${SHUTDOWN_PORT} -eq 0 ] && [ -z "${javaPs}" ]; then
logger "Artifactory Tomcat stopped"
else
logger "ERROR: Artifactory Tomcat did not stop"
RETVAL=1
fi
fi
for serviceScript in ${MANDATORY_JF_SERVICES_SCRIPT}; do
performActionOnScriptAsUser "${serviceScript}" "stop"
done
stopReplicator
[ $RETVAL=0 ] && rm -f ${CATALINA_LOCK_FILE} ${JF_ARTIFACTORY_PID} ${CATALINA_PID}
}
start_and_wait() {
local artLog=${JF_PRODUCT_HOME}/var/log/${ARTIFACTORY_NAME}/artifactory.log
start
if [ -e ${JF_ARTIFACTORY_PID} ]; then
PID=$(cat ${JF_ARTIFACTORY_PID})
while [ ! -e "${artLog}" ]; do
sleep 10
done
tail -f ${artLog} &
terminating() {
logger "Received stop"
stop
while [ -e ${JF_ARTIFACTORY_PID} ] || [ ps ${PID} >/dev/null 2>&1 ]; do
sleep 1
done
exit 0
}
trap terminating SIGINT SIGTERM
while :; do
sleep 5
done
fi
logger "Something went wrong ${PID} $?"
}
status() {
findShutdownPort
if [ ${SHUTDOWN_PORT} -eq 0 ]; then
if [ -e "$JF_ARTIFACTORY_PID" ]; then
logger "ERROR: Artifactory is stopped but the pid file $JF_ARTIFACTORY_PID still exist"
RETVAL=1
else
if [ -e "$CATALINA_LOCK_FILE" ]; then
logger "ERROR: Artifactory is stopped but the lock file $CATALINA_LOCK_FILE still exist"
RETVAL=2
else
logger "Artifactory Tomcat stopped"
RETVAL=3
fi
fi
else
logger "Artifactory Tomcat running"
RETVAL=0
fi
}
sourceScript(){
local fileName=$1
[ ! -z "${fileName}" ] || errorExit "Target file is not set"
[ -f "${fileName}" ] || errorExit "${fileName} file is not found"
source "${fileName}" || errorExit "Unable to source ${fileName}, please check if the $USER user has permissions to perform this action"
}
initHelpers(){
local systemYamlHelper="${ARTIFACTORY_BIN_FOLDER}"/systemYamlHelper.sh
local installerCommon="${ARTIFACTORY_BIN_FOLDER}"/installerCommon.sh
local artCommon="${ARTIFACTORY_BIN_FOLDER}"/artifactoryCommon.sh
export YQ_PATH="${ARTIFACTORY_BIN_FOLDER}/../third-party/yq"
sourceScript "${systemYamlHelper}"
sourceScript "${installerCommon}"
sourceScript "${artCommon}"
# init at each service startup
export JF_SYSTEM_YAML="${JF_PRODUCT_HOME}/var/etc/system.yaml"
setupScriptLogsRedirection || true
}
init() {
initHelpers
translateEnv "${ART_ENV_MAP}"
initJava
initNode
}
check() {
if [ -f ${JF_ARTIFACTORY_PID} ]; then
echo "Artifactory is running with pid="$(cat ${JF_ARTIFACTORY_PID})
echo ""
exit 0
fi
echo "Checking arguments to Artifactory: "
echo "JF_PRODUCT_HOME = ${JF_PRODUCT_HOME}"
echo "JF_ARTIFACTORY_USER = ${JF_ARTIFACTORY_USER}"
echo "TOMCAT_HOME = ${TOMCAT_HOME}"
echo "JF_ARTIFACTORY_PID = ${JF_ARTIFACTORY_PID}"
echo "JAVA_HOME = ${JAVA_HOME}"
echo "JAVA_OPTIONS = ${JAVA_OPTIONS}"
echo
checkJavaVersion
exit 1
}
###
ARTIFACTORY_BIN_FOLDER="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
MIN_MAX_OPEN_FILES=32000
MIN_MAX_OPEN_PROCESSES=1024
replicatorScript=${ARTIFACTORY_BIN_FOLDER}/../replicator/bin/replicator.sh
metadataScript=${ARTIFACTORY_BIN_FOLDER}/../metadata/bin/metadata.sh
routerScript=${ARTIFACTORY_BIN_FOLDER}/../router/bin/router.sh
frontendScript=${ARTIFACTORY_BIN_FOLDER}/../frontend/bin/frontend.sh
eventScript=${ARTIFACTORY_BIN_FOLDER}/../event/bin/event.sh
# Any new mandatory service to be started or stopped can be added to this variable
MANDATORY_JF_SERVICES_SCRIPT="${routerScript} ${metadataScript} ${eventScript} ${frontendScript}"
export JF_PRODUCT_HOME="$(cd ${ARTIFACTORY_BIN_FOLDER}/../.. && pwd)"
export JF_ARTIFACTORY_PID="/var/run/artifactory.pid"
artDefaultFile="${ARTIFACTORY_BIN_FOLDER}/artifactory.default"
. ${artDefaultFile} || errorArtHome "ERROR: $artDefaultFile does not exist or not executable"
# Basic variables used
export CATALINA_PID_FOLDER=${JF_PRODUCT_HOME}/var/work/${ARTIFACTORY_NAME}/tomcat
export CATALINA_PID=${CATALINA_PID_FOLDER}/tomcat.pid
CATALINA_LOCK_FILE=${CATALINA_PID_FOLDER}/lock
CATALINA_MGNT_PORT=${CATALINA_MGNT_PORT:-8015}
init
checkArtUser
checkArtHome
checkArData
checkTomcatHome
RETVAL=0
case "$1" in
start)
checkJavaVersion
start
;;
wait)
checkJavaVersion
start_and_wait
;;
stop)
stop
;;
restart)
stop
start
;;
redebug)
stop
;;
status)
status
;;
check)
checkJavaVersion
addExtraJavaArgs
check
;;
*)
echo "Usage: $0 {start|stop|restart|redebug|status|check}"
exit 1
;;
esac
exit ${RETVAL}
\ No newline at end of file
#!/bin/bash
if [ -x /etc/systemd/system/artifactory.service ]; then
# Delegate to systemd service
systemctl "$@" artifactory.service
elif [ -x /etc/init.d/artifactory ]; then
# Delegate to init.d service
/etc/init.d/artifactory "$@"
else
# call artifactory.sh
artBinDir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
${artBinDir}/artifactory.sh "$@"
\ No newline at end of file
#!/bin/bash
#
# An entrypoint script for Artifactory to allow custom setup before server starts
#
: ${ARTIFACTORY_NAME:=artifactory}
: ${JF_PRODUCT_HOME:=/opt/jfrog/artifactory}
: ${ARTIFACTORY_BOOTSTRAP:=/artifactory_bootstrap}
: ${BOOTSTRAP:=/bootstrap}
JF_ARTIFACTORY_PID=${JF_PRODUCT_HOME}/app/run/${ARTIFACTORY_NAME}.pid
. ${JF_PRODUCT_HOME}/app/bin/installerCommon.sh
ARTIFACTORY_BIN_FOLDER=${JF_PRODUCT_HOME}/app/bin
sourceScript(){
local fileName=$1
[ ! -z "${fileName}" ] || errorExit "Target file is not set"
[ -f "${fileName}" ] || errorExit "${fileName} file is not found"
source "${fileName}" || errorExit "Unable to source ${fileName}, please check if the $USER user has permissions to perform this action"
}
initHelpers(){
local systemYamlHelper="${ARTIFACTORY_BIN_FOLDER}"/systemYamlHelper.sh
local installerCommon="${ARTIFACTORY_BIN_FOLDER}"/installerCommon.sh
local artCommon="${ARTIFACTORY_BIN_FOLDER}"/artifactoryCommon.sh
export YQ_PATH="${ARTIFACTORY_BIN_FOLDER}/../third-party/yq"
sourceScript "${systemYamlHelper}"
sourceScript "${installerCommon}"
sourceScript "${artCommon}"
export JF_SYSTEM_YAML="${JF_PRODUCT_HOME}/var/etc/system.yaml"
}
# Print on container startup information about Dockerfile location
printDockerFileLocation() {
logger "Dockerfile for this image can found inside the container."
logger "To view the Dockerfile: 'cat /docker/artifactory-oss/Dockerfile.artifactory'."
}
copyArtifactoryBootstrapFiles () {
if [[ -d "${ARTIFACTORY_BOOTSTRAP}" ]]; then
logger "Copying Artifactory bootstrap files"
copyFilesNoOverwrite "${ARTIFACTORY_BOOTSTRAP}" "${JF_PRODUCT_HOME}/var/etc/${ARTIFACTORY_NAME}"
fi
}
copyBootstrapFiles () {
if [[ -d "${BOOTSTRAP}" ]]; then
logger "Copying bootstrap files"
copyFilesNoOverwrite "${BOOTSTRAP}" "${JF_PRODUCT_HOME}/var/etc"
fi
}
terminate () {
echo -e "\nTerminating Artifactory"
${JF_PRODUCT_HOME}/app/bin/artifactory.sh stop
}
backupFile() {
local sourceFile=$1
local destinationFile=$2
if [ -f "${sourceFile}" ]; then
yes | \cp -f "${sourceFile}" "${destinationFile}" || warn "Could not copy [${sourceFile}] to [${destinationFile}]"
chown -R "${JF_USER}":"${JF_USER}" "${destinationFile}" || warn "Setting ownership of [${destinationFile}] to [${JF_USER}:${JF_USER}] failed"
fi
}
#Triggering migration
dockerMigration() {
if [[ -z "$ENABLE_MIGRATION" ]]; then
return
fi
if [[ $ENABLE_MIGRATION =~ (y|Y) ]]; then
if [ -f "${JF_PRODUCT_HOME}/app/bin/migrate.sh" ]; then
logger "Triggering migration script. This will migrate if needed and may take some time."
logger "Migration logs will be available at [${JF_PRODUCT_HOME}/app/bin/migration.log]. The file will be archived at [${JF_PRODUCT_HOME}/var/log]"
export JF_ROOT_DATA_DIR="/var/opt/jfrog/artifactory"
export JF_USER="${ARTIFACTORY_NAME}"
bash ${JF_PRODUCT_HOME}/app/bin/migrate.sh >/dev/null || errorExit "Aborting configuration since migration has failed"
else
errorExit "Skipping migration because ${JF_PRODUCT_HOME}/app/bin/migrate.sh is missing"
fi
backupFile "${JF_PRODUCT_HOME}/app/bin/migration.log" "${JF_PRODUCT_HOME}/var/log/migration.log"
fi
}
# Set libaio path
setLibaioPath() {
local libaioPath=${JF_PRODUCT_HOME}/app/artifactory/libaio
getSystemValue "$SYS_KEY_SHARED_DATABASE_TYPE" "NOT_SET" "false" "$JF_SYSTEM_YAML"
DATABASE_TYPE="$YAML_VALUE"
if [[ "${DATABASE_TYPE}" == "${SYS_KEY_SHARED_DATABASE_TYPE_VALUE_ORACLE}" ]]; then
getYamlValue "shared.env.LD_LIBRARY_PATH" "$JF_SYSTEM_YAML" "false"
local yamlLdLibraryPath="$YAML_VALUE"
if [[ -z "${yamlLdLibraryPath}" ]]; then
setSystemValue "shared.env.LD_LIBRARY_PATH" "${libaioPath}" "$JF_SYSTEM_YAML"
else
[[ "${yamlLdLibraryPath}" != *"${libaioPath}"* ]] && setSystemValue "shared.env.LD_LIBRARY_PATH" "${libaioPath}:${yamlLdLibraryPath}" "$JF_SYSTEM_YAML"
fi
fi
}
# Catch Ctrl+C and other termination signals to try graceful shutdown
trap terminate SIGINT SIGTERM SIGHUP
logger "Preparing to run Artifactory in Docker"
logger "Running as $(id)"
printDockerFileLocation
initHelpers
commonStartupActions "docker" 2>/dev/null
dockerMigration
setLibaioPath
# Wait for DB
# On slow systems, when working with docker-compose, the DB container might be up,
# but not ready to accept connections when Artifactory is already trying to access it.
waitForDB
[ $? -eq 0 ] || errorExit "Database failed to start in the given time"
copyArtifactoryBootstrapFiles
copyBootstrapFiles
# Run Artifactory as JF_ARTIFACTORY_USER user
exec ${JF_PRODUCT_HOME}/app/bin/artifactory.sh &
art_pid=$!
if [ -n "$JF_ARTIFACTORY_PID" ];
then
mkdir -p $(dirname "$JF_ARTIFACTORY_PID") || \
errorExit "Could not create dir for $JF_ARTIFACTORY_PID";
fi
echo "${art_pid}" > ${JF_ARTIFACTORY_PID}
wait ${art_pid}
\ No newline at end of file
#!/bin/bash
SERVICE_TYPE=""
errorArtHome() {
echo
echo -e "\033[31m** ERROR: $1\033[0m"
echo
exit 1
}
checkRoot() {
curUser=
if [ -x "/usr/xpg4/bin/id" ]
then
curUser=$(/usr/xpg4/bin/id -nu)
else
curUser=$(id -nu)
fi
if [ "$curUser" != "root" ]
then
errorArtHome "Only root user can install artifactory as a service"
fi
if [ "$0" = "." ] || [ "$0" = "source" ]; then
errorArtHome "Cannot execute script with source $0"
fi
}
sourceScript(){
local fileName=$1
[ ! -z "${fileName}" ] || errorExit "Target file is not set"
[ -f "${fileName}" ] || errorExit "${fileName} file is not found"
source "${fileName}" || errorExit "Unable to source ${fileName}, please check if the $USER user has permissions to perform this action"
}
initHelpers(){
local systemYamlHelper="${ARTIFACTORY_BIN_FOLDER}"/systemYamlHelper.sh
local installerCommon="${ARTIFACTORY_BIN_FOLDER}"/installerCommon.sh
local artCommon="${ARTIFACTORY_BIN_FOLDER}"/artifactoryCommon.sh
export YQ_PATH="${ARTIFACTORY_BIN_FOLDER}/../third-party/yq"
sourceScript "${systemYamlHelper}"
sourceScript "${installerCommon}"
sourceScript "${artCommon}"
# init at each service startup
export JF_SYSTEM_YAML="${JF_PRODUCT_HOME}/var/etc/system.yaml"
}
createArtUser() {
echo -n "Creating user ${JF_ARTIFACTORY_USER}..."
artifactoryUsername=$(getent passwd ${JF_ARTIFACTORY_USER} | awk -F: '{print $1}')
if [ "$artifactoryUsername" = "${JF_ARTIFACTORY_USER}" ]; then
echo -n "already exists..."
else
echo -n "creating..."
useradd -M -s /usr/sbin/nologin ${JF_ARTIFACTORY_USER}
if [ ! $? ]; then
errorArtHome "Could not create user ${JF_ARTIFACTORY_USER}"
fi
fi
echo " DONE"
}
saveUserGroupInfo(){
setSystemValueNoOverride "shared.user" "${JF_ARTIFACTORY_USER}" "${JF_SYSTEM_YAML}" 2>/dev/null || true
setSystemValueNoOverride "shared.group" "${JF_ARTIFACTORY_GROUP}" "${JF_SYSTEM_YAML}" 2>/dev/null || true
}
createArtGroup() {
[ "${JF_ARTIFACTORY_GROUP}" == "" ] && return 0;
echo -n "Creating Group ${JF_ARTIFACTORY_GROUP}..."
artifactoryGroupname=$(getent group ${JF_ARTIFACTORY_GROUP} | awk -F: '{print $1}')
if [ "$artifactoryGroupname" = "${JF_ARTIFACTORY_GROUP}" ]; then
echo -n "already exists..."
else
echo -n "creating..."
groupadd ${JF_ARTIFACTORY_GROUP}
if [ ! $? ]; then
errorArtHome "Could not create Group ${JF_ARTIFACTORY_GROUP}"
fi
fi
echo " DONE"
}
createArtDefault() {
echo -n "Modifying environment file $artDefaultFile..."
sed --in-place -e "
s,.*export JF_PRODUCT_HOME=.*,export JF_PRODUCT_HOME=${JF_PRODUCT_HOME},g;
s,.*export JF_ARTIFACTORY_USER=.*,export JF_ARTIFACTORY_USER=${JF_ARTIFACTORY_USER},g;
s,export TOMCAT_HOME=.*,export TOMCAT_HOME=${TOMCAT_HOME},g;" ${artDefaultFile} || \
errorArtHome "Could not change values in $artDefaultFile"
echo -e " DONE"
echo -e "\033[33m** INFO: Please create/edit system.yaml file in $productEtcDir to set the correct environment\033[0m"
echo -e "\033[33m Templates with information can be found in the same directory\033[0m"
}
createArtRun() {
# Since tomcat 6.0.24 the PID file cannot be created before running catalina.sh. Using /var/opt/jfrog/artifactory/run folder.
if [ ! -d "$artRunDir" ]; then
mkdir -p "$artRunDir" || errorArtHome "Could not create $artRunDir"
fi
}
checkServiceStatus() {
# Shutting down the artifactory service if running
if [ -e "$artInitdFile" ]; then
SERVICE_STATUS="$(${artInitdFile} status)"
if [[ ! "$SERVICE_STATUS" =~ .*[sS]topped.* ]]; then
echo "Stopping the artifactory service..."
${artInitdFile} stop || exit $?
fi
fi
if [ -e "$artSystemdFile" ]; then
SERVICE_STATUS="$(systemctl status artifactory.service)"
if [[ ! "$SERVICE_STATUS" =~ .*[sS]topped.* ]]; then
echo "Stopping the artifactory service..."
systemctl stop artifactory.service || exit $?
fi
fi
}
installInitdService() {
if [ -e ${artSystemdFile} ]; then
rm -f ${artSystemdFile}
fi
if [ -e "$artInitdFile" ]; then
cp -f ${artInitdFile} ${serviceFiles}/${serviceInitName}.disabled
fi
cp -f ${serviceFiles}/artifactory ${artInitdFile}
chmod a+x ${artInitdFile}
# Change default location if needed
sed --in-place -e "
/processname:/ s%artifactory%$serviceInitName%g;
/Provides:/ s%artifactory%$serviceInitName%g;
s%${envPlaceHolder}%${artDefaultFile}%g;
" ${artInitdFile} || errorArtHome "Could not change values in $artInitdFile"
# Try update-rc.d for debian/ubuntu else use chkconfig
if [ -x /usr/sbin/update-rc.d ]; then
echo
echo -n "Initializing artifactory service with update-rc.d..."
update-rc.d ${serviceInitName} defaults && \
chkconfigOK=true
elif [ -x /usr/sbin/chkconfig ] || [ -x /sbin/chkconfig ]; then
echo
echo -n "Initializing $serviceInitName service with chkconfig..."
chkconfig --add ${serviceInitName} && \
chkconfig ${serviceInitName} on && \
chkconfig --list ${serviceInitName} && \
chkconfigOK=true
else
ln -s ${artInitdFile} /etc/rc3.d/S99${serviceInitName} && \
chkconfigOK=true
fi
[ ${chkconfigOK} ] || errorArtHome "Could not install artifactory service"
echo -e " DONE"
SERVICE_TYPE="init.d"
}
installSystemdService() {
if [ -e ${artInitdFile} ]; then
mv ${artInitdFile} ${artInitdFile}.disabled
fi
serviceFiles=${ARTIFACTORY_BIN_FOLDER}/../misc/service
if [ -e "${artSystemdFile}" ]; then
mv ${artSystemdFile} ${serviceFiles}/${serviceSystemdName}.disabled
fi
cp -f ${serviceFiles}/artifactory.service ${artSystemdFile}
chmod a+x ${artSystemdFile}
# Edit artifactory.service for artifactoryManage.sh script location
sed -i "s|ExecStart=\/opt\/jfrog\/artifactory\/app\/bin\/artifactoryManage.sh start|ExecStart=${ARTIFACTORY_BIN_FOLDER}\/artifactoryManage.sh start|g; \
s|ExecStop=\/opt\/jfrog\/artifactory\/app\/bin\/artifactoryManage.sh stop|ExecStop=${ARTIFACTORY_BIN_FOLDER}\/artifactoryManage.sh stop|g;" ${artSystemdFile}
# Use the systemctl command to enable the service
echo -n "Initializing $serviceSystemdName service with systemctl..."
systemctl daemon-reload &>/dev/null
systemctl enable artifactory &>/dev/null
systemctl list-unit-files --type=service | grep artifactory.service &>/dev/null || errorArtHome "Could not install artifactory service"
echo -e " DONE"
SERVICE_TYPE="systemd"
}
installService() {
checkServiceStatus
# Distribution-specific logic
systemctl -h > /dev/null 2>&1
if [[ $? -eq 0 ]]; then
# Installing service from type systemd
installSystemdService
else
# Installing service from type init.d
installInitdService
fi
}
copyTomcatEnv() {
cp ${serviceFiles}/setenv.sh ${TOMCAT_HOME}/bin/setenv.sh && \
chmod a+x ${TOMCAT_HOME}/bin/* || errorArtHome "Could not set the $TOMCAT_HOME/bin/setenv.sh"
}
setPermissions() {
echo
echo "Setting file permissions..."
chown -RL ${JF_ARTIFACTORY_USER}:${JF_ARTIFACTORY_GROUP} ${JF_PRODUCT_HOME}/app || errorArtHome "Could not set permissions"
checkAndSetOwnerOnDir "${JF_PRODUCT_HOME}/var" "${JF_ARTIFACTORY_USER}" "${JF_ARTIFACTORY_GROUP}"
}
showSummary() {
echo
echo -e "\033[33m************ SUCCESS ****************\033[0m"
echo -e "\033[33mInstallation of Artifactory completed\033[0m"
echo
if [ ${SERVICE_TYPE} == "init.d" ]; then
echo "Start Artifactory with:"
echo "> service artifactory start (or $artInitdFile start)"
echo
echo "Check Artifactory status with:"
echo "> service artifactory status (or $artInitdFile status)"
fi
if [ ${SERVICE_TYPE} == "systemd" ]; then
echo "Start Artifactory with:"
echo "> systemctl start artifactory.service"
echo
echo "Check Artifactory status with:"
echo "> systemctl status artifactory.service"
fi
echo
echo "Logs can be found under ${JF_PRODUCT_HOME}/var/log"
echo "System configuration templates can be found under ${JF_PRODUCT_HOME}/var/etc"
echo "Copy any configuration you want to modify from the template to ${JF_PRODUCT_HOME}/var/etc/system.yaml"
echo
}
##
checkRoot
ARTIFACTORY_BIN_FOLDER="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
artExtractDir="$(cd "$(dirname "$ARTIFACTORY_BIN_FOLDER")" && pwd)"
serviceFiles=${ARTIFACTORY_BIN_FOLDER}/../misc/service
envPlaceHolder=__ARTIFACTORY_ENV_FILE__
mkdir -p ${artExtractDir}/../var || errorArtHome "Could not create dir ${artExtractDir}/../var"
[ -n "$JF_PRODUCT_HOME" ] || JF_PRODUCT_HOME="$(cd "$(dirname "$ARTIFACTORY_BIN_FOLDER")"/.. && pwd)"
[ -n "$productEtcDir" ] || productEtcDir="${JF_PRODUCT_HOME}/var/etc"
export JF_PRODUCT_HOME
export CATALINA_PID_FOLDER=${JF_PRODUCT_HOME}/var/work/artifactory/tomcat
export CATALINA_PID=${CATALINA_PID_FOLDER}/tomcat.pid
TOMCAT_HOME="${JF_PRODUCT_HOME}/app/artifactory/tomcat"
artLogDir="${JF_PRODUCT_HOME}/var/log/artifactory"
artRunDir="${JF_PRODUCT_HOME}/app/run"
[ -n "$artInitdFile" ] || artInitdFile="/etc/init.d/artifactory"
if [ -z "$artSystemdFile" ]; then
SUSE=$(cat /etc/issue | grep -io suse)
NOSUSE=$(echo $SUSE | tr "[:upper:]" "[:lower:]")
UNAME=$(uname | tr "[:upper:]" "[:lower:]")
if [ "$UNAME" == "linux" ] && [ "$NOSUSE" != "suse" ]; then
artSystemdFile="/lib/systemd/system/artifactory.service"
else
artSystemdFile="/usr/lib/systemd/system/artifactory.service"
fi
fi
serviceInitName=$(basename ${artInitdFile})
serviceSystemdName=$(basename ${artSystemdFile})
artDefaultFile="${ARTIFACTORY_BIN_FOLDER}/artifactory.default"
initHelpers
syncEtc
# This will set JF_ARTIFACTORY_USER and JF_ARTIFACTORY_GROUP (default artifactory:artifactory)
setUserGroup "$1" "$2"
echo
echo "Installing artifactory as a Unix service that will run as user ${JF_ARTIFACTORY_USER}${JF_ARTIFACTORY_GROUP:+ and group $JF_ARTIFACTORY_GROUP}"
echo "Installing artifactory with home ${JF_PRODUCT_HOME}/app"
createArtUser
createArtGroup
createArtDefault
createArtRun
installService
copyTomcatEnv
prepareTomcat
setPermissions
saveUserGroupInfo
showSummary
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
migration:
product: ARTIFACTORY
oldDataDir: /var/opt/jfrog/artifactory
propertyFiles:
files:
dbProperty
haNodeProperty
accessDbProperty
dbProperty:
# Note $JF_ROOT_DATA_DIR will be prepended to the filePath value
filePath: etc/artifactory/old
fileName: db.properties
map:
# map should be in format example: systemYamlPath=property
shared.database.type=type
shared.database.driver=driver
shared.database.url=url
shared.database.username=username
shared.database.password=password
artifactory.database.poolType=pool.type
artifactory.database.maxOpenConnections=pool.max.active
artifactory.database.maxIdleConnections=pool.max.idle
artifactory.database.minIdleConnections=minIdle
artifactory.database.lockingdbUsername=lockingdb.username
artifactory.database.lockingdbPassword=lockingdb.password
artifactory.database.lockingdbType=lockingdb.type
artifactory.database.lockingdbUrl=lockingdb.url
artifactory.database.lockingdbDriver=lockingdb.driver
accessDbProperty:
# Note $JF_ROOT_DATA_DIR will be prepended to the filePath value
filePath: etc/access/old
fileName: db.properties
map:
# map should be in format example: systemYamlPath=property
access.database.poolType=pool.type
access.database.maxOpenConnections=pool.max.active
access.database.maxIdleConnections=pool.max.idle
access.database.minIdleConnections=minIdle
haNodeProperty:
# Note $JF_ROOT_DATA_DIR will be prepended to the filePath value
filePath: etc/artifactory/old
fileName: ha-node.properties
map:
# map should be in format example: systemYamlPath=property
shared.node.id=node.id
shared.node.primary=primary
artifactory.node.contextUrl=context.url
artifactory.node.membershipPort=membership.port
artifactory.node.haDataDir=artifactory.ha.data.dir
artifactory.node.haBackupDir=artifactory.ha.backup.dir
artifactory.node.crossZoneOrder=cross.zone.order
artifactory.node.clusterHome=cluster.home
artifactory.node.hazelcastInterface=hazelcast.interface
moveDirectories:
map:
# Note : $JF_ROOT_DATA_DIR will be prepended to the sourceDirectoryPath value only if relative path and $JF_ROOT_DATA_DIR will be prepended to the targetDirectoryPath value
# map should be in format example: targetDirectoryPath=sourceDirectoryPath
backup/access=access/backup
data/access=access/data
etc/access=access/etc
work/access=access/tmp
log/archived/access=access/logs
log/archived/artifactory=logs
etc/replicator=replicator/etc
backup/replicator=replicator/backup
data/replicator=replicator/data
log/archived/replicator=replicator/logs
linkFiles:
map:
# Note : $oldDataDir will be prepended to the sourceDirectoryPath value and $JF_ROOT_DATA_DIR will be prepended to the targetDirectoryPath value
# map should be in format example: targetDirectoryPath=sourceDirectoryPath
backup/artifactory=backup
data/artifactory=data
etc/artifactory=etc
yaml:
files:
replicatorYaml
replicatorYaml:
# Note $JF_ROOT_DATA_DIR will be prepended to the filePath value
filePath: etc/replicator/old
fileName: replicator.yaml
# map should be in format example: systemYamlPath=key in config file
map:
replicator.externalUrl=externalUrl
replicator.internalUrl=internalUrl
replicator.port=listenPort
replicator.logging.application.level=logLevel
replicator.tls.skipVerifyCertificate=skipVerifyCertificate
replicator.profiling.port=profilingListenPort
replicator.profiling.allowedHost=profilingListenHost
replicator.txDir.cleanUpAgeSecs=txDirCleanUpAgeInSeconds
replicator.txDir.cleanUpIntervalSecs=txDirCleanUpIntervalInSeconds
replicator.profiling.enabled=profilingDisabled
cleanUpOldDataDir:
# Note $JF_ROOT_DATA_DIR will be prepended to the map entry
map:
access
replicator
metadata
logs
\ No newline at end of file
This diff is collapsed.
#!/bin/bash
error() {
echo -e "\n\033[31m** ERROR: $1\033[0m\n" && exit 1
}
checkRoot() {
curUser=
if [ -x "/usr/xpg4/bin/id" ]
then
curUser=$(/usr/xpg4/bin/id -nu)
else
curUser=$(id -nu)
fi
if [ "$curUser" != "root" ]
then
error "Only root user can install artifactory as a service"
fi
if [ "$0" = "." ] || [ "$0" = "source" ]; then
error "Cannot execute script with source $0"
fi
}
shutdownService() {
if [ -f ${artServiceFile} ]; then
SERVICE_STATUS="$(${artServiceFile} status)"
if [[ ! "$SERVICE_STATUS" =~ .*[sS]topped.* ]]; then
echo
echo -n "Stopping the artifactory service..."
${artServiceFile} stop || exit $?
echo -e " DONE"
fi
fi
if [ -f ${artSystemdFile} ]; then
SERVICE_STATUS="$(systemctl status artifactory.service)"
if [[ ! "$SERVICE_STATUS" =~ .*[sS]topped.* ]]; then
echo
echo -n "Stopping the artifactory service..."
systemctl stop artifactory.service || exit $?
echo -e " DONE"
fi
fi
}
uninstallInitdService() {
if [ -x /usr/sbin/update-rc.d ]; then
/usr/sbin/update-rc.d -f ${serviceInitName} remove &>/dev/null && removeOk=true
elif [ -x /usr/sbin/chkconfig ]; then
/usr/sbin/chkconfig --del ${serviceInitName} &>/dev/null && removeOk=true
elif [ -x /sbin/chkconfig ]; then
/sbin/chkconfig --del ${serviceInitName} &>/dev/null && removeOk=true
fi
[ ${removeOk} ] || error "Could not uninstall service"
removeOk=
if [ -x ${artServiceFile} ]; then
rm -f ${artServiceFile} && removeOk=true
rm -f ${artServiceFile}.disable &>/dev/null
fi
[ ${removeOk} ] || error "Could not delete $artServiceFile"
removeOk=
rm ${TOMCAT_HOME}/bin/setenv.sh && removeOk=true
[ ${removeOk} ] || error "Could not delete $TOMCAT_HOME/bin/setenv.sh"
echo -e " DONE"
}
uninstallSystemdService() {
systemctl disable ${serviceSystemdName} &>/dev/null || error "Could not uninstall service"
if [ -f ${artSystemdFile} ]; then
rm -f ${artSystemdFile} || error "Could not delete $artSystemdFile"
fi
if [ -f ${artSystemdLibFile} ]; then
rm -f ${artSystemdLibFile} || error "Could not delete $artSystemdLibFile"
fi
rm -f ${TOMCAT_HOME}/bin/setenv.sh || error "Could not delete $TOMCAT_HOME/bin/setenv.sh"
echo -e " DONE"
}
uninstallService() {
echo -n "Removing the artifactory service from auto-start..."
# Check if init.d service was installed
if [ -f ${artServiceFile} ]; then
uninstallInitdService
fi
# Check if systemd service was installed
if [ -f ${artSystemdFile} ]; then
uninstallSystemdService
fi
}
moveDir() {
local src=$1
local dest=$2
if [ -z "${src}" ] || [ -z "${dest}" ]; then
return
fi
if [ -d "$src" ]; then
echo "Moving directory ${src} to ${dest}"
mv "${src}" "${dest}" || exit $?
fi
}
createBackup() {
# if some files in data move them to a backup folder
if [ -d "${JF_PRODUCT_HOME}/var/etc" ] || [ -d "${JF_PRODUCT_HOME}/var/data" ] || [ -d "${JF_PRODUCT_HOME}/var/log" ]; then
TIMESTAMP=$(echo "$(date '+%T')" | tr -d ":")
CURRENT_TIME="$(date '+%Y%m%d').$TIMESTAMP"
BACKUP_DIR="${JF_PRODUCT_HOME}/artifactory.backup.${CURRENT_TIME}"
echo "Creating a backup of the artifactory home folder in ${BACKUP_DIR}..."
mkdir -p "${BACKUP_DIR}" || exit $?
moveDir "${productEtcDir}" "${BACKUP_DIR}/etc"
moveDir "${JF_PRODUCT_HOME}/var/data" "${BACKUP_DIR}/data"
moveDir "${JF_PRODUCT_HOME}/var/log" "${BACKUP_DIR}/log"
rm -rf "${JF_PRODUCT_HOME}/var/backup"
rm -rf "${JF_PRODUCT_HOME}/var/bootstrap"
rm -rf "${JF_PRODUCT_HOME}/var/work"
if [ -e ${TOMCAT_HOME}/lib/mysql-connector-java*.jar ]; then
echo; echo -n "MySQL connector found"
mv ${TOMCAT_HOME}/lib/mysql-connector-java* "${BACKUP_DIR}" || exit $?
fi
fi
}
removeArtUser() {
echo "Logging off user $JF_ARTIFACTORY_USER..."
pkill -KILL -u ${JF_ARTIFACTORY_USER}
rm -rf ${JF_PRODUCT_HOME}/app/tomcat/work/* || exit $?
# Ignoring user folders since the home dir is deleted already by the RPM spec
echo; echo -n "Removing user $JF_ARTIFACTORY_USER..."
userdel ${JF_ARTIFACTORY_USER} || exit $?
EXISTING_GROUP="$(grep $artGroup /etc/group | awk -F ':' '{ print $1 }' 2>/dev/null)"
if [ "$EXISTING_GROUP" == "$artGroup" ]; then
echo -n "Removing group $artGroup"
groupdel ${artGroup}
fi
echo -e " DONE"
}
removeResources() {
rm -rf ${productEtcDir} && \
removeOk=true
[ ${removeOk} ] || error "Could not remove ${productEtcDir} directory"
rm -rf ${TOMCAT_HOME}/logs
if [ -d ${TOMCAT_HOME}/logs.original ]; then
mv ${TOMCAT_HOME}/logs.original ${TOMCAT_HOME}/logs
fi
}
showSummary() {
echo
echo -e "\033[33mUninstallation of Artifactory completed\033[0m"
echo -e "Please change the permissions of ${JF_PRODUCT_HOME}/app"
}
sourceScript(){
local fileName=$1
[ ! -z "${fileName}" ] || errorExit "Target file is not set"
[ -f "${fileName}" ] || errorExit "${fileName} file is not found"
source "${fileName}" || errorExit "Unable to source ${fileName}, please check if the $USER user has permissions to perform this action"
}
initHelpers(){
local systemYamlHelper="${ARTIFACTORY_BIN_FOLDER}"/systemYamlHelper.sh
local installerCommon="${ARTIFACTORY_BIN_FOLDER}"/installerCommon.sh
local artCommon="${ARTIFACTORY_BIN_FOLDER}"/artifactoryCommon.sh
export YQ_PATH="${ARTIFACTORY_BIN_FOLDER}/../third-party/yq"
sourceScript "${systemYamlHelper}"
sourceScript "${installerCommon}"
sourceScript "${artCommon}"
# init at each service startup
export JF_SYSTEM_YAML="${JF_PRODUCT_HOME}/var/etc/system.yaml"
}
ARTIFACTORY_BIN_FOLDER="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
artExtractDir="$(cd "$(dirname "$ARTIFACTORY_BIN_FOLDER")" && pwd)"
[ -n "${JF_PRODUCT_HOME}" ] || JF_PRODUCT_HOME="$(cd "$(dirname "$ARTIFACTORY_BIN_FOLDER")"/.. && pwd)"
[ -n "$productEtcDir" ] || productEtcDir="${JF_PRODUCT_HOME}/var/etc"
[ -n "$artServiceFile" ] || artServiceFile="/etc/init.d/artifactory"
[ -n "$artSystemdFile" ] || artSystemdFile="/etc/systemd/system/artifactory.service"
serviceInitName=$(basename ${artServiceFile})
serviceSystemdName=$(basename ${artSystemdFile})
artSystemdLibFile="/lib/systemd/system/artifactory.service"
artDefaultFile="${ARTIFACTORY_BIN_FOLDER}/artifactory.default"
checkRoot
. ${artDefaultFile} || error "$artDefaultFile does not exist or not executable"
initHelpers
# This will set JF_ARTIFACTORY_USER and JF_ARTIFACTORY_GROUP (default artifactory:artifactory)
setUserGroup "$1" "$2"
artGroup="$JF_ARTIFACTORY_USER"
shutdownService
uninstallService
createBackup
removeArtUser
removeResources
showSummary
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment