nixos-module/server/lxc-containers: make container startup conditional
preparing for cold failover
This commit is contained in:
parent
8434dcad0f
commit
30aa03f07f
|
@ -138,6 +138,16 @@ let
|
||||||
set -e
|
set -e
|
||||||
done
|
done
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
enable-script = pkgs.writeScriptBin "enable-containers" ''
|
||||||
|
touch /etc/start-containers
|
||||||
|
systemctl start lxc-containers.target
|
||||||
|
'';
|
||||||
|
|
||||||
|
disable-script = pkgs.writeScriptBin "disable-containers" ''
|
||||||
|
rm /etc/start-containers
|
||||||
|
systemctl stop lxc-containers.target lxc@\*.service
|
||||||
|
'';
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
boot.kernel.sysctl = lib.mkIf enabled {
|
boot.kernel.sysctl = lib.mkIf enabled {
|
||||||
|
@ -160,7 +170,12 @@ in
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
environment.systemPackages = [ lxc build-script ];
|
environment.systemPackages = [
|
||||||
|
# `lxc-attach` et al
|
||||||
|
lxc build-script
|
||||||
|
# User scripts
|
||||||
|
enable-script disable-script
|
||||||
|
];
|
||||||
|
|
||||||
# Create lxc.container.conf files
|
# Create lxc.container.conf files
|
||||||
environment.etc =
|
environment.etc =
|
||||||
|
@ -211,7 +226,10 @@ in
|
||||||
systemd.services."lxc@" = {
|
systemd.services."lxc@" = {
|
||||||
description = "LXC container '%i'";
|
description = "LXC container '%i'";
|
||||||
after = [ "network.target" ];
|
after = [ "network.target" ];
|
||||||
unitConfig.ConditionPathExists = "/var/lib/lxc/%i/rootfs/init";
|
unitConfig.ConditionPathExists = [
|
||||||
|
"/var/lib/lxc/%i/rootfs/init"
|
||||||
|
"/etc/start-containers"
|
||||||
|
];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "simple";
|
Type = "simple";
|
||||||
ExecStart = "${lxc}/bin/lxc-start -F -C -n %i";
|
ExecStart = "${lxc}/bin/lxc-start -F -C -n %i";
|
||||||
|
|
Loading…
Reference in New Issue
Block a user