/usr/bin/tomcat7-instance-create is in tomcat7-user 7.0.56-3+deb8u11.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | #!/bin/sh
# Script to create a CATALINA_BASE directory for your own tomcat
PROG=`basename $0`
TARGET=""
HPORT=8080
CPORT=8005
CWORD="SHUTDOWN"
warned=0
warnlowport=0
usage() {
echo "Usage: $PROG [options] <directoryname>"
echo " directoryname: name of the tomcat instance directory to create"
echo "Options:"
echo " -h, --help Display this help message"
echo " -p httpport HTTP port to be used by Tomcat (default is $HPORT)"
echo " -c controlport Server shutdown control port (default is $CPORT)"
echo " -w magicword Word to send to trigger shutdown (default is $CWORD)"
}
checkport() {
type=$1
port=$2
# Fail if port is non-numeric
num=`expr ${port} + 1 2> /dev/null`
if [ $? != 0 ] || [ $num -lt 2 ]; then
echo "Error: ${type} port '${port}' is not a valid TCP port number."
exit 1
fi
# Fail if port is above 65535
if [ ${port} -gt 65535 ]; then
echo "Error: ${type} port ${port} is above TCP port numbers (> 65535)."
exit 1
fi
# Warn if port is below 1024 (once)
if [ ${warnlowport} -eq 0 ]; then
if [ ${port} -lt 1024 ]; then
echo "Warning: ports below 1024 are reserved to the super-user."
warnlowport=1
warned=1
fi
fi
# Warn if port appears to be in use
if nc localhost "${port}" -z > /dev/null; then
echo "Warning: ${type} port ${port} appears to be in use."
warned=1
fi
}
if [ "$#" -lt 1 ]; then
usage
exit 1
fi
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
usage
exit 0
fi
while getopts ":p:c:w:h" options; do
case $options in
p ) HPORT=$OPTARG ;;
c ) CPORT=$OPTARG ;;
w ) CWORD=$OPTARG ;;
h ) usage;;
* ) echo "Error: Unknown parameter '$OPTARG'."
exit 1;;
esac
done
shift $(($OPTIND - 1))
TARGET=$1
shift
echo "You are about to create a Tomcat instance in directory '$TARGET'"
# Fail if no target specified
if [ -z "${TARGET}" ]; then
echo "Error: No target directory specified (use -d)."
exit 1
fi
# Fail if ports are the same
if [ "${HPORT}" = "${CPORT}" ]; then
echo "Error: HTTP port and control port must be different."
exit 1
fi
# Fail if target directory already exists
if [ -d "${TARGET}" ]; then
echo "Error: Target directory already exists."
exit 1
fi
# Check ports
checkport HTTP "${HPORT}"
checkport Control "${CPORT}"
# Ask for confirmation if warnings were printed out
if [ ${warned} -eq 1 ]; then
echo "Type <ENTER> to continue, <CTRL-C> to abort."
read answer
fi
mkdir -p "${TARGET}"
FULLTARGET=`cd "${TARGET}" > /dev/null && pwd`
mkdir "${TARGET}/conf"
mkdir "${TARGET}/logs"
mkdir "${TARGET}/webapps"
mkdir "${TARGET}/work"
mkdir "${TARGET}/temp"
cp -r /usr/share/tomcat7/skel/* "${TARGET}"
sed -i -e "s/Connector port=\"8080\"/Connector port=\"${HPORT}\"/;s/Server port=\"8005\" shutdown=\"SHUTDOWN\"/Server port=\"${CPORT}\" shutdown=\"${CWORD}\"/" "${TARGET}/conf/server.xml"
cat > "${TARGET}/bin/startup.sh" << EOT
#!/bin/sh
export CATALINA_BASE="${FULLTARGET}"
/usr/share/tomcat7/bin/startup.sh
echo "Tomcat started"
EOT
cat > "${TARGET}/bin/shutdown.sh" << EOT
#!/bin/sh
export CATALINA_BASE="${FULLTARGET}"
/usr/share/tomcat7/bin/shutdown.sh
echo "Tomcat stopped"
EOT
chmod a+x "${TARGET}/bin/startup.sh" "${TARGET}/bin/shutdown.sh"
echo "* New Tomcat instance created in ${TARGET}"
echo "* You might want to edit default configuration in ${TARGET}/conf"
echo "* Run ${TARGET}/bin/startup.sh to start your Tomcat instance"
|