2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2009-10-12 16:36:19 +00:00
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with lib;
|
2008-01-30 11:00:59 +00:00
|
|
|
|
|
|
|
let
|
2009-10-12 16:36:19 +00:00
|
|
|
|
|
|
|
cfg = config.services.tomcat;
|
2014-09-11 20:32:16 +00:00
|
|
|
tomcat = cfg.package;
|
2009-10-12 16:36:19 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
2016-09-08 08:47:04 +00:00
|
|
|
meta = {
|
|
|
|
maintainers = with maintainers; [ danbst ];
|
|
|
|
};
|
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
###### interface
|
2008-02-19 16:52:08 +00:00
|
|
|
|
2009-03-06 12:26:34 +00:00
|
|
|
options = {
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
services.tomcat = {
|
2018-02-24 13:13:53 +00:00
|
|
|
enable = mkEnableOption "Apache Tomcat";
|
2009-10-12 16:36:19 +00:00
|
|
|
|
2014-09-11 20:32:16 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
2022-03-11 23:56:44 +00:00
|
|
|
default = pkgs.tomcat9;
|
|
|
|
defaultText = literalExpression "pkgs.tomcat9";
|
2021-10-03 16:06:03 +00:00
|
|
|
example = lib.literalExpression "pkgs.tomcat9";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2014-09-11 20:32:16 +00:00
|
|
|
Which tomcat package to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-10-29 11:26:22 +00:00
|
|
|
purifyOnStart = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
On startup, the `baseDir` directory is populated with various files,
|
|
|
|
subdirectories and symlinks. If this option is enabled, these items
|
|
|
|
(except for the `logs` and `work` subdirectories) are first removed.
|
|
|
|
This prevents interference from remainders of an old configuration
|
|
|
|
(libraries, webapps, etc.), so it's recommended to enable this option.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
baseDir = mkOption {
|
2018-02-24 13:13:53 +00:00
|
|
|
type = lib.types.path;
|
2009-10-12 16:36:19 +00:00
|
|
|
default = "/var/tomcat";
|
2018-10-29 11:26:22 +00:00
|
|
|
description = ''
|
|
|
|
Location where Tomcat stores configuration files, web applications
|
|
|
|
and logfiles. Note that it is partially cleared on each service startup
|
|
|
|
if `purifyOnStart` is enabled.
|
|
|
|
'';
|
2009-10-12 16:36:19 +00:00
|
|
|
};
|
|
|
|
|
2017-12-18 21:36:32 +00:00
|
|
|
logDirs = mkOption {
|
|
|
|
default = [];
|
2018-02-24 13:13:53 +00:00
|
|
|
type = types.listOf types.path;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Directories to create in baseDir/logs/";
|
2017-12-18 21:36:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraConfigFiles = mkOption {
|
|
|
|
default = [];
|
2018-02-24 13:13:53 +00:00
|
|
|
type = types.listOf types.path;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Extra configuration files to pull into the tomcat conf directory";
|
2017-12-18 21:36:32 +00:00
|
|
|
};
|
|
|
|
|
2018-02-24 13:13:53 +00:00
|
|
|
extraEnvironment = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
example = [ "ENVIRONMENT=production" ];
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Environment Variables to pass to the tomcat service";
|
2017-12-18 21:36:32 +00:00
|
|
|
};
|
|
|
|
|
2010-11-01 19:01:26 +00:00
|
|
|
extraGroups = mkOption {
|
|
|
|
default = [];
|
2021-01-22 15:22:06 +00:00
|
|
|
type = types.listOf types.str;
|
2012-02-06 14:04:15 +00:00
|
|
|
example = [ "users" ];
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Defines extra groups to which the tomcat user belongs.";
|
2010-11-01 19:01:26 +00:00
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
user = mkOption {
|
2018-02-24 13:13:53 +00:00
|
|
|
type = types.str;
|
2009-10-12 16:36:19 +00:00
|
|
|
default = "tomcat";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "User account under which Apache Tomcat runs.";
|
2011-09-14 18:20:50 +00:00
|
|
|
};
|
2009-10-12 16:36:19 +00:00
|
|
|
|
|
|
|
group = mkOption {
|
2018-02-24 13:13:53 +00:00
|
|
|
type = types.str;
|
2009-10-12 16:36:19 +00:00
|
|
|
default = "tomcat";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Group account under which Apache Tomcat runs.";
|
2011-09-14 18:20:50 +00:00
|
|
|
};
|
2009-10-12 16:36:19 +00:00
|
|
|
|
|
|
|
javaOpts = mkOption {
|
2018-02-24 13:13:53 +00:00
|
|
|
type = types.either (types.listOf types.str) types.str;
|
2009-10-12 16:36:19 +00:00
|
|
|
default = "";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Parameters to pass to the Java Virtual Machine which spawns Apache Tomcat";
|
2009-10-12 16:36:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
catalinaOpts = mkOption {
|
2018-02-24 13:13:53 +00:00
|
|
|
type = types.either (types.listOf types.str) types.str;
|
2009-10-12 16:36:19 +00:00
|
|
|
default = "";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Parameters to pass to the Java Virtual Machine which spawns the Catalina servlet container";
|
2009-10-12 16:36:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
sharedLibs = mkOption {
|
2018-02-24 13:13:53 +00:00
|
|
|
type = types.listOf types.str;
|
2009-10-12 16:36:19 +00:00
|
|
|
default = [];
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "List containing JAR files or directories with JAR files which are libraries shared by the web applications";
|
2009-10-12 16:36:19 +00:00
|
|
|
};
|
|
|
|
|
2017-12-18 21:36:32 +00:00
|
|
|
serverXml = mkOption {
|
2018-02-24 13:13:53 +00:00
|
|
|
type = types.lines;
|
2017-12-18 21:36:32 +00:00
|
|
|
default = "";
|
2022-08-14 03:16:55 +00:00
|
|
|
description = ''
|
2017-12-18 21:36:32 +00:00
|
|
|
Verbatim server.xml configuration.
|
2018-02-24 13:13:53 +00:00
|
|
|
This is mutually exclusive with the virtualHosts options.
|
2022-08-14 03:16:55 +00:00
|
|
|
'';
|
2017-12-18 21:36:32 +00:00
|
|
|
};
|
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
commonLibs = mkOption {
|
2018-02-24 13:13:53 +00:00
|
|
|
type = types.listOf types.str;
|
2009-10-12 16:36:19 +00:00
|
|
|
default = [];
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "List containing JAR files or directories with JAR files which are libraries shared by the web applications and the servlet container";
|
2009-10-12 16:36:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
webapps = mkOption {
|
2018-08-02 16:22:45 +00:00
|
|
|
type = types.listOf types.path;
|
2018-06-11 09:02:54 +00:00
|
|
|
default = [ tomcat.webapps ];
|
2022-03-11 23:56:44 +00:00
|
|
|
defaultText = literalExpression "[ config.services.tomcat.package.webapps ]";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "List containing WAR files or directories with WAR files which are web applications to be deployed on Tomcat";
|
2009-10-12 16:36:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
virtualHosts = mkOption {
|
2018-02-24 13:13:53 +00:00
|
|
|
type = types.listOf (types.submodule {
|
|
|
|
options = {
|
|
|
|
name = mkOption {
|
2018-08-02 15:46:00 +00:00
|
|
|
type = types.str;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "name of the virtualhost";
|
2018-08-02 15:46:00 +00:00
|
|
|
};
|
2018-09-23 14:41:35 +00:00
|
|
|
aliases = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "aliases of the virtualhost";
|
2018-09-23 14:41:35 +00:00
|
|
|
default = [];
|
|
|
|
};
|
2018-08-02 15:46:00 +00:00
|
|
|
webapps = mkOption {
|
|
|
|
type = types.listOf types.path;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2018-08-02 15:46:00 +00:00
|
|
|
List containing web application WAR files and/or directories containing
|
|
|
|
web applications and configuration files for the virtual host.
|
|
|
|
'';
|
2018-02-24 13:13:53 +00:00
|
|
|
default = [];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
2009-10-12 16:36:19 +00:00
|
|
|
default = [];
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "List consisting of a virtual host name and a list of web applications to deploy on each virtual host";
|
2009-10-12 16:36:19 +00:00
|
|
|
};
|
|
|
|
|
2010-02-17 12:32:19 +00:00
|
|
|
logPerVirtualHost = mkOption {
|
2018-02-24 13:13:53 +00:00
|
|
|
type = types.bool;
|
2011-09-14 18:20:50 +00:00
|
|
|
default = false;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Whether to enable logging per virtual host.";
|
2011-09-14 18:20:50 +00:00
|
|
|
};
|
2010-02-17 12:32:19 +00:00
|
|
|
|
2014-08-01 08:52:19 +00:00
|
|
|
jdk = mkOption {
|
2016-01-17 18:34:55 +00:00
|
|
|
type = types.package;
|
2014-08-01 08:52:19 +00:00
|
|
|
default = pkgs.jdk;
|
2021-10-03 16:06:03 +00:00
|
|
|
defaultText = literalExpression "pkgs.jdk";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Which JDK to use.";
|
2014-08-03 14:09:45 +00:00
|
|
|
};
|
2014-08-01 08:52:19 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
axis2 = {
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-03-06 12:26:34 +00:00
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
2018-02-24 13:13:53 +00:00
|
|
|
type = types.bool;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Whether to enable an Apache Axis2 container";
|
2009-03-06 12:26:34 +00:00
|
|
|
};
|
2009-10-12 16:36:19 +00:00
|
|
|
|
|
|
|
services = mkOption {
|
2009-08-09 20:19:07 +00:00
|
|
|
default = [];
|
2018-02-24 13:13:53 +00:00
|
|
|
type = types.listOf types.str;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "List containing AAR files or directories with AAR files which are web services to be deployed on Axis2";
|
2009-03-06 12:26:34 +00:00
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-03-06 12:26:34 +00:00
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-03-06 12:26:34 +00:00
|
|
|
};
|
2009-10-12 16:36:19 +00:00
|
|
|
|
2009-03-06 12:26:34 +00:00
|
|
|
};
|
|
|
|
|
2008-07-06 19:55:34 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
###### implementation
|
2008-08-06 13:41:08 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
config = mkIf config.services.tomcat.enable {
|
2009-03-06 12:26:34 +00:00
|
|
|
|
2019-09-14 17:51:29 +00:00
|
|
|
users.groups.tomcat.gid = config.ids.gids.tomcat;
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2019-09-14 17:51:29 +00:00
|
|
|
users.users.tomcat =
|
|
|
|
{ uid = config.ids.uids.tomcat;
|
2009-10-12 16:36:19 +00:00
|
|
|
description = "Tomcat user";
|
|
|
|
home = "/homeless-shelter";
|
2022-03-11 23:56:44 +00:00
|
|
|
group = "tomcat";
|
2012-02-06 14:04:15 +00:00
|
|
|
extraGroups = cfg.extraGroups;
|
2009-10-12 16:36:19 +00:00
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2016-01-06 06:50:18 +00:00
|
|
|
systemd.services.tomcat = {
|
|
|
|
description = "Apache Tomcat server";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-09-10 18:21:14 +00:00
|
|
|
after = [ "network.target" ];
|
2016-01-06 06:50:18 +00:00
|
|
|
|
|
|
|
preStart = ''
|
2018-10-29 11:26:22 +00:00
|
|
|
${lib.optionalString cfg.purifyOnStart ''
|
|
|
|
# Delete most directories/symlinks we create from the existing base directory,
|
|
|
|
# to get rid of remainders of an old configuration.
|
|
|
|
# The list of directories to delete is taken from the "mkdir" command below,
|
|
|
|
# excluding "logs" (because logs are valuable) and "work" (because normally
|
|
|
|
# session files are there), and additionally including "bin".
|
|
|
|
rm -rf ${cfg.baseDir}/{conf,virtualhosts,temp,lib,shared/lib,webapps,bin}
|
|
|
|
''}
|
|
|
|
|
2016-01-06 06:50:18 +00:00
|
|
|
# Create the base directory
|
2018-02-24 13:13:53 +00:00
|
|
|
mkdir -p \
|
|
|
|
${cfg.baseDir}/{conf,virtualhosts,logs,temp,lib,shared/lib,webapps,work}
|
|
|
|
chown ${cfg.user}:${cfg.group} \
|
|
|
|
${cfg.baseDir}/{conf,virtualhosts,logs,temp,lib,shared/lib,webapps,work}
|
2017-12-18 21:36:32 +00:00
|
|
|
|
2016-01-06 06:50:18 +00:00
|
|
|
# Create a symlink to the bin directory of the tomcat component
|
|
|
|
ln -sfn ${tomcat}/bin ${cfg.baseDir}/bin
|
|
|
|
|
|
|
|
# Symlink the config files in the conf/ directory (except for catalina.properties and server.xml)
|
2018-02-24 13:13:53 +00:00
|
|
|
for i in $(ls ${tomcat}/conf | grep -v catalina.properties | grep -v server.xml); do
|
|
|
|
ln -sfn ${tomcat}/conf/$i ${cfg.baseDir}/conf/`basename $i`
|
2016-01-06 06:50:18 +00:00
|
|
|
done
|
|
|
|
|
2017-12-18 21:36:32 +00:00
|
|
|
${if cfg.extraConfigFiles != [] then ''
|
2018-02-24 13:13:53 +00:00
|
|
|
for i in ${toString cfg.extraConfigFiles}; do
|
2017-12-18 21:36:32 +00:00
|
|
|
ln -sfn $i ${cfg.baseDir}/conf/`basename $i`
|
|
|
|
done
|
|
|
|
'' else ""}
|
|
|
|
|
2016-01-06 06:50:18 +00:00
|
|
|
# Create a modified catalina.properties file
|
|
|
|
# Change all references from CATALINA_HOME to CATALINA_BASE and add support for shared libraries
|
|
|
|
sed -e 's|''${catalina.home}|''${catalina.base}|g' \
|
2018-02-24 13:13:53 +00:00
|
|
|
-e 's|shared.loader=|shared.loader=''${catalina.base}/shared/lib/*.jar|' \
|
|
|
|
${tomcat}/conf/catalina.properties > ${cfg.baseDir}/conf/catalina.properties
|
2016-01-06 06:50:18 +00:00
|
|
|
|
2017-12-18 21:36:32 +00:00
|
|
|
${if cfg.serverXml != "" then ''
|
2018-02-24 13:13:53 +00:00
|
|
|
cp -f ${pkgs.writeTextDir "server.xml" cfg.serverXml}/* ${cfg.baseDir}/conf/
|
2018-09-23 14:41:35 +00:00
|
|
|
'' else
|
|
|
|
let
|
|
|
|
hostElementForVirtualHost = virtualHost: ''
|
|
|
|
<Host name="${virtualHost.name}" appBase="virtualhosts/${virtualHost.name}/webapps"
|
|
|
|
unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
|
|
|
|
'' + concatStrings (innerElementsForVirtualHost virtualHost) + ''
|
|
|
|
</Host>
|
|
|
|
'';
|
|
|
|
innerElementsForVirtualHost = virtualHost:
|
|
|
|
(map (alias: ''
|
|
|
|
<Alias>${alias}</Alias>
|
|
|
|
'') virtualHost.aliases)
|
|
|
|
++ (optional cfg.logPerVirtualHost ''
|
|
|
|
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs/${virtualHost.name}"
|
|
|
|
prefix="${virtualHost.name}_access_log." pattern="combined" resolveHosts="false"/>
|
|
|
|
'');
|
|
|
|
hostElementsString = concatMapStringsSep "\n" hostElementForVirtualHost cfg.virtualHosts;
|
|
|
|
hostElementsSedString = replaceStrings ["\n"] ["\\\n"] hostElementsString;
|
|
|
|
in ''
|
|
|
|
# Create a modified server.xml which also includes all virtual hosts
|
|
|
|
sed -e "/<Engine name=\"Catalina\" defaultHost=\"localhost\">/a\\"${escapeShellArg hostElementsSedString} \
|
|
|
|
${tomcat}/conf/server.xml > ${cfg.baseDir}/conf/server.xml
|
2017-12-18 21:36:32 +00:00
|
|
|
''
|
|
|
|
}
|
2018-02-24 13:13:53 +00:00
|
|
|
${optionalString (cfg.logDirs != []) ''
|
|
|
|
for i in ${toString cfg.logDirs}; do
|
|
|
|
mkdir -p ${cfg.baseDir}/logs/$i
|
|
|
|
chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/logs/$i
|
|
|
|
done
|
|
|
|
''}
|
|
|
|
${optionalString cfg.logPerVirtualHost (toString (map (h: ''
|
|
|
|
mkdir -p ${cfg.baseDir}/logs/${h.name}
|
|
|
|
chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/logs/${h.name}
|
|
|
|
'') cfg.virtualHosts))}
|
2016-01-06 06:50:18 +00:00
|
|
|
|
|
|
|
# Symlink all the given common libs files or paths into the lib/ directory
|
2018-02-24 13:13:53 +00:00
|
|
|
for i in ${tomcat} ${toString cfg.commonLibs}; do
|
|
|
|
if [ -f $i ]; then
|
|
|
|
# If the given web application is a file, symlink it into the common/lib/ directory
|
|
|
|
ln -sfn $i ${cfg.baseDir}/lib/`basename $i`
|
|
|
|
elif [ -d $i ]; then
|
|
|
|
# If the given web application is a directory, then iterate over the files
|
|
|
|
# in the special purpose directories and symlink them into the tomcat tree
|
|
|
|
|
|
|
|
for j in $i/lib/*; do
|
|
|
|
ln -sfn $j ${cfg.baseDir}/lib/`basename $j`
|
|
|
|
done
|
|
|
|
fi
|
2016-01-06 06:50:18 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# Symlink all the given shared libs files or paths into the shared/lib/ directory
|
2018-02-24 13:13:53 +00:00
|
|
|
for i in ${toString cfg.sharedLibs}; do
|
|
|
|
if [ -f $i ]; then
|
|
|
|
# If the given web application is a file, symlink it into the common/lib/ directory
|
|
|
|
ln -sfn $i ${cfg.baseDir}/shared/lib/`basename $i`
|
|
|
|
elif [ -d $i ]; then
|
|
|
|
# If the given web application is a directory, then iterate over the files
|
|
|
|
# in the special purpose directories and symlink them into the tomcat tree
|
|
|
|
|
|
|
|
for j in $i/shared/lib/*; do
|
|
|
|
ln -sfn $j ${cfg.baseDir}/shared/lib/`basename $j`
|
|
|
|
done
|
|
|
|
fi
|
2016-01-06 06:50:18 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# Symlink all the given web applications files or paths into the webapps/ directory
|
2018-02-24 13:13:53 +00:00
|
|
|
for i in ${toString cfg.webapps}; do
|
|
|
|
if [ -f $i ]; then
|
|
|
|
# If the given web application is a file, symlink it into the webapps/ directory
|
|
|
|
ln -sfn $i ${cfg.baseDir}/webapps/`basename $i`
|
|
|
|
elif [ -d $i ]; then
|
|
|
|
# If the given web application is a directory, then iterate over the files
|
|
|
|
# in the special purpose directories and symlink them into the tomcat tree
|
|
|
|
|
|
|
|
for j in $i/webapps/*; do
|
|
|
|
ln -sfn $j ${cfg.baseDir}/webapps/`basename $j`
|
|
|
|
done
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2018-02-24 13:13:53 +00:00
|
|
|
# Also symlink the configuration files if they are included
|
|
|
|
if [ -d $i/conf/Catalina ]; then
|
|
|
|
for j in $i/conf/Catalina/*; do
|
|
|
|
mkdir -p ${cfg.baseDir}/conf/Catalina/localhost
|
|
|
|
ln -sfn $j ${cfg.baseDir}/conf/Catalina/localhost/`basename $j`
|
|
|
|
done
|
2016-01-06 06:50:18 +00:00
|
|
|
fi
|
2018-02-24 13:13:53 +00:00
|
|
|
fi
|
2016-01-06 06:50:18 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
${toString (map (virtualHost: ''
|
|
|
|
# Create webapps directory for the virtual host
|
|
|
|
mkdir -p ${cfg.baseDir}/virtualhosts/${virtualHost.name}/webapps
|
|
|
|
|
|
|
|
# Modify ownership
|
|
|
|
chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/virtualhosts/${virtualHost.name}/webapps
|
|
|
|
|
|
|
|
# Symlink all the given web applications files or paths into the webapps/ directory
|
|
|
|
# of this virtual host
|
2018-02-24 13:13:53 +00:00
|
|
|
for i in "${if virtualHost ? webapps then toString virtualHost.webapps else ""}"; do
|
|
|
|
if [ -f $i ]; then
|
|
|
|
# If the given web application is a file, symlink it into the webapps/ directory
|
|
|
|
ln -sfn $i ${cfg.baseDir}/virtualhosts/${virtualHost.name}/webapps/`basename $i`
|
|
|
|
elif [ -d $i ]; then
|
|
|
|
# If the given web application is a directory, then iterate over the files
|
|
|
|
# in the special purpose directories and symlink them into the tomcat tree
|
|
|
|
|
|
|
|
for j in $i/webapps/*; do
|
|
|
|
ln -sfn $j ${cfg.baseDir}/virtualhosts/${virtualHost.name}/webapps/`basename $j`
|
|
|
|
done
|
|
|
|
|
|
|
|
# Also symlink the configuration files if they are included
|
|
|
|
if [ -d $i/conf/Catalina ]; then
|
|
|
|
for j in $i/conf/Catalina/*; do
|
|
|
|
mkdir -p ${cfg.baseDir}/conf/Catalina/${virtualHost.name}
|
|
|
|
ln -sfn $j ${cfg.baseDir}/conf/Catalina/${virtualHost.name}/`basename $j`
|
|
|
|
done
|
2016-01-06 06:50:18 +00:00
|
|
|
fi
|
2018-02-24 13:13:53 +00:00
|
|
|
fi
|
2016-01-06 06:50:18 +00:00
|
|
|
done
|
2018-02-24 13:13:53 +00:00
|
|
|
'') cfg.virtualHosts)}
|
|
|
|
|
|
|
|
${optionalString cfg.axis2.enable ''
|
|
|
|
# Copy the Axis2 web application
|
|
|
|
cp -av ${pkgs.axis2}/webapps/axis2 ${cfg.baseDir}/webapps
|
|
|
|
|
|
|
|
# Turn off addressing, which causes many errors
|
|
|
|
sed -i -e 's%<module ref="addressing"/>%<!-- <module ref="addressing"/> -->%' ${cfg.baseDir}/webapps/axis2/WEB-INF/conf/axis2.xml
|
|
|
|
|
|
|
|
# Modify permissions on the Axis2 application
|
|
|
|
chown -R ${cfg.user}:${cfg.group} ${cfg.baseDir}/webapps/axis2
|
|
|
|
|
|
|
|
# Symlink all the given web service files or paths into the webapps/axis2/WEB-INF/services directory
|
|
|
|
for i in ${toString cfg.axis2.services}; do
|
|
|
|
if [ -f $i ]; then
|
|
|
|
# If the given web service is a file, symlink it into the webapps/axis2/WEB-INF/services
|
|
|
|
ln -sfn $i ${cfg.baseDir}/webapps/axis2/WEB-INF/services/`basename $i`
|
|
|
|
elif [ -d $i ]; then
|
|
|
|
# If the given web application is a directory, then iterate over the files
|
|
|
|
# in the special purpose directories and symlink them into the tomcat tree
|
|
|
|
|
|
|
|
for j in $i/webapps/axis2/WEB-INF/services/*; do
|
|
|
|
ln -sfn $j ${cfg.baseDir}/webapps/axis2/WEB-INF/services/`basename $j`
|
|
|
|
done
|
|
|
|
|
|
|
|
# Also symlink the configuration files if they are included
|
|
|
|
if [ -d $i/conf/Catalina ]; then
|
|
|
|
for j in $i/conf/Catalina/*; do
|
|
|
|
ln -sfn $j ${cfg.baseDir}/conf/Catalina/localhost/`basename $j`
|
|
|
|
done
|
2017-12-18 21:36:32 +00:00
|
|
|
fi
|
2018-02-24 13:13:53 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
''}
|
2016-01-06 06:50:18 +00:00
|
|
|
'';
|
2012-02-06 14:04:15 +00:00
|
|
|
|
2018-02-24 13:13:53 +00:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "forking";
|
|
|
|
PermissionsStartOnly = true;
|
|
|
|
PIDFile="/run/tomcat/tomcat.pid";
|
|
|
|
RuntimeDirectory = "tomcat";
|
|
|
|
User = cfg.user;
|
|
|
|
Environment=[
|
|
|
|
"CATALINA_BASE=${cfg.baseDir}"
|
|
|
|
"CATALINA_PID=/run/tomcat/tomcat.pid"
|
|
|
|
"JAVA_HOME='${cfg.jdk}'"
|
|
|
|
"JAVA_OPTS='${builtins.toString cfg.javaOpts}'"
|
|
|
|
"CATALINA_OPTS='${builtins.toString cfg.catalinaOpts}'"
|
|
|
|
] ++ cfg.extraEnvironment;
|
|
|
|
ExecStart = "${tomcat}/bin/startup.sh";
|
|
|
|
ExecStop = "${tomcat}/bin/shutdown.sh";
|
|
|
|
};
|
2016-01-06 06:50:18 +00:00
|
|
|
};
|
2009-03-06 12:26:34 +00:00
|
|
|
};
|
2008-01-30 11:00:59 +00:00
|
|
|
}
|