diff options
Diffstat (limited to 'modules/services/web-servers/tomcat.nix')
-rw-r--r-- | modules/services/web-servers/tomcat.nix | 104 |
1 files changed, 52 insertions, 52 deletions
diff --git a/modules/services/web-servers/tomcat.nix b/modules/services/web-servers/tomcat.nix index 83b95655011b..078877b15bc5 100644 --- a/modules/services/web-servers/tomcat.nix +++ b/modules/services/web-servers/tomcat.nix @@ -5,7 +5,7 @@ with pkgs.lib; let cfg = config.services.tomcat; - + in { @@ -13,9 +13,9 @@ in ###### interface options = { - + services.tomcat = { - + enable = mkOption { default = false; description = "Whether to enable Apache Tomcat"; @@ -31,16 +31,16 @@ in example = [ "users" ]; description = "Defines extra groups to which the tomcat user belongs."; }; - + user = mkOption { default = "tomcat"; description = "User account under which Apache Tomcat runs."; - }; + }; group = mkOption { default = "tomcat"; description = "Group account under which Apache Tomcat runs."; - }; + }; javaOpts = mkOption { default = ""; @@ -73,12 +73,12 @@ in }; logPerVirtualHost = mkOption { - default = false; + default = false; description = "Whether to enable logging per virtual host."; - }; + }; axis2 = { - + enable = mkOption { default = false; description = "Whether to enable an Apache Axis2 container"; @@ -88,9 +88,9 @@ in default = []; description = "List containing AAR files or directories with AAR files which are web services to be deployed on Axis2"; }; - + }; - + }; }; @@ -104,7 +104,7 @@ in { name = "tomcat"; gid = config.ids.gids.tomcat; }; - + users.extraUsers = singleton { name = "tomcat"; uid = config.ids.uids.tomcat; @@ -112,7 +112,7 @@ in home = "/homeless-shelter"; extraGroups = cfg.extraGroups; }; - + jobs.tomcat = { description = "Apache Tomcat server"; @@ -122,62 +122,62 @@ in environment = { TZ = config.time.timeZone; }; preStart = - '' + '' # Create the base directory mkdir -p ${cfg.baseDir} - + # Create a symlink to the bin directory of the tomcat component ln -sfn ${pkgs.tomcat6}/bin ${cfg.baseDir}/bin - + # Create a conf/ directory mkdir -p ${cfg.baseDir}/conf chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/conf - + # Symlink the config files in the conf/ directory (except for catalina.properties and server.xml) for i in $(ls ${pkgs.tomcat6}/conf | grep -v catalina.properties | grep -v server.xml) do ln -sfn ${pkgs.tomcat6}/conf/$i ${cfg.baseDir}/conf/`basename $i` done - + # Create subdirectory for virtual hosts mkdir -p ${cfg.baseDir}/virtualhosts - - # Create a modified catalina.properties file + + # 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' \ -e 's|shared.loader=|shared.loader=''${catalina.base}/shared/lib/*.jar|' \ ${pkgs.tomcat6}/conf/catalina.properties > ${cfg.baseDir}/conf/catalina.properties - + # Create a modified server.xml which also includes all virtual hosts sed -e "/<Engine name=\"Catalina\" defaultHost=\"localhost\">/a\ ${ toString (map (virtualHost: ''<Host name=\"${virtualHost.name}\" appBase=\"virtualhosts/${virtualHost.name}/webapps\" unpackWARs=\"true\" autoDeploy=\"true\" xmlValidation=\"false\" xmlNamespaceAware=\"false\" >${if cfg.logPerVirtualHost then ''<Valve className=\"org.apache.catalina.valves.AccessLogValve\" directory=\"logs/${virtualHost.name}\" prefix=\"${virtualHost.name}_access_log.\" pattern=\"combined\" resolveHosts=\"false\"/>'' else ""}</Host>'') cfg.virtualHosts)}" \ ${pkgs.tomcat6}/conf/server.xml > ${cfg.baseDir}/conf/server.xml - + # Create a logs/ directory mkdir -p ${cfg.baseDir}/logs chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/logs - ${if cfg.logPerVirtualHost then + ${if cfg.logPerVirtualHost then toString (map (h: '' mkdir -p ${cfg.baseDir}/logs/${h.name} chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/logs/${h.name} '') cfg.virtualHosts) else ''''} - + # Create a temp/ directory mkdir -p ${cfg.baseDir}/temp chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/temp - # Create a lib/ directory + # Create a lib/ directory mkdir -p ${cfg.baseDir}/lib chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/lib - + # Create a shared/lib directory mkdir -p ${cfg.baseDir}/shared/lib chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/shared/lib - + # Create a webapps/ directory mkdir -p ${cfg.baseDir}/webapps chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/webapps - + # Symlink all the given common libs files or paths into the lib/ directory for i in ${pkgs.tomcat6} ${toString cfg.commonLibs} do @@ -189,13 +189,13 @@ in 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 - done + done # Symlink all the given shared libs files or paths into the shared/lib/ directory for i in ${toString cfg.sharedLibs} @@ -208,14 +208,14 @@ in 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 - done - + done + # Symlink all the given web applications files or paths into the webapps/ directory for i in ${toString cfg.webapps} do @@ -227,12 +227,12 @@ in 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 - + # Also symlink the configuration files if they are included if [ -d $i/conf/Catalina ] then @@ -243,15 +243,15 @@ in done fi fi - done - + 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 for i in "${if virtualHost ? webapps then toString virtualHost.webapps else ""}" @@ -264,12 +264,12 @@ in 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 @@ -279,27 +279,27 @@ in ln -sfn $j ${cfg.baseDir}/conf/Catalina/${virtualHost.name}/`basename $j` done fi - fi + fi done - + '' ) cfg.virtualHosts) } - + # Create a work/ directory mkdir -p ${cfg.baseDir}/work chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/work - + ${if cfg.axis2.enable then '' # 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 @@ -311,12 +311,12 @@ in 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 @@ -326,13 +326,13 @@ in done fi fi - done + done '' else ""} ${pkgs.su}/bin/su -s ${pkgs.bash}/bin/sh ${cfg.user} -c 'CATALINA_BASE=${cfg.baseDir} JAVA_HOME=${pkgs.jdk} JAVA_OPTS="${cfg.javaOpts}" CATALINA_OPTS="${cfg.catalinaOpts}" ${pkgs.tomcat6}/bin/startup.sh' ''; - + postStop = '' echo "Stopping tomcat..." |