2009-03-06 12:26:34 +00:00
|
|
|
{pkgs, config, ...}:
|
2008-01-30 11:00:59 +00:00
|
|
|
|
2009-03-06 12:26:34 +00:00
|
|
|
###### interface
|
2008-01-30 11:00:59 +00:00
|
|
|
let
|
2009-03-06 12:26:34 +00:00
|
|
|
inherit (pkgs.lib) mkOption mkIf;
|
2008-02-19 16:52:08 +00:00
|
|
|
|
2009-03-06 12:26:34 +00:00
|
|
|
options = {
|
|
|
|
services = {
|
|
|
|
tomcat = {
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable Apache Tomcat";
|
|
|
|
};
|
2008-07-23 15:13:27 +01:00
|
|
|
|
2009-03-06 12:26:34 +00:00
|
|
|
baseDir = mkOption {
|
|
|
|
default = "/var/tomcat";
|
|
|
|
description = "Location where Tomcat stores configuration files, webapplications and logfiles";
|
|
|
|
};
|
2008-07-23 15:13:27 +01:00
|
|
|
|
2009-03-06 12:26:34 +00:00
|
|
|
user = mkOption {
|
|
|
|
default = "tomcat";
|
|
|
|
description = "User account under which Apache Tomcat runs.";
|
|
|
|
};
|
2008-07-23 15:13:27 +01:00
|
|
|
|
2009-03-06 12:26:34 +00:00
|
|
|
deployFrom = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "Location where webapplications are stored. Leave empty to use the baseDir.";
|
|
|
|
};
|
2008-07-23 15:13:27 +01:00
|
|
|
|
2009-03-06 12:26:34 +00:00
|
|
|
javaOpts = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "Parameters to pass to the Java Virtual Machine which spawns Apache Tomcat";
|
|
|
|
};
|
2008-07-23 15:13:27 +01:00
|
|
|
|
2009-03-06 12:26:34 +00:00
|
|
|
catalinaOpts = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "Parameters to pass to the Java Virtual Machine which spawns the Catalina servlet container";
|
|
|
|
};
|
2008-07-23 15:13:27 +01:00
|
|
|
|
2009-03-06 12:26:34 +00:00
|
|
|
sharedLibFrom = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "Location where shared libraries are stored. Leave empty to use the baseDir.";
|
|
|
|
};
|
|
|
|
|
|
|
|
commonLibFrom = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "Location where common libraries are stored. Leave empty to use the baseDir.";
|
|
|
|
};
|
|
|
|
|
|
|
|
contextXML = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "Location of the context.xml to use. Leave empty to use the default.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
|
|
|
|
###### implementation
|
2008-07-06 20:55:34 +01:00
|
|
|
|
2009-03-06 12:26:34 +00:00
|
|
|
let
|
|
|
|
cfg = config.services.tomcat;
|
|
|
|
in
|
2008-08-06 14:41:08 +01:00
|
|
|
|
2009-03-06 12:26:34 +00:00
|
|
|
mkIf config.services.tomcat.enable {
|
|
|
|
require = [
|
|
|
|
options
|
|
|
|
];
|
|
|
|
|
|
|
|
services = {
|
|
|
|
extraJobs = [{
|
|
|
|
name = "tomcat";
|
|
|
|
|
|
|
|
groups = [
|
|
|
|
{ name = "tomcat";
|
2009-05-29 15:25:56 +01:00
|
|
|
gid = config.ids.gids.tomcat;
|
2009-03-06 12:26:34 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
users = [
|
|
|
|
{ name = "tomcat";
|
2009-05-29 15:25:56 +01:00
|
|
|
uid = config.ids.uids.tomcat;
|
2009-03-06 12:26:34 +00:00
|
|
|
description = "Tomcat user";
|
|
|
|
home = "/homeless-shelter";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
job = ''
|
|
|
|
description "Apache Tomcat server"
|
|
|
|
|
|
|
|
start on network-interface/started
|
|
|
|
stop on network-interfaces/stop
|
2008-07-23 15:13:27 +01:00
|
|
|
|
2009-03-06 12:26:34 +00:00
|
|
|
start script
|
|
|
|
# Create initial state data
|
|
|
|
|
|
|
|
if ! test -d ${cfg.baseDir}
|
|
|
|
then
|
|
|
|
mkdir -p ${cfg.baseDir}/webapps
|
|
|
|
mkdir -p ${cfg.baseDir}/shared
|
|
|
|
mkdir -p ${cfg.baseDir}/lib
|
|
|
|
cp -av ${pkgs.tomcat6}/{conf,temp,logs} ${cfg.baseDir}
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Deploy context.xml
|
|
|
|
|
|
|
|
if test "${cfg.contextXML}" = ""
|
|
|
|
then
|
|
|
|
cp ${pkgs.tomcat6}/conf/context.xml.default ${cfg.baseDir}/conf/context.xml
|
|
|
|
else
|
|
|
|
cp ${cfg.contextXML} ${cfg.baseDir}/conf/context.xml
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Deploy all webapplications
|
|
|
|
|
|
|
|
if ! test "${cfg.deployFrom}" = ""
|
|
|
|
then
|
|
|
|
rm -rf ${cfg.baseDir}/webapps
|
|
|
|
mkdir -p ${cfg.baseDir}/webapps
|
|
|
|
for i in ${cfg.deployFrom}/*
|
|
|
|
do
|
|
|
|
cp -rL $i ${cfg.baseDir}/webapps
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Fix permissions
|
|
|
|
|
|
|
|
chown -R ${cfg.user} ${cfg.baseDir}
|
|
|
|
|
|
|
|
for i in `find ${cfg.baseDir} -type d`
|
|
|
|
do
|
|
|
|
chmod -v 755 $i
|
|
|
|
done
|
|
|
|
|
|
|
|
for i in `find ${cfg.baseDir} -type f`
|
|
|
|
do
|
|
|
|
chmod -v 644 $i
|
|
|
|
done
|
2008-07-06 20:55:34 +01:00
|
|
|
|
2009-03-06 12:26:34 +00:00
|
|
|
# Deploy all common libraries
|
|
|
|
|
|
|
|
rm -rf ${cfg.baseDir}/lib/*
|
|
|
|
|
|
|
|
if test "${cfg.commonLibFrom}" = ""
|
|
|
|
then
|
|
|
|
commonLibFrom="${pkgs.tomcat6}/lib";
|
|
|
|
else
|
|
|
|
commonLibFrom="${cfg.commonLibFrom}";
|
|
|
|
fi
|
|
|
|
|
|
|
|
for i in $commonLibFrom/*.jar
|
|
|
|
do
|
|
|
|
ln -s $i ${cfg.baseDir}/lib
|
|
|
|
done
|
|
|
|
|
|
|
|
# Deploy all shared libraries
|
|
|
|
|
|
|
|
if ! test "${cfg.sharedLibFrom}" = ""
|
|
|
|
then
|
|
|
|
rm -f ${cfg.baseDir}/shared/lib
|
|
|
|
ln -s ${cfg.sharedLibFrom} ${cfg.baseDir}/shared/lib
|
|
|
|
fi
|
|
|
|
|
|
|
|
end script
|
|
|
|
|
|
|
|
respawn ${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; sleep 1000d'
|
|
|
|
|
|
|
|
stop script
|
|
|
|
echo "Stopping tomcat..."
|
|
|
|
CATALINA_BASE=${cfg.baseDir} JAVA_HOME=${pkgs.jdk} ${pkgs.su}/bin/su -s ${pkgs.bash}/bin/sh ${cfg.user} -c ${pkgs.tomcat6}/bin/shutdown.sh
|
|
|
|
end script
|
|
|
|
'';
|
|
|
|
}];
|
|
|
|
};
|
2008-01-30 11:00:59 +00:00
|
|
|
}
|