Import acme-utils and tomcat-bin ebuilds

Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
This commit is contained in:
Stefan Knoblich
2021-02-16 13:44:16 +01:00
parent d66a55eeb7
commit 334b29843d
9 changed files with 823 additions and 0 deletions

View File

@@ -0,0 +1,240 @@
#!/bin/bash
# Copyright 1999-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# Author: Ralph Sennhauser <sera@gentoo.org>
die() {
echo "${@}"
exit 1
}
usage() {
cat <<EOL
Usage: ${BASH_SOURCE} <--create|--remove|--help> [--suffix s][--user u][--group g]
Options:
--help:
show this text.
--create:
create a new instance
--remove:
remove an existing instance.
--suffix SUFFIX:
a suffix for this instance. the suffix may not collide with an already
existing instance, defaults to empty.
--user USER:
the user for which to configure this instance for. The user needs to
exist already. defaults to tomcat.
--group GROUP:
the group for which to configure this instance for. The group needs to
exist already. defaults to tomcat.
Examples:
${BASH_SOURCE} --create --suffix testing --user tacmot --group tacmot
${BASH_SOURCE} --remove --suffix testing
EOL
}
parse_argv() {
action="not specified"
instance_name="tomcat-@SLOT@"
instance_user="tomcat"
instance_group="tomcat"
while [[ -n $1 ]]; do
case $1 in
--help)
usage
exit 0;;
--suffix)
instance_name+="-$2"
shift; shift;;
--user)
instance_user="$2"
shift; shift;;
--group)
instance_group="$2"
shift; shift;;
--create)
action=create
shift;;
--remove)
action=remove
shift;;
--backup)
action=backup
shift;;
--restore)
action=restore
shift;;
--update)
action=update
shift;;
*)
echo "Invalid option '$1'"
usage
exit 2;;
esac
done
tomcat_home="/@GENTOO_PORTAGE_EPREFIX@usr/share/tomcat-@SLOT@"
instance_base="/@GENTOO_PORTAGE_EPREFIX@var/lib/${instance_name}"
instance_conf="/@GENTOO_PORTAGE_EPREFIX@etc/${instance_name}"
instance_logs="/@GENTOO_PORTAGE_EPREFIX@var/log/${instance_name}"
instance_temp="/@GENTOO_PORTAGE_EPREFIX@var/tmp/${instance_name}"
all_targets=(
"${instance_base}"
"${instance_logs}"
"${instance_temp}"
"/@GENTOO_PORTAGE_EPREFIX@etc/${instance_name}"
"/@GENTOO_PORTAGE_EPREFIX@etc/init.d/${instance_name}"
"/@GENTOO_PORTAGE_EPREFIX@etc/conf.d/${instance_name}"
)
}
test_can_deploy() {
local no_deploy target
for target in "${all_targets[@]}"; do
if [[ -e "${target}" ]]; then
echo "Error: '${target}' already exists."
no_deploy=yes
fi
done
if [[ -n "${no_deploy}" ]]; then
cat <<-EOL
To protect an existing installation no new instance was deployed. You can use
'${BASH_SOURCE} --remove'
to remove an existing instance first or run
'${BASH_SOURCE} --create --sufix <instance_suffix>'
to deploy an instance under a different name
EOL
usage
exit 1
fi
if ! getent passwd | cut -d: -f1 | grep -Fx "${instance_user}" > /dev/null; then
echo "Error: user '${instance_user}' doesn't exist."
exit 1
fi
if ! getent group | cut -d: -f1 | grep -Fx "${instance_group}" > /dev/null; then
echo "Error: group '${instance_group}' doesn't exist."
exit 1
fi
}
deploy_instance() {
test_can_deploy
mkdir -p "${instance_base}"/{work,webapps} || die
mkdir -p "${instance_logs}" || die
mkdir -p "${instance_temp}" || die
cp -r "${tomcat_home}"/webapps/ROOT "${instance_base}"/webapps || die
chown -R "${instance_user}":"${instance_group}" \
"${instance_base}" "${instance_logs}" "${instance_temp}" || die
find "${instance_base}"/webapps -type d -exec chmod 750 {} + || die
find "${instance_base}"/webapps -type f -exec chmod 640 {} + || die
# initial config #
cp -r "${tomcat_home}"/conf "${instance_conf}" || die
sed -i -e "s|\${catalina.base}/logs|${instance_logs}|" \
"${instance_conf}"/logging.properties || die
sed -i -e "s|directory=\"logs\"|directory=\"${instance_logs}\"|" \
"${instance_conf}"/server.xml || die
mkdir -p "${instance_conf}"/Catalina/localhost || die
cat > "${instance_conf}"/Catalina/localhost/host-manager.xml <<-'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="${catalina.home}/webapps/host-manager"
antiResourceLocking="false" privileged="true" />
EOF
cat > "${instance_conf}"/Catalina/localhost/manager.xml <<-'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="${catalina.home}/webapps/manager"
antiResourceLocking="false" privileged="true" />
EOF
if [[ -d "${tomcat_home}"/webapps/docs ]]; then
cat > "${instance_conf}"/Catalina/localhost/docs.xml <<-'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="${catalina.home}/webapps/docs" />
EOF
fi
if [[ -d "${tomcat_home}"/webapps/examples ]]; then
cat > "${instance_conf}"/Catalina/localhost/examples.xml <<-'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="${catalina.home}/webapps/examples" />
EOF
fi
chown -R "${instance_user}":"${instance_group}" "${instance_conf}" || die
find "${instance_conf}" -type d -exec chmod 750 {} + || die
find "${instance_conf}" -type f -exec chmod 640 {} + || die
# rc script #
cp "${tomcat_home}"/gentoo/tomcat.init \
"/@GENTOO_PORTAGE_EPREFIX@etc/init.d/${instance_name}" || die
sed -e "s|@INSTANCE_NAME@|${instance_name}|g" \
-e "s|@INSTANCE_USER@|${instance_user}|g" \
-e "s|@INSTANCE_GROUP@|${instance_group}|g" \
"${tomcat_home}"/gentoo/tomcat.conf \
> "/@GENTOO_PORTAGE_EPREFIX@etc/conf.d/${instance_name}" || die
# some symlinks for tomcat and netbeans #
ln -s "${instance_conf}" "${instance_base}"/conf || die
ln -s "${instance_temp}" "${instance_base}"/temp || die
# a note to update the default configuration #
cat <<-EOL
Successfully created instance '${instance_name}'
It's strongly recommended for production systems to go carefully through the
configuration files at '${instance_conf}'.
The generated initial configuration is close to upstreams default which
favours the demo aspect over hardening.
EOL
}
remove_instance() {
echo "The following files will be removed permanently:"
local target; for target in "${all_targets[@]}"; do
find ${target}
done
echo "Type 'yes' to continue"
read
if [[ ${REPLY} == yes ]]; then
rm -rv "${all_targets[@]}"
else
echo "Aborting as requested ..."
fi
}
parse_argv "$@"
if [[ ${action} == create ]]; then
deploy_instance
elif [[ ${action} == remove ]]; then
remove_instance
elif [[ ${action} == "not specified" ]]; then
echo "No action specified!"
usage
exit 1
else
echo "${action} not yet implemented!"
usage
exit 1
fi

View File

@@ -0,0 +1,49 @@
# Set the handle of the JVM to use. If unset uses the system-vm.
# run 'eselect java-vm list' to get possible values.
#
#TOMCAT_JVM="icedtea-7"
# Additional options to pass to the JVM.
# Example to set library path for tomcat-native:
# JAVA_OPTS="-Djava.library.path=/usr/lib"
#
#JAVA_OPTS=""
# Additional packages to put on the default classpath.
# jakarta-jstl is needed for some of the examples.
# Note: The extra jars listed here will be visible to webapps.
# Example:
# TOMCAT_EXTRA_JARS="jakarta-jstl,xerces-2"
#
#TOMCAT_EXTRA_JARS=""
# User/Group of this instance.
CATALINA_USER=@INSTANCE_USER@
CATALINA_GROUP=@INSTANCE_GROUP@
# Directory path location of temporary directory the JVM should
# use (java.io.tmpdir).
# Note: This directory must exist and be read/writable by tomcat.
# See #246362 as an example where /var/tmp was deleted on shutdown.
#
#CATALINA_TMPDIR="/@GENTOO_PORTAGE_EPREFIX@var/tmp/@INSTANCE_NAME@"
# TOMCAT STARTUP
# debug Start Catalina in a debugger
# -security debug Debug Catalina with a security manager
# jpda start Start Catalina under JPDA debugger
# start Start Catalina in a separate window
# -security start Start in a separate window with security manager
#
#TOMCAT_START="start"
# Java Platform Debugger Architecture (JPDA)
# http://java.sun.com/products/jpda/
# Override default JPDA address and transport for the "jpda start" command.
#
#JPDA_ADDRESS="8000"
#JPDA_TRANSPORT="dt_socket"
# Additional options to pass to catalina
#
#CATALINA_OPTS=""

View File

@@ -0,0 +1,105 @@
#!/@GENTOO_PORTAGE_EPREFIX@sbin/openrc-run
# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
extra_commands="forcestop"
PIDFILE=/@GENTOO_PORTAGE_EPREFIX@var/run/${RC_SVCNAME}.pid
: ${CATALINA_HOME:=/@GENTOO_PORTAGE_EPREFIX@opt/tomcat@SLOT@}
: ${CATALINA_BASE:=/@GENTOO_PORTAGE_EPREFIX@var/lib/${RC_SVCNAME}}
: ${CATALINA_TMPDIR:=/@GENTOO_PORTAGE_EPREFIX@var/tmp/${RC_SVCNAME}}
: ${CATALINA_USER:=tomcat}
: ${CATALINA_GROUP:=tomcat}
: ${TOMCAT_START:=start}
: ${JPDA_TRANSPORT:="dt_socket"}
: ${JPDA_ADDRESS:="8000"}
: ${JPDA_OPTS="-Xdebug -Xrunjdwp:transport=${JPDA_TRANSPORT},address=${JPDA_ADDRESS},server=y,suspend=n"}
export JAVA_HOME=`java-config ${TOMCAT_JVM:+--select-vm ${TOMCAT_JVM}} --jre-home`
CLASSPATH=`java-config --classpath tomcat-bin-@SLOT@${TOMCAT_EXTRA_JARS:+,${TOMCAT_EXTRA_JARS}}`
export CLASSPATH="${CLASSPATH}${TOMCAT_EXTRA_CLASSPATH:+:${TOMCAT_EXTRA_CLASSPATH}}"
depend() {
use dns logger net
}
start() {
ebegin "Starting '${RC_SVCNAME}'"
if [ ! -e "${CATALINA_TMPDIR}" ]; then
eerror "CATALINA_TMPDIR does not exist. Unable to start tomcat."
eerror "Please see /@GENTOO_PORTAGE_EPREFIX@etc/conf.d/${RC_SVCNAME} for more information."
eend 1
fi
cmd=java args=
if [ "${TOMCAT_START}" = "debug" ] || [ "${TOMCAT_START}" = "-security debug" ] ; then
cmd=jdb
args="${args} -sourcepath ${CATALINA_HOME}/../../jakarta-tomcat-catalina/catalina/src/share"
fi
if [ "${TOMCAT_START}" = "-security debug" ] || [ "${TOMCAT_START}" = "-security start" ]; then
args="${args} -Djava.security.manager"
args="${args} -Djava.security.policy=${CATALINA_BASE}/conf/catalina.policy"
fi
if [ "${TOMCAT_START}" = "jpda start" ] ; then
args="${args} ${JPDA_OPTS}"
fi
if [ -r "${CATALINA_HOME}"/bin/tomcat-juli.jar ]; then
args="${args} -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager \
-Djava.util.logging.config.file=${CATALINA_BASE}/conf/logging.properties"
fi
start-stop-daemon --start \
--quiet --background \
--chdir "${CATALINA_TMPDIR}" \
--user ${CATALINA_USER}:${CATALINA_GROUP} \
--make-pidfile --pidfile ${PIDFILE} \
--exec ${JAVA_HOME}/bin/${cmd} \
-- \
${JAVA_OPTS} \
${args} \
-Dcatalina.base="${CATALINA_BASE}" \
-Dcatalina.home="${CATALINA_HOME}" \
-Djava.io.tmpdir="${CATALINA_TMPDIR}" \
-classpath "${CLASSPATH}" \
org.apache.catalina.startup.Bootstrap \
${CATALINA_OPTS} \
${TOMCAT_START}
eend $?
}
stop() {
ebegin "Stopping '${RC_SVCNAME}'"
start-stop-daemon --stop \
--quiet --retry=60 \
--pidfile ${PIDFILE} \
--exec ${JAVA_HOME}/bin/java \
-- \
${JAVA_OPTS} \
-classpath "${CLASSPATH}" \
${CATALINA_OPTS} \
stop ${STD_OUT}
eend $?
}
forcestop() {
ebegin "Forcing '${RC_SVCNAME}' to stop"
start-stop-daemon --stop \
--quiet --retry=60 \
--pidfile ${PIDFILE} \
--signal=9
if service_started "${RC_SVCNAME}"; then
mark_service_stopped "${RC_SVCNAME}"
fi
eend $?
}

View File

@@ -0,0 +1,145 @@
#!/bin/bash
# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
eerror() {
echo "ERROR: ${@}" >&2
}
RC_SVCNAME="${2:-tomcat@SLOT@}"
RC_SVCBASE="/@GENTOO_PORTAGE_EPREFIX@etc/conf.d/"
RC_SVCCONF="${RC_SVCBASE}${RC_SVCNAME}"
if [ ! -e "${RC_SVCCONF}" ]; then
# Try alternate (preferred) service name "tomcat@SLOT@-NAME" before giving up
RC_SVCNAME="tomcat@SLOT@-${RC_SVCNAME/tomcat@SLOT@-/}"
RC_SVCCONF="${RC_SVCBASE}${RC_SVCNAME}"
if [ ! -e "${RC_SVCCONF}" ]; then
eerror "Invalid instance name \"${RC_SVCNAME}\""
eerror "Make sure the instance name is correct and the configuration file"
eerror "in \"${RC_SVCCONF}\" exists and is readable by the tomcat user"
exit 1
fi
fi
source ${RC_SVCCONF}
if [ $? -ne 0 ]; then
eerror "Environment configuration file \"${RC_SVCCONF}\" contains errors"
exit 1
fi
: ${CATALINA_HOME:=/@GENTOO_PORTAGE_EPREFIX@opt/tomcat@SLOT@}
: ${CATALINA_BASE:=/@GENTOO_PORTAGE_EPREFIX@var/lib/${RC_SVCNAME}}
: ${CATALINA_TMPDIR:=/@GENTOO_PORTAGE_EPREFIX@var/tmp/${RC_SVCNAME}}
: ${TOMCAT_START:=start}
: ${JPDA_TRANSPORT:="dt_socket"}
: ${JPDA_ADDRESS:="8000"}
: ${JPDA_OPTS="-Xdebug -Xrunjdwp:transport=${JPDA_TRANSPORT},address=${JPDA_ADDRESS},server=y,suspend=n"}
JAVA_HOME=`java-config ${TOMCAT_JVM:+--select-vm ${TOMCAT_JVM}} --jre-home`
CLASSPATH=`java-config --classpath tomcat-bin-@SLOT@${TOMCAT_EXTRA_JARS:+,${TOMCAT_EXTRA_JARS}}`
CLASSPATH="${CLASSPATH}${TOMCAT_EXTRA_CLASSPATH:+:${TOMCAT_EXTRA_CLASSPATH}}"
start() {
if [ ! -e "${CATALINA_BASE}" ]; then
eerror "CATALINA_BASE does not exist. Unable to start tomcat."
exit 1
fi
if [ ! -e "${CATALINA_HOME}" ]; then
eerror "CATALINA_HOME does not exist. Unable to start tomcat."
exit 1
fi
if [ ! -e "${CATALINA_TMPDIR}" ]; then
eerror "CATALINA_TMPDIR does not exist. Unable to start tomcat."
eerror "Please see /@GENTOO_PORTAGE_EPREFIX@etc/conf.d/${RC_SVCNAME} for more information."
exit 1
fi
if [ $(id -u) -eq 0 ]; then
eerror "This service should not be started as root"
exit 1
fi
cmd=java args=
if [ "${TOMCAT_START}" = "debug" ] || [ "${TOMCAT_START}" = "-security debug" ] ; then
cmd=jdb
args="${args} -sourcepath ${CATALINA_HOME}/../../jakarta-tomcat-catalina/catalina/src/share"
fi
if [ "${TOMCAT_START}" = "-security debug" ] || [ "${TOMCAT_START}" = "-security start" ]; then
args="${args} -Djava.security.manager"
args="${args} -Djava.security.policy=${CATALINA_BASE}/conf/catalina.policy"
fi
if [ "${TOMCAT_START}" = "jpda start" ] ; then
args="${args} ${JPDA_OPTS}"
fi
if [ -r "${CATALINA_HOME}"/bin/tomcat-juli.jar ]; then
args="${args} -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager \
-Djava.util.logging.config.file=${CATALINA_BASE}/conf/logging.properties"
fi
cd "${CATALINA_BASE}"
exec ${JAVA_HOME}/bin/${cmd} \
${JAVA_OPTS} \
${args} \
-Dcatalina.base="${CATALINA_BASE}" \
-Dcatalina.home="${CATALINA_HOME}" \
-Djava.io.tmpdir="${CATALINA_TMPDIR}" \
-classpath "${CLASSPATH}" \
org.apache.catalina.startup.Bootstrap \
${CATALINA_OPTS} \
${TOMCAT_START}
}
stop() {
exec ${JAVA_HOME}/bin/java \
${JAVA_OPTS} \
-Dcatalina.base="${CATALINA_BASE}" \
-Dcatalina.home="${CATALINA_HOME}" \
-Djava.io.tmpdir="${CATALINA_TMPDIR}" \
-classpath "${CLASSPATH}" \
org.apache.catalina.startup.Bootstrap \
${CATALINA_OPTS} \
stop
ret=$?
# Ignore sigterm
[[ $ret -eq 143 ]] && \
ret=0
return $ret
}
version() {
exec ${JAVA_HOME}/bin/java \
${JAVA_OPTS} \
-Dcatalina.base="${CATALINA_BASE}" \
-Dcatalina.home="${CATALINA_HOME}" \
-Djava.io.tmpdir="${CATALINA_TMPDIR}" \
-classpath "${CLASSPATH}" \
org.apache.catalina.util.ServerInfo
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
version)
version
;;
*)
echo "Usage: $0 {start|stop|restart|version|getenv} [instance name]" >&2
exit 1
esac