Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tomcat with lvm #2

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 53 additions & 6 deletions nixos/modules/services/web-servers/tomcat.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ in
description = "Location where Tomcat stores configuration files, webapplications and logfiles";
};

logDirs = mkOption {
default = [];
description = "Directories to create in baseDir/logs/";
};

extraConfigFiles = mkOption {
default = [];
description = "Extra configuration files to pull into the tomcat conf directory";
};

environment = mkOption {
default = "";
description = "File to be sourced before executing tomcat. Can be used to set environment variables";
};

extraGroups = mkOption {
default = [];
example = [ "users" ];
Expand Down Expand Up @@ -71,6 +86,14 @@ in
description = "List containing JAR files or directories with JAR files which are libraries shared by the web applications";
};

serverXml = mkOption {
default = "";
description = "
Verbatim server.xml configuration.
This is mutualyl exclusive with the virtualHosts options.
";
};

commonLibs = mkOption {
default = [];
description = "List containing JAR files or directories with JAR files which are libraries shared by the web applications and the servlet container";
Expand Down Expand Up @@ -147,6 +170,8 @@ in
# Create the base directory
mkdir -p ${cfg.baseDir}

mkdir -p ${cfg.baseDir}

# Create a symlink to the bin directory of the tomcat component
ln -sfn ${tomcat}/bin ${cfg.baseDir}/bin

Expand All @@ -160,6 +185,13 @@ in
ln -sfn ${tomcat}/conf/$i ${cfg.baseDir}/conf/`basename $i`
done

${if cfg.extraConfigFiles != [] then ''
for i in ${toString cfg.extraConfigFiles}
do
ln -sfn $i ${cfg.baseDir}/conf/`basename $i`
done
'' else ""}

# Create subdirectory for virtual hosts
mkdir -p ${cfg.baseDir}/virtualhosts

Expand All @@ -169,14 +201,24 @@ in
-e 's|shared.loader=|shared.loader=''${catalina.base}/shared/lib/*.jar|' \
${tomcat}/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)}" \
${tomcat}/conf/server.xml > ${cfg.baseDir}/conf/server.xml

${if cfg.serverXml != "" then ''
cat <<'EOF' > ${cfg.baseDir}/conf/server.xml
${cfg.serverXml}EOF
'' else ''
# 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)}" \
${tomcat}/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.logDirs != [] then ''
for i in ${toString cfg.logDirs}; do
mkdir -p ${cfg.baseDir}/logs/$i
chown ${cfg.user}:${cfg.group} ${cfg.baseDir}/logs/$i
done
'' else ""}
${if cfg.logPerVirtualHost then
toString (map (h: ''
mkdir -p ${cfg.baseDir}/logs/${h.name}
Expand Down Expand Up @@ -353,6 +395,11 @@ in
'';

script = ''
${if cfg.environment != "" then ''
if [ -r ${cfg.environment} ]; then
. ${cfg.environment}
fi
'' else ""}
${pkgs.su}/bin/su -s ${pkgs.bash}/bin/sh ${cfg.user} -c 'CATALINA_BASE=${cfg.baseDir} JAVA_HOME=${cfg.jdk} JAVA_OPTS="${cfg.javaOpts}" CATALINA_OPTS="${cfg.catalinaOpts}" ${tomcat}/bin/startup.sh'
'';

Expand All @@ -363,6 +410,6 @@ in

};

};
};

}
1 change: 0 additions & 1 deletion nixos/modules/system/boot/stage-1-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ udevadm settle
# XXX: Use case usb->lvm will still fail, usb->luks->lvm is covered
@preLVMCommands@


echo "starting device mapper and LVM..."
lvm vgchange -ay

Expand Down
10 changes: 9 additions & 1 deletion nixos/modules/virtualisation/grow-partition.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,19 @@ with lib;
'';

boot.initrd.postDeviceCommands = ''
set -x
echo "boot.initrd.postDeviceCommands: running grow partition"
rootDevice="${config.fileSystems."/".device}"
if [ -e "$rootDevice" ]; then
rootDevice="$(readlink -f "$rootDevice")"
parentDevice="$(lsblk -npo PKNAME "$rootDevice")"
TMPDIR=/run sh $(type -P growpart) "$parentDevice" "''${rootDevice#$parentDevice}"
# support nvme style partitions on AWS
if echo "$parentDevice" | grep nvme >/dev/null 2>&1; then
partitionNumber="''${rootDevice#''${parentDevice}p}"
else
partitionNumber="''${rootDevice#$parentDevice}"
fi
TMPDIR=/run sh $(type -P growpart) "$parentDevice" "$partitionNumber"
udevadm settle
fi
'';
Expand Down