/[gentoo-x86]/www-servers/tomcat/files/tomcat-instance-manager.bash
Gentoo

Contents of /www-servers/tomcat/files/tomcat-instance-manager.bash

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations) (download)
Fri Jul 20 17:36:54 2012 UTC (7 years, 3 months ago) by sera
Branch: MAIN
CVS Tags: HEAD
Full rewrite.
Add tomcat-instance-manager.bash to convienintly create and remove multiple instances.
Don't symlink jars but use java-config as appropriate.
Migrate init script to baselayout2 including major cleanup.
Add use extra-webapps to build and install the docs and examples web apps. Use USE=doc for javadocs.
Major cleanup of the ebuild, like dropping elog massages obsolete for ages.
Don't copy manager and host-manager to catalina base but use a shared instance in catalina home which gets updated with a package
update.
Actually install sources if requested.
Initial Gentoo Prefix support.
#180519 : don kill ROOT application
#191611 : init script improvements
#254526 : emerge --config, implemented with tomcat-instance-manager.bash
#283273, #363931 : build docs and examples
#309211 : handling of manager / host-manager
#333153 : arbitrary classpath per instance
#381693 : init fails with non existent CATALINA_TMPDIR
#406285, #411597 : support multiple instances
#407979 : fails if /run is tmpfs
#420383 : forces invalid java compiler

(Portage version: 2.1.11.9/cvs/Linux x86_64)

1 #!/bin/bash
2 # Copyright 1999-2012 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # Author: Ralph Sennhauser <sera@gentoo.org>
5
6 die() {
7 echo "${@}"
8 exit 1
9 }
10
11 usage() {
12 cat <<EOL
13 Usage: ${BASH_SOURCE} <--create|--remove|--help> [--suffix s][--user u][--group g]
14
15 Options:
16 --help:
17 show this text.
18 --create:
19 create a new instance
20 --remove:
21 remove an existing instance.
22 --suffix SUFFIX:
23 a suffix for this instance. the suffix may not collide with an already
24 existing instance, defaults to empty.
25 --user USER:
26 the user for which to configure this instance for. The user needs to
27 exist already. defaults to tomcat.
28 --group GROUP:
29 the group for which to configure this instance for. The group needs to
30 exist already. defaults to tomcat.
31
32 Examples:
33 ${BASH_SOURCE} --create --suffix testing --user tacmot --group tacmot
34 ${BASH_SOURCE} --remove --suffix testing
35 EOL
36 }
37
38 parse_argv() {
39 action="not specified"
40 instance_name="tomcat-@SLOT@"
41 instance_user="tomcat"
42 instance_group="tomcat"
43
44 while [[ -n $1 ]]; do
45 case $1 in
46 --help)
47 usage
48 exit 0;;
49 --suffix)
50 instance_name+="-$2"
51 shift; shift;;
52 --user)
53 instance_user="$2"
54 shift; shift;;
55 --group)
56 instance_group="$2"
57 shift; shift;;
58 --create)
59 action=create
60 shift;;
61 --remove)
62 action=remove
63 shift;;
64 --backup)
65 action=backup
66 shift;;
67 --restore)
68 action=restore
69 shift;;
70 --update)
71 action=update
72 shift;;
73 *)
74 echo "Invalid option '$1'"
75 usage
76 exit 2;;
77 esac
78 done
79
80 tomcat_home="/@GENTOO_PORTAGE_EPREFIX@usr/share/tomcat-@SLOT@"
81 instance_base="/@GENTOO_PORTAGE_EPREFIX@var/lib/${instance_name}"
82 instance_conf="/@GENTOO_PORTAGE_EPREFIX@etc/${instance_name}"
83 instance_logs="/@GENTOO_PORTAGE_EPREFIX@var/log/${instance_name}"
84 instance_temp="/@GENTOO_PORTAGE_EPREFIX@var/tmp/${instance_name}"
85
86 all_targets=(
87 "${instance_base}"
88 "${instance_logs}"
89 "${instance_temp}"
90 "/@GENTOO_PORTAGE_EPREFIX@etc/${instance_name}"
91 "/@GENTOO_PORTAGE_EPREFIX@etc/init.d/${instance_name}"
92 "/@GENTOO_PORTAGE_EPREFIX@etc/conf.d/${instance_name}"
93 )
94 }
95
96 test_can_deploy() {
97 local no_deploy target
98 for target in "${all_targets[@]}"; do
99 if [[ -e "${target}" ]]; then
100 echo "Error: '${target}' already exists."
101 no_deploy=yes
102 fi
103 done
104 if [[ -n "${no_deploy}" ]]; then
105 cat <<-EOL
106
107 To protect an existing installation no new instance was deployed. You can use
108 '${BASH_SOURCE} --remove'
109 to remove an existing instance first or run
110 '${BASH_SOURCE} --create --sufix <instance_suffix>'
111 to deploy an instance under a different name
112
113 EOL
114 usage
115 exit 1
116 fi
117
118 if ! id --user "${instance_user}" >/dev/null 2>&1; then
119 echo "Error: user '${instance_user}' doesn't exist."
120 exit 1
121 fi
122
123 if ! id --group "${instance_group}" >/dev/null 2>&1; then
124 echo "Error: group '${instance_group}' doesn't exist."
125 exit 1
126 fi
127 }
128
129 deploy_instance() {
130 test_can_deploy
131
132 mkdir -p "${instance_base}"/{work,webapps} || die
133 mkdir -p "${instance_logs}" || die
134 mkdir -p "${instance_temp}" || die
135
136 cp -r "${tomcat_home}"/webapps/ROOT "${instance_base}"/webapps || die
137
138 chown -R "${instance_user}":"${instance_group}" \
139 "${instance_base}" "${instance_logs}" "${instance_temp}" || die
140
141 find "${instance_base}"/webapps -type d -exec chmod 750 {} + || die
142 find "${instance_base}"/webapps -type f -exec chmod 640 {} + || die
143
144 # initial config #
145
146 cp -r "${tomcat_home}"/conf "${instance_conf}" || die
147
148 sed -i -e "s|\${catalina.base}/logs|${instance_logs}|" \
149 "${instance_conf}"/logging.properties || die
150 sed -i -e "s|directory=\"logs\"|directory=\"${instance_logs}\"|" \
151 "${instance_conf}"/server.xml || die
152
153 mkdir -p "${instance_conf}"/Catalina/localhost || die
154 cat > "${instance_conf}"/Catalina/localhost/host-manager.xml <<-'EOF'
155 <?xml version="1.0" encoding="UTF-8"?>
156 <Context docBase="${catalina.home}/webapps/host-manager"
157 antiResourceLocking="false" privileged="true" />
158 EOF
159
160 cat > "${instance_conf}"/Catalina/localhost/manager.xml <<-'EOF'
161 <?xml version="1.0" encoding="UTF-8"?>
162 <Context docBase="${catalina.home}/webapps/manager"
163 antiResourceLocking="false" privileged="true" />
164 EOF
165
166 if [[ -d "${tomcat_home}"/webapps/docs ]]; then
167 cat > "${instance_conf}"/Catalina/localhost/docs.xml <<-'EOF'
168 <?xml version="1.0" encoding="UTF-8"?>
169 <Context docBase="${catalina.home}/webapps/docs" />
170 EOF
171 fi
172
173 if [[ -d "${tomcat_home}"/webapps/examples ]]; then
174 cat > "${instance_conf}"/Catalina/localhost/examples.xml <<-'EOF'
175 <?xml version="1.0" encoding="UTF-8"?>
176 <Context docBase="${catalina.home}/webapps/examples" />
177 EOF
178 fi
179
180 chown -R "${instance_user}":"${instance_group}" "${instance_conf}" || die
181 find "${instance_conf}" -type d -exec chmod 750 {} + || die
182 find "${instance_conf}" -type f -exec chmod 640 {} + || die
183
184 # rc script #
185
186 cp "${tomcat_home}"/gentoo/tomcat.init \
187 "/@GENTOO_PORTAGE_EPREFIX@etc/init.d/${instance_name}" || die
188
189 sed -e "s|@INSTANCE_NAME@|${instance_name}|g" \
190 -e "s|@INSTANCE_USER@|${instance_user}|g" \
191 -e "s|@INSTANCE_GROUP@|${instance_group}|g" \
192 "${tomcat_home}"/gentoo/tomcat.conf \
193 > "/@GENTOO_PORTAGE_EPREFIX@etc/conf.d/${instance_name}" || die
194
195 # some symlinks for tomcat and netbeans #
196
197 ln -s "${instance_conf}" "${instance_base}"/conf || die
198 ln -s "${instance_temp}" "${instance_base}"/temp || die
199
200 # a note to update the default configuration #
201
202 cat <<-EOL
203 Successfully created instance '${instance_name}'
204 It's strongly recommended for production systems to go carefully through the
205 configuration files at '${instance_conf}'.
206 The generated initial configuration is close to upstreams default which
207 favours the demo aspect over hardening.
208 EOL
209 }
210
211 remove_instance() {
212 echo "The following files will be removed permanently:"
213 local target; for target in "${all_targets[@]}"; do
214 find ${target}
215 done
216
217 echo "Type 'yes' to continue"
218 read
219 if [[ ${REPLY} == yes ]]; then
220 rm -rv "${all_targets[@]}"
221 else
222 echo "Aborting as requested ..."
223 fi
224 }
225
226 parse_argv "$@"
227
228 if [[ ${action} == create ]]; then
229 deploy_instance
230 elif [[ ${action} == remove ]]; then
231 remove_instance
232 elif [[ ${action} == "not specified" ]]; then
233 echo "No action specified!"
234 usage
235 exit 1
236 else
237 echo "${action} not yet implemented!"
238 usage
239 exit 1
240 fi

  ViewVC Help
Powered by ViewVC 1.1.20