mirror of
https://github.com/oqyude/nixos.git
synced 2026-08-09 08:03:16 +03:00
Compare commits
1
Commits
dev
...
2527c2cfd3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2527c2cfd3 |
@@ -98,11 +98,12 @@
|
|||||||
# Folders
|
# Folders
|
||||||
tmpfiles.rules = [
|
tmpfiles.rules = [
|
||||||
"d /mnt 0755 root root -"
|
"d /mnt 0755 root root -"
|
||||||
"d /mnt/containers 0755 root root -"
|
"d /mnt/services 0755 root root -"
|
||||||
"d /mnt/services/containers 0755 root root -"
|
"d /mnt/services/containers 0755 root root -"
|
||||||
"d /mnt/services/containers/3x-ui 0755 root root -"
|
"d /mnt/services/containers/3x-ui 0755 root root -"
|
||||||
"d /mnt/services/containers/3x-ui/cert 0755 root root -"
|
"d /mnt/services/containers/3x-ui/cert 0755 root root -"
|
||||||
"d /mnt/services/containers/3x-ui/db 0755 root root -"
|
"d /mnt/services/containers/3x-ui/db 0755 root root -"
|
||||||
|
"Z /mnt/services/containers/3x-ui 0755 root root -"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -92,7 +92,7 @@
|
|||||||
ssh_key_public_root = {
|
ssh_key_public_root = {
|
||||||
format = "yaml";
|
format = "yaml";
|
||||||
key = "ssh_key_public";
|
key = "ssh_key_public";
|
||||||
path = "/root/.ssh/id_ed25519";
|
path = "/root/.ssh/id_ed25519.pub";
|
||||||
owner = "root";
|
owner = "root";
|
||||||
group = "root";
|
group = "root";
|
||||||
mode = "0655";
|
mode = "0655";
|
||||||
|
|||||||
@@ -7,8 +7,14 @@
|
|||||||
../containers/3x-ui.nix
|
../containers/3x-ui.nix
|
||||||
./nginx.nix
|
./nginx.nix
|
||||||
./samba.nix
|
./samba.nix
|
||||||
|
./systemd.nix
|
||||||
# ./glances.nix
|
# ./glances.nix
|
||||||
# ./netbird.nix
|
# ./netbird.nix
|
||||||
# ./xray.nix
|
# ./xray.nix
|
||||||
];
|
];
|
||||||
|
systemd.tmpfiles.rules = [
|
||||||
|
"d /mnt 0755 root root -"
|
||||||
|
"d /mnt/services 0755 root root -"
|
||||||
|
"d /mnt/services/containers 0755 root root -"
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
xlib,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
serviceName = "rsync-services-sync";
|
||||||
|
serverAddress = "oqyude@100.64.0.0";
|
||||||
|
serverDir = "/mnt/services/nodes/vds";
|
||||||
|
nodeDir = "/mnt/services";
|
||||||
|
in
|
||||||
|
{
|
||||||
|
systemd = {
|
||||||
|
services = {
|
||||||
|
"${serviceName}" = {
|
||||||
|
description = "Bidirectional rsync";
|
||||||
|
unitConfig.RequiresMountsFor = [ ];
|
||||||
|
after = [ "network-online.target" ];
|
||||||
|
wants = [ "network-online.target" ];
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
script = ''
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
RSYNC="${pkgs.rsync}/bin/rsync"
|
||||||
|
SSH="${pkgs.openssh}/bin/ssh"
|
||||||
|
|
||||||
|
SSH_CMD="$SSH \
|
||||||
|
-o BatchMode=yes \
|
||||||
|
-o ConnectTimeout=5 \
|
||||||
|
-o StrictHostKeyChecking=no"
|
||||||
|
|
||||||
|
echo "Waiting for server..."
|
||||||
|
|
||||||
|
for i in $(seq 1 60); do
|
||||||
|
echo "Attempt $i"
|
||||||
|
|
||||||
|
if $SSH_CMD ${serverAddress} true >/dev/null 2>&1; then
|
||||||
|
echo "Server available"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
|
|
||||||
|
# final check
|
||||||
|
$SSH_CMD ${serverAddress} true >/dev/null 2>&1
|
||||||
|
|
||||||
|
mkdir -p "${nodeDir}"
|
||||||
|
|
||||||
|
if [ ! -d "${nodeDir}" ] || [ -z "$(ls -A "${nodeDir}")" ]; then
|
||||||
|
echo "Pull <- ${serverAddress}"
|
||||||
|
|
||||||
|
mkdir -p "${nodeDir}"
|
||||||
|
|
||||||
|
$RSYNC \
|
||||||
|
-e "$SSH_CMD" \
|
||||||
|
-a \
|
||||||
|
"${serverAddress}:${serverDir}/" \
|
||||||
|
"${nodeDir}/"
|
||||||
|
else
|
||||||
|
echo "Push -> ${serverAddress}"
|
||||||
|
|
||||||
|
$RSYNC \
|
||||||
|
-e "$SSH_CMD" \
|
||||||
|
-a \
|
||||||
|
--delete \
|
||||||
|
"${nodeDir}/" \
|
||||||
|
"${serverAddress}:${serverDir}/"
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
User = "root";
|
||||||
|
Group = "root";
|
||||||
|
Nice = 10;
|
||||||
|
CPUQuota = "5%";
|
||||||
|
IOSchedulingClass = "idle";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
timers = {
|
||||||
|
"${serviceName}" = {
|
||||||
|
wantedBy = [ "timers.target" ];
|
||||||
|
timerConfig = {
|
||||||
|
OnCalendar = "daily";
|
||||||
|
Persistent = true;
|
||||||
|
Unit = "${serviceName}.service";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user