Skip to content

Commit

Permalink
use wantedBy for root service deps
Browse files Browse the repository at this point in the history
  • Loading branch information
aksiksi committed Nov 15, 2023
1 parent 4e4c4c4 commit b1801e8
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 71 deletions.
2 changes: 2 additions & 0 deletions templates/container.nix.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ systemd.services."{{.Runtime}}-{{.Name}}" = {
startLimitIntervalSec = {{derefInt .SystemdConfig.StartLimitIntervalSec}};
{{- end}}
{{- if rootTarget}}
{{- /* PartOf for stop/restart of root, WantedBy for start of root. */}}
partOf = [ "{{rootTarget}}.target" ];
wantedBy = [ "{{rootTarget}}.target" ];
{{- end}}
};
5 changes: 0 additions & 5 deletions templates/main.nix.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@
unitConfig = {
Description = "Root target generated by compose2nix.";
};
wants = [
{{- range $units}}
"{{.}}"
{{- end}}
];
{{- if .AutoStart}}
wantedBy = [ "multi-user.target" ];
{{- end}}
Expand Down
2 changes: 2 additions & 0 deletions templates/network.nix.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ systemd.services."{{.Runtime}}-network-{{.Name}}" = {
];
{{- end}}
{{- if rootTarget}}
{{- /* PartOf for stop/restart of root, WantedBy for start of root. */}}
partOf = [ "{{rootTarget}}.target" ];
wantedBy = [ "{{rootTarget}}.target" ];
{{- end}}
};
2 changes: 2 additions & 0 deletions templates/volume.nix.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ systemd.services."{{.Runtime}}-volume-{{.Name}}" = {
];
{{- end}}
{{- if rootTarget}}
{{- /* PartOf for stop/restart of root, WantedBy for start of root. */}}
partOf = [ "{{rootTarget}}.target" ];
wantedBy = [ "{{rootTarget}}.target" ];
{{- end}}
};
22 changes: 10 additions & 12 deletions testdata/TestDocker_RemoveVolumes_out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
startLimitBurst = 3;
startLimitIntervalSec = 120;
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};
virtualisation.oci-containers.containers."myproject-sabnzbd" = {
image = "lscr.io/linuxserver/sabnzbd";
Expand Down Expand Up @@ -89,6 +90,7 @@
Description = "This is the sabnzbd container!";
};
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};
virtualisation.oci-containers.containers."photoprism-mariadb" = {
image = "docker.io/library/mariadb:10.9";
Expand Down Expand Up @@ -123,6 +125,7 @@
startLimitBurst = 10;
startLimitIntervalSec = 86400;
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};
virtualisation.oci-containers.containers."torrent-client" = {
image = "docker.io/haugene/transmission-openvpn";
Expand Down Expand Up @@ -183,6 +186,7 @@
startLimitBurst = 3;
startLimitIntervalSec = 86400;
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};
virtualisation.oci-containers.containers."traefik" = {
image = "docker.io/library/traefik";
Expand Down Expand Up @@ -227,6 +231,7 @@
AllowIsolate = true;
};
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};

# Networks
Expand All @@ -247,6 +252,7 @@
"docker-myproject-sabnzbd.service"
];
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};
systemd.services."docker-network-myproject-something" = {
path = [ pkgs.docker ];
Expand All @@ -265,6 +271,7 @@
"docker-torrent-client.service"
];
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};

# Volumes
Expand All @@ -285,6 +292,7 @@
"docker-jellyseerr.service"
];
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};
systemd.services."docker-volume-photos" = {
path = [ pkgs.docker ];
Expand All @@ -303,6 +311,7 @@
"docker-photoprism-mariadb.service"
];
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};
systemd.services."docker-volume-storage" = {
path = [ pkgs.docker ];
Expand All @@ -323,6 +332,7 @@
"docker-torrent-client.service"
];
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};

# Root service
Expand All @@ -332,17 +342,5 @@
unitConfig = {
Description = "Root target generated by compose2nix.";
};
wants = [
"docker-jellyseerr.service"
"docker-myproject-sabnzbd.service"
"docker-photoprism-mariadb.service"
"docker-torrent-client.service"
"docker-traefik.service"
"docker-network-myproject-default.service"
"docker-network-myproject-something.service"
"docker-volume-books.service"
"docker-volume-photos.service"
"docker-volume-storage.service"
];
};
}
22 changes: 10 additions & 12 deletions testdata/TestDocker_SystemdMount_out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
startLimitBurst = 3;
startLimitIntervalSec = 120;
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};
virtualisation.oci-containers.containers."myproject-sabnzbd" = {
image = "lscr.io/linuxserver/sabnzbd";
Expand Down Expand Up @@ -101,6 +102,7 @@
"mnt-media.mount"
];
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};
virtualisation.oci-containers.containers."photoprism-mariadb" = {
image = "docker.io/library/mariadb:10.9";
Expand Down Expand Up @@ -141,6 +143,7 @@
startLimitBurst = 10;
startLimitIntervalSec = 86400;
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};
virtualisation.oci-containers.containers."torrent-client" = {
image = "docker.io/haugene/transmission-openvpn";
Expand Down Expand Up @@ -207,6 +210,7 @@
startLimitBurst = 3;
startLimitIntervalSec = 86400;
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};
virtualisation.oci-containers.containers."traefik" = {
image = "docker.io/library/traefik";
Expand Down Expand Up @@ -251,6 +255,7 @@
AllowIsolate = true;
};
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};

# Networks
Expand All @@ -271,6 +276,7 @@
"docker-myproject-sabnzbd.service"
];
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};
systemd.services."docker-network-myproject-something" = {
path = [ pkgs.docker ];
Expand All @@ -289,6 +295,7 @@
"docker-torrent-client.service"
];
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};

# Volumes
Expand All @@ -308,6 +315,7 @@
"docker-jellyseerr.service"
];
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};
systemd.services."docker-volume-photos" = {
path = [ pkgs.docker ];
Expand All @@ -325,6 +333,7 @@
"docker-photoprism-mariadb.service"
];
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};
systemd.services."docker-volume-storage" = {
path = [ pkgs.docker ];
Expand All @@ -344,6 +353,7 @@
"docker-torrent-client.service"
];
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};

# Root service
Expand All @@ -353,17 +363,5 @@
unitConfig = {
Description = "Root target generated by compose2nix.";
};
wants = [
"docker-jellyseerr.service"
"docker-myproject-sabnzbd.service"
"docker-photoprism-mariadb.service"
"docker-torrent-client.service"
"docker-traefik.service"
"docker-network-myproject-default.service"
"docker-network-myproject-something.service"
"docker-volume-books.service"
"docker-volume-photos.service"
"docker-volume-storage.service"
];
};
}
22 changes: 10 additions & 12 deletions testdata/TestDocker_WithProject_out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
startLimitBurst = 3;
startLimitIntervalSec = 120;
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};
virtualisation.oci-containers.containers."myproject-sabnzbd" = {
image = "lscr.io/linuxserver/sabnzbd";
Expand Down Expand Up @@ -89,6 +90,7 @@
Description = "This is the sabnzbd container!";
};
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};
virtualisation.oci-containers.containers."photoprism-mariadb" = {
image = "docker.io/library/mariadb:10.9";
Expand Down Expand Up @@ -123,6 +125,7 @@
startLimitBurst = 10;
startLimitIntervalSec = 86400;
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};
virtualisation.oci-containers.containers."torrent-client" = {
image = "docker.io/haugene/transmission-openvpn";
Expand Down Expand Up @@ -183,6 +186,7 @@
startLimitBurst = 3;
startLimitIntervalSec = 86400;
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};
virtualisation.oci-containers.containers."traefik" = {
image = "docker.io/library/traefik";
Expand Down Expand Up @@ -227,6 +231,7 @@
AllowIsolate = true;
};
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};

# Networks
Expand All @@ -247,6 +252,7 @@
"docker-myproject-sabnzbd.service"
];
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};
systemd.services."docker-network-myproject-something" = {
path = [ pkgs.docker ];
Expand All @@ -265,6 +271,7 @@
"docker-torrent-client.service"
];
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};

# Volumes
Expand All @@ -284,6 +291,7 @@
"docker-jellyseerr.service"
];
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};
systemd.services."docker-volume-photos" = {
path = [ pkgs.docker ];
Expand All @@ -301,6 +309,7 @@
"docker-photoprism-mariadb.service"
];
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};
systemd.services."docker-volume-storage" = {
path = [ pkgs.docker ];
Expand All @@ -320,6 +329,7 @@
"docker-torrent-client.service"
];
partOf = [ "docker-compose-myproject-root.target" ];
wantedBy = [ "docker-compose-myproject-root.target" ];
};

# Root service
Expand All @@ -329,17 +339,5 @@
unitConfig = {
Description = "Root target generated by compose2nix.";
};
wants = [
"docker-jellyseerr.service"
"docker-myproject-sabnzbd.service"
"docker-photoprism-mariadb.service"
"docker-torrent-client.service"
"docker-traefik.service"
"docker-network-myproject-default.service"
"docker-network-myproject-something.service"
"docker-volume-books.service"
"docker-volume-photos.service"
"docker-volume-storage.service"
];
};
}
Loading

0 comments on commit b1801e8

Please sign in to comment.