2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2014-03-12 21:06:28 +00:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2014-03-12 21:06:28 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.winstone;
|
|
|
|
|
|
|
|
winstoneOpts = { name, ... }: {
|
|
|
|
options = {
|
|
|
|
name = mkOption {
|
|
|
|
default = name;
|
|
|
|
internal = true;
|
|
|
|
};
|
|
|
|
|
2014-03-12 22:28:38 +00:00
|
|
|
serviceName = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
The name of the systemd service. By default, it is
|
|
|
|
derived from the winstone instance name.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-03-12 21:06:28 +00:00
|
|
|
warFile = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
The WAR file that Winstone should serve.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
javaPackage = mkOption {
|
|
|
|
type = types.package;
|
2015-01-07 19:20:46 +00:00
|
|
|
default = pkgs.jre;
|
2016-01-17 18:34:55 +00:00
|
|
|
defaultText = "pkgs.jre";
|
2014-03-12 21:06:28 +00:00
|
|
|
description = ''
|
|
|
|
Which Java derivation to use for running Winstone.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
The user that should run this Winstone process and
|
|
|
|
own the working directory.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
The group that will own the working directory.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
workDir = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
The working directory for this Winstone instance. Will
|
|
|
|
contain extracted webapps etc. The directory will be
|
|
|
|
created if it doesn't exist.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraJavaOptions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
Extra command line options given to the java process running
|
|
|
|
Winstone.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraOptions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
Extra command line options given to the Winstone process.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
workDir = mkDefault "/run/winstone/${name}";
|
2014-03-12 22:28:38 +00:00
|
|
|
serviceName = mkDefault "winstone-${name}";
|
2014-03-12 21:06:28 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
mkService = cfg: let
|
|
|
|
opts = concatStringsSep " " (cfg.extraOptions ++ [
|
|
|
|
"--warfile ${cfg.warFile}"
|
|
|
|
]);
|
|
|
|
|
|
|
|
javaOpts = concatStringsSep " " (cfg.extraJavaOptions ++ [
|
|
|
|
"-Djava.io.tmpdir=${cfg.workDir}"
|
|
|
|
"-jar ${pkgs.winstone}/lib/winstone.jar"
|
|
|
|
]);
|
|
|
|
in {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
description = "winstone service for ${cfg.name}";
|
|
|
|
preStart = ''
|
|
|
|
mkdir -p "${cfg.workDir}"
|
|
|
|
chown ${cfg.user}:${cfg.group} "${cfg.workDir}"
|
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${cfg.javaPackage}/bin/java ${javaOpts} ${opts}";
|
|
|
|
User = cfg.user;
|
|
|
|
PermissionsStartOnly = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
in {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
services.winstone = mkOption {
|
|
|
|
default = {};
|
|
|
|
type = types.attrsOf types.optionSet;
|
|
|
|
options = [ winstoneOpts ];
|
|
|
|
description = ''
|
|
|
|
Defines independent Winstone services, each serving one WAR-file.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf (cfg != {}) {
|
|
|
|
|
2014-03-12 22:28:38 +00:00
|
|
|
systemd.services = mapAttrs' (n: c: nameValuePair c.serviceName (mkService c)) cfg;
|
2014-03-12 21:06:28 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|