From 7813be5e54bac085bd125591f72f44c7d12db2da Mon Sep 17 00:00:00 2001 From: Sander van der Burg Date: Sat, 5 Jul 2008 22:27:36 +0000 Subject: [PATCH] Updated tomcat service with a more sophisticated model svn path=/nixos/trunk/; revision=12268 --- system/ids.nix | 4 ++- system/options.nix | 2 +- upstart-jobs/tomcat.nix | 70 +++++++++++++++++++++++++++++++++++------ 3 files changed, 64 insertions(+), 12 deletions(-) diff --git a/system/ids.nix b/system/ids.nix index 312fd94e351e..4a94179eea60 100644 --- a/system/ids.nix +++ b/system/ids.nix @@ -17,6 +17,7 @@ zabbix = 13; postfix = 14; dovecot = 15; + tomcat = 16; nixbld = 30000; # start of range of uids nobody = 65534; @@ -42,7 +43,8 @@ floppy = 18; uucp = 19; lp = 20; - + tomcat = 21; + users = 100; nixbld = 30000; nogroup = 65534; diff --git a/system/options.nix b/system/options.nix index 0bdbe3921354..378c42792898 100644 --- a/system/options.nix +++ b/system/options.nix @@ -1446,7 +1446,7 @@ }; user = mkOption { - default = "nobody"; + default = "tomcat"; description = "User account under which Apache Tomcat runs."; }; diff --git a/upstart-jobs/tomcat.nix b/upstart-jobs/tomcat.nix index e5b7d1d2b21b..f595ad199722 100644 --- a/upstart-jobs/tomcat.nix +++ b/upstart-jobs/tomcat.nix @@ -1,23 +1,73 @@ args: with args; let - cfg = config.services.tomcat; - - tomcatService = import ../services/tomcat { - inherit (pkgs) stdenv jdk tomcat6 su; - inherit (cfg) baseDir user deployFrom; - }; - in { name = "tomcat"; + + groups = [ + { name = "tomcat"; + gid = (import ../system/ids.nix).gids.tomcat; + } + ]; + + users = [ + { name = "tomcat"; + uid = (import ../system/ids.nix).uids.tomcat; + description = "Tomcat user"; + home = "/homeless-shelter"; + } + ]; + job = '' description "Apache Tomcat server" - stop on shutdown - - respawn ${tomcatService}/bin/control start + start on network-interface/started + stop on network-interfaces/stop + + start script + # Create initial state data + + if ! test -d ${cfg.baseDir} + then + mkdir -p ${cfg.baseDir}/webapps + cp -av ${pkgs.tomcat6}/{conf,temp,logs} ${cfg.baseDir} + 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 + end script + + respawn ${pkgs.su}/bin/su -s ${pkgs.bash}/bin/sh ${cfg.user} -c 'CATALINA_BASE=${cfg.baseDir} JAVA_HOME=${pkgs.jdk} ${pkgs.tomcat6}/bin/startup.sh; sleep 1d' + + 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 ''; }