Share option definitions between the systemd and Upstart compatibility modules
This commit is contained in:
parent
f74ffe3550
commit
9f9ae7c7e9
@ -181,20 +181,19 @@ in
|
||||
postStart =
|
||||
''
|
||||
while ! psql postgres -c ""; do
|
||||
stop_check
|
||||
sleep 1
|
||||
done
|
||||
'';
|
||||
|
||||
extraConfig =
|
||||
serviceConfig =
|
||||
''
|
||||
# Shut down Postgres using SIGINT ("Fast Shutdown mode"). See
|
||||
# http://www.postgresql.org/docs/current/static/server-shutdown.html
|
||||
kill signal INT
|
||||
KillSignal=SIGINT
|
||||
|
||||
# Give Postgres a decent amount of time to clean up after
|
||||
# receiving Upstart's SIGINT.
|
||||
kill timeout 60
|
||||
# receiving systemd's SIGINT.
|
||||
TimeoutSec=60
|
||||
'';
|
||||
};
|
||||
|
||||
|
101
modules/system/boot/systemd-unit-options.nix
Normal file
101
modules/system/boot/systemd-unit-options.nix
Normal file
@ -0,0 +1,101 @@
|
||||
{ config, pkgs }:
|
||||
|
||||
with pkgs.lib;
|
||||
|
||||
{
|
||||
|
||||
serviceOptions = {
|
||||
|
||||
description = mkOption {
|
||||
default = "";
|
||||
types = types.uniq types.string;
|
||||
description = "Description of this unit used in systemd messages and progress indicators.";
|
||||
};
|
||||
|
||||
requires = mkOption {
|
||||
default = [];
|
||||
types = types.listOf types.string;
|
||||
description = ''
|
||||
Start the specified units when this unit is started, and stop
|
||||
this unit when the specified units are stopped or fail.
|
||||
'';
|
||||
};
|
||||
|
||||
wants = mkOption {
|
||||
default = [];
|
||||
types = types.listOf types.string;
|
||||
description = ''
|
||||
Start the specified units when this unit is started.
|
||||
'';
|
||||
};
|
||||
|
||||
after = mkOption {
|
||||
default = [];
|
||||
types = types.listOf types.string;
|
||||
description = ''
|
||||
If the specified units are started at the same time as
|
||||
this unit, delay this unit until they have started.
|
||||
'';
|
||||
};
|
||||
|
||||
before = mkOption {
|
||||
default = [];
|
||||
types = types.listOf types.string;
|
||||
description = ''
|
||||
If the specified units are started at the same time as
|
||||
this unit, delay them until this unit has started.
|
||||
'';
|
||||
};
|
||||
|
||||
wantedBy = mkOption {
|
||||
default = [];
|
||||
types = types.listOf types.string;
|
||||
description = "Units that want (i.e. depend on) this unit.";
|
||||
};
|
||||
|
||||
environment = mkOption {
|
||||
default = {};
|
||||
type = types.attrs;
|
||||
example = { PATH = "/foo/bar/bin"; LANG = "nl_NL.UTF-8"; };
|
||||
description = "Environment variables passed to the services's processes.";
|
||||
};
|
||||
|
||||
path = mkOption {
|
||||
default = [];
|
||||
apply = ps: "${makeSearchPath "bin" ps}:${makeSearchPath "sbin" ps}";
|
||||
description = ''
|
||||
Packages added to the service's <envar>PATH</envar>
|
||||
environment variable. Both the <filename>bin</filename>
|
||||
and <filename>sbin</filename> subdirectories of each
|
||||
package are added.
|
||||
'';
|
||||
};
|
||||
|
||||
serviceConfig = mkOption {
|
||||
default = "";
|
||||
type = types.string;
|
||||
description = ''
|
||||
Contents of the <literal>[Service]</literal> section of the unit.
|
||||
See <citerefentry><refentrytitle>systemd.unit</refentrytitle>
|
||||
<manvolnum>5</manvolnum></citerefentry> for details.
|
||||
'';
|
||||
};
|
||||
|
||||
script = mkOption {
|
||||
type = types.uniq types.string;
|
||||
default = "";
|
||||
description = "Shell commands executed as the service's main process.";
|
||||
};
|
||||
|
||||
preStart = mkOption {
|
||||
type = types.string;
|
||||
default = "";
|
||||
description = ''
|
||||
Shell commands executed before the service's main process
|
||||
is started.
|
||||
'';
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -1,122 +1,10 @@
|
||||
{ config, pkgs, ... }:
|
||||
|
||||
with pkgs.lib;
|
||||
with import ./systemd-unit-options.nix { inherit config pkgs; };
|
||||
|
||||
let
|
||||
|
||||
servicesOptions = {
|
||||
|
||||
description = mkOption {
|
||||
default = "";
|
||||
types = types.uniq types.string;
|
||||
description = "Description of this unit used in systemd messages and progress indicators.";
|
||||
};
|
||||
|
||||
requires = mkOption {
|
||||
default = [];
|
||||
types = types.listOf types.string;
|
||||
description = ''
|
||||
Start the specified units when this unit is started, and stop
|
||||
this unit when the specified units are stopped or fail.
|
||||
'';
|
||||
};
|
||||
|
||||
wants = mkOption {
|
||||
default = [];
|
||||
types = types.listOf types.string;
|
||||
description = ''
|
||||
Start the specified units when this unit is started.
|
||||
'';
|
||||
};
|
||||
|
||||
after = mkOption {
|
||||
default = [];
|
||||
types = types.listOf types.string;
|
||||
description = ''
|
||||
If the specified units are started at the same time as
|
||||
this unit, delay this unit until they have started.
|
||||
'';
|
||||
};
|
||||
|
||||
before = mkOption {
|
||||
default = [];
|
||||
types = types.listOf types.string;
|
||||
description = ''
|
||||
If the specified units are started at the same time as
|
||||
this unit, delay them until this unit has started.
|
||||
'';
|
||||
};
|
||||
|
||||
wantedBy = mkOption {
|
||||
default = [];
|
||||
types = types.listOf types.string;
|
||||
description = "Start this unit when the specified units are started.";
|
||||
};
|
||||
|
||||
environment = mkOption {
|
||||
default = {};
|
||||
type = types.attrs;
|
||||
example = { PATH = "/foo/bar/bin"; LANG = "nl_NL.UTF-8"; };
|
||||
description = "Environment variables passed to the services's processes.";
|
||||
};
|
||||
|
||||
path = mkOption {
|
||||
default = [];
|
||||
apply = ps: "${makeSearchPath "bin" ps}:${makeSearchPath "sbin" ps}";
|
||||
description = ''
|
||||
Packages added to the service's <envar>PATH</envar>
|
||||
environment variable. Both the <filename>bin</filename>
|
||||
and <filename>sbin</filename> subdirectories of each
|
||||
package are added.
|
||||
'';
|
||||
};
|
||||
|
||||
serviceConfig = mkOption {
|
||||
default = "";
|
||||
type = types.string;
|
||||
description = ''
|
||||
Contents of the <literal>[Service]</literal> section of the unit.
|
||||
See <citerefentry><refentrytitle>systemd.unit</refentrytitle>
|
||||
<manvolnum>5</manvolnum></citerefentry> for details.
|
||||
'';
|
||||
};
|
||||
|
||||
script = mkOption {
|
||||
type = types.uniq types.string;
|
||||
default = "";
|
||||
description = "Shell commands executed as the service's main process.";
|
||||
};
|
||||
|
||||
preStart = mkOption {
|
||||
type = types.string;
|
||||
default = "";
|
||||
description = ''
|
||||
Shell commands executed before the service's main process
|
||||
is started.
|
||||
'';
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
servicesConfig = { name, config, ... }: {
|
||||
|
||||
config = {
|
||||
|
||||
# Default path for systemd services. Should be quite minimal.
|
||||
path =
|
||||
[ pkgs.coreutils
|
||||
pkgs.findutils
|
||||
pkgs.gnugrep
|
||||
pkgs.gnused
|
||||
systemd
|
||||
];
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
cfg = config.boot.systemd;
|
||||
|
||||
systemd = pkgs.systemd;
|
||||
@ -260,6 +148,19 @@ let
|
||||
|
||||
makeJobScript = name: content: "${pkgs.writeScriptBin name content}/bin/${name}";
|
||||
|
||||
serviceConfig = { name, config, ... }: {
|
||||
config = {
|
||||
# Default path for systemd services. Should be quite minimal.
|
||||
path =
|
||||
[ pkgs.coreutils
|
||||
pkgs.findutils
|
||||
pkgs.gnugrep
|
||||
pkgs.gnused
|
||||
systemd
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
serviceToUnit = name: def:
|
||||
{ inherit (def) wantedBy;
|
||||
|
||||
@ -350,29 +251,24 @@ in
|
||||
description = "Definition of systemd units.";
|
||||
default = {};
|
||||
type = types.attrsOf types.optionSet;
|
||||
|
||||
options = {
|
||||
|
||||
text = mkOption {
|
||||
types = types.uniq types.string;
|
||||
description = "Text of this systemd unit.";
|
||||
};
|
||||
|
||||
wantedBy = mkOption {
|
||||
default = [];
|
||||
types = types.listOf types.string;
|
||||
description = "Units that want (i.e. depend on) this unit.";
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
boot.systemd.services = mkOption {
|
||||
description = "Definition of systemd services.";
|
||||
default = {};
|
||||
type = types.attrsOf types.optionSet;
|
||||
options = [ servicesOptions servicesConfig ];
|
||||
options = [ serviceOptions serviceConfig ];
|
||||
};
|
||||
|
||||
boot.systemd.defaultUnit = mkOption {
|
||||
|
@ -1,11 +1,10 @@
|
||||
{ config, pkgs, ... }:
|
||||
|
||||
with pkgs.lib;
|
||||
with import ../boot/systemd-unit-options.nix { inherit config pkgs; };
|
||||
|
||||
let
|
||||
|
||||
upstart = pkgs.upstart;
|
||||
|
||||
userExists = u:
|
||||
(u == "") || any (uu: uu.name == u) (attrValues config.users.extraUsers);
|
||||
|
||||
@ -66,6 +65,8 @@ let
|
||||
|
||||
serviceConfig =
|
||||
''
|
||||
${job.serviceConfig}
|
||||
|
||||
${optionalString (job.preStart != "" && (job.script != "" || job.exec != "")) ''
|
||||
ExecStartPre=${preStartScript}
|
||||
''}
|
||||
@ -100,7 +101,7 @@ let
|
||||
};
|
||||
|
||||
|
||||
jobOptions = {
|
||||
jobOptions = serviceOptions // {
|
||||
|
||||
name = mkOption {
|
||||
# !!! The type should ensure that this could be a filename.
|
||||
@ -111,14 +112,6 @@ let
|
||||
'';
|
||||
};
|
||||
|
||||
description = mkOption {
|
||||
type = types.string;
|
||||
default = "";
|
||||
description = ''
|
||||
A short description of this job.
|
||||
'';
|
||||
};
|
||||
|
||||
startOn = mkOption {
|
||||
# !!! Re-enable this once we're on Upstart >= 0.6.
|
||||
#type = types.string;
|
||||
@ -137,15 +130,6 @@ let
|
||||
'';
|
||||
};
|
||||
|
||||
preStart = mkOption {
|
||||
type = types.string;
|
||||
default = "";
|
||||
description = ''
|
||||
Shell commands executed before the job is started
|
||||
(i.e. before the job's main process is started).
|
||||
'';
|
||||
};
|
||||
|
||||
postStart = mkOption {
|
||||
type = types.string;
|
||||
default = "";
|
||||
@ -186,15 +170,6 @@ let
|
||||
'';
|
||||
};
|
||||
|
||||
script = mkOption {
|
||||
type = types.string;
|
||||
default = "";
|
||||
description = ''
|
||||
Shell commands executed as the job's main process. Can be
|
||||
specified instead of the <varname>exec</varname> attribute.
|
||||
'';
|
||||
};
|
||||
|
||||
respawn = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
@ -223,15 +198,6 @@ let
|
||||
'';
|
||||
};
|
||||
|
||||
environment = mkOption {
|
||||
type = types.attrs;
|
||||
default = {};
|
||||
example = { PATH = "/foo/bar/bin"; LANG = "nl_NL.UTF-8"; };
|
||||
description = ''
|
||||
Environment variables passed to the job's processes.
|
||||
'';
|
||||
};
|
||||
|
||||
daemonType = mkOption {
|
||||
type = types.string;
|
||||
default = "none";
|
||||
@ -264,15 +230,6 @@ let
|
||||
'';
|
||||
};
|
||||
|
||||
extraConfig = mkOption {
|
||||
type = types.string;
|
||||
default = "";
|
||||
example = "limit nofile 4096 4096";
|
||||
description = ''
|
||||
Additional Upstart stanzas not otherwise supported.
|
||||
'';
|
||||
};
|
||||
|
||||
path = mkOption {
|
||||
default = [];
|
||||
description = ''
|
||||
@ -282,18 +239,6 @@ let
|
||||
'';
|
||||
};
|
||||
|
||||
console = mkOption {
|
||||
default = "";
|
||||
example = "console";
|
||||
description = ''
|
||||
If set to <literal>output</literal>, job output is written to
|
||||
the console. If it's <literal>owner</literal>, additionally
|
||||
the job becomes owner of the console. It it's empty (the
|
||||
default), output is written to
|
||||
<filename>/var/log/upstart/<replaceable>jobname</replaceable></filename>
|
||||
'';
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -313,15 +258,6 @@ let
|
||||
# The default name is the name extracted from the attribute path.
|
||||
name = mkDefaultValue name;
|
||||
|
||||
# Default path for Upstart jobs. Should be quite minimal.
|
||||
path =
|
||||
[ pkgs.coreutils
|
||||
pkgs.findutils
|
||||
pkgs.gnugrep
|
||||
pkgs.gnused
|
||||
upstart
|
||||
];
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user