autorestart rclone sync jobs on failure
This commit is contained in:
parent
7fd04a7551
commit
d0583ddb89
|
@ -141,7 +141,6 @@ in {
|
||||||
{
|
{
|
||||||
source = "/home/misskey/misskey-files";
|
source = "/home/misskey/misskey-files";
|
||||||
dest = "Storage-Media-Crypt:";
|
dest = "Storage-Media-Crypt:";
|
||||||
serviceConfig = {};
|
|
||||||
timerConfig = {
|
timerConfig = {
|
||||||
OnStartupSec = "60";
|
OnStartupSec = "60";
|
||||||
OnCalendar = "4h";
|
OnCalendar = "4h";
|
||||||
|
|
|
@ -20,5 +20,6 @@
|
||||||
compressImage = false;
|
compressImage = false;
|
||||||
squashfsCompression = "zstd -Xcompression-level 1";
|
squashfsCompression = "zstd -Xcompression-level 1";
|
||||||
};
|
};
|
||||||
|
|
||||||
config.services.openssh.permitRootLogin = lib.mkForce "yes";
|
config.services.openssh.permitRootLogin = lib.mkForce "yes";
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,16 +19,13 @@
|
||||||
|
|
||||||
./secrets.nix
|
./secrets.nix
|
||||||
./profiles/wireguard.nix
|
./profiles/wireguard.nix
|
||||||
./profiles/harry-vpn.nix
|
|
||||||
./profiles/misskey-dev.nix
|
|
||||||
];
|
];
|
||||||
|
|
||||||
environment.systemPackages = with pkgs; [teamviewer];
|
|
||||||
|
|
||||||
home-manager.users.root = {
|
home-manager.users.root = {
|
||||||
imports = with tree; [home.base];
|
imports = with tree; [home.base];
|
||||||
home.stateVersion = "22.05";
|
home.stateVersion = "22.05";
|
||||||
};
|
};
|
||||||
|
|
||||||
home-manager.users.chaos = {
|
home-manager.users.chaos = {
|
||||||
imports = with tree; [
|
imports = with tree; [
|
||||||
home.base
|
home.base
|
||||||
|
|
|
@ -9,22 +9,26 @@ with lib; let
|
||||||
|
|
||||||
makeNameSafe = name: builtins.replaceStrings ["/" ":"] ["-" "-"] name;
|
makeNameSafe = name: builtins.replaceStrings ["/" ":"] ["-" "-"] name;
|
||||||
|
|
||||||
daemonService = sync_config:
|
daemonService = sync_config: {
|
||||||
lib.mkMerge [
|
serviceConfig = lib.mkMerge [
|
||||||
{
|
{
|
||||||
serviceConfig = {
|
Type = "oneshot";
|
||||||
Type = "oneshot";
|
|
||||||
|
|
||||||
User =
|
User =
|
||||||
if cfg.user != null
|
if cfg.user != null
|
||||||
then "${cfg.user}"
|
then "${cfg.user}"
|
||||||
else "root";
|
else "root";
|
||||||
|
|
||||||
ExecStart = "${pkgs.rclone}/bin/rclone sync ${sync_config.source} ${sync_config.dest} -P";
|
ExecStart = "${pkgs.rclone}/bin/rclone sync ${sync_config.source} ${sync_config.dest} -P";
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
(lib.mkIf sync_config.autoRestart {
|
||||||
|
TimeoutSec = 60;
|
||||||
|
Restart = "on-failure";
|
||||||
|
})
|
||||||
|
|
||||||
sync_config.serviceConfig
|
sync_config.serviceConfig
|
||||||
];
|
];
|
||||||
|
};
|
||||||
in {
|
in {
|
||||||
options = {
|
options = {
|
||||||
services.rclone-sync = {
|
services.rclone-sync = {
|
||||||
|
@ -43,9 +47,22 @@ in {
|
||||||
options = {
|
options = {
|
||||||
source = mkOption {type = types.str;};
|
source = mkOption {type = types.str;};
|
||||||
dest = mkOption {type = types.str;};
|
dest = mkOption {type = types.str;};
|
||||||
|
autoRestart = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = true;
|
||||||
|
};
|
||||||
|
|
||||||
timerConfig = mkOption {type = types.attrs;};
|
timerConfig = mkOption {
|
||||||
serviceConfig = mkOption {type = types.attrs;};
|
type = types.attrs;
|
||||||
|
default = {
|
||||||
|
OnStartupSec = "60";
|
||||||
|
OnCalendar = "4h";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
serviceConfig = mkOption {
|
||||||
|
type = types.attrs;
|
||||||
|
default = {};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
default = [];
|
default = [];
|
||||||
|
@ -55,6 +72,15 @@ in {
|
||||||
|
|
||||||
config = mkMerge [
|
config = mkMerge [
|
||||||
(mkIf (cfg.enable && cfg.sync_jobs != []) {
|
(mkIf (cfg.enable && cfg.sync_jobs != []) {
|
||||||
|
envionment.systemPackages = let
|
||||||
|
allServices = lib.concatStringsSep " " (map (job: "rclone-sync-${makeNameSafe job.source}-${makeNameSafe job.dest}"));
|
||||||
|
in [
|
||||||
|
(pkgs.writeShellScriptBin "rclone-sync-all" ''
|
||||||
|
systemctl stop ${allServices}
|
||||||
|
systemctl start --wait ${allServices}
|
||||||
|
'')
|
||||||
|
];
|
||||||
|
|
||||||
systemd.services = listToAttrs (map (job: {
|
systemd.services = listToAttrs (map (job: {
|
||||||
name = "rclone-sync-${makeNameSafe job.source}-${makeNameSafe job.dest}";
|
name = "rclone-sync-${makeNameSafe job.source}-${makeNameSafe job.dest}";
|
||||||
value = daemonService job;
|
value = daemonService job;
|
||||||
|
|
Loading…
Reference in a new issue