[archive] Attempts to fix the archive mount being stopped before the system sleeps.
This commit is contained in:
@@ -2,18 +2,9 @@
|
|||||||
{
|
{
|
||||||
home.packages = with pkgs; [ sshfs ];
|
home.packages = with pkgs; [ sshfs ];
|
||||||
|
|
||||||
systemd.user.services.mcp-archive = {
|
systemd.user.services =
|
||||||
Unit = {
|
let
|
||||||
Description = "SSHFS mount for remote archive";
|
mountArchive = ''
|
||||||
After = [ "network-online.target" ];
|
|
||||||
Before = [ "sleep.target" ];
|
|
||||||
StopPropagatedFrom = [ "sleep.target" ];
|
|
||||||
};
|
|
||||||
|
|
||||||
Service = {
|
|
||||||
Type = "simple";
|
|
||||||
ExecStartPre = "/run/current-system/sw/bin/mkdir -p %h/archive";
|
|
||||||
ExecStart = ''
|
|
||||||
${pkgs.sshfs}/bin/sshfs \
|
${pkgs.sshfs}/bin/sshfs \
|
||||||
-f \
|
-f \
|
||||||
-o reconnect \
|
-o reconnect \
|
||||||
@@ -24,14 +15,62 @@
|
|||||||
drew@mcp:/tank/archive/drew \
|
drew@mcp:/tank/archive/drew \
|
||||||
%h/archive
|
%h/archive
|
||||||
'';
|
'';
|
||||||
ExecStop = "/run/wrappers/bin/fusermount -u %h/archive";
|
unmountArchive = "/run/wrappers/bin/fusermount -u %h/mnt/archive";
|
||||||
Restart = "on-failure";
|
in
|
||||||
RestartSec = "10s";
|
{
|
||||||
};
|
# Mounts the archive when the system is online.
|
||||||
|
mcp-archive = {
|
||||||
|
Unit = {
|
||||||
|
Description = "SSHFS mount for remote archive";
|
||||||
|
|
||||||
Install = {
|
# Start only after the network is online
|
||||||
WantedBy = [ "default.target" ];
|
After = [ "network-online.target" ];
|
||||||
|
|
||||||
|
# Stop this service if the network stops
|
||||||
|
StopPropagatedFrom = [ "network-online.target" ];
|
||||||
|
};
|
||||||
|
|
||||||
|
Service = {
|
||||||
|
Type = "simple";
|
||||||
|
ExecStartPre = "/run/current-system/sw/bin/mkdir -p %h/archive";
|
||||||
|
ExecStart = mountArchive;
|
||||||
|
ExecStop = unmountArchive;
|
||||||
|
|
||||||
|
Restart = "on-failure";
|
||||||
|
RestartSec = "10s";
|
||||||
|
};
|
||||||
|
|
||||||
|
Install = {
|
||||||
|
WantedBy = [ "default.target" ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
# Unmounts the SSHFS mount whenever the system wants to go to sleep. If I
|
||||||
|
# don't do this, the service will prevent sleep while it tries to
|
||||||
|
# reconnect.
|
||||||
|
mcp-archive-unmount-on-sleep = {
|
||||||
|
Unit = {
|
||||||
|
Description = "Unmount SSHFS archive before sleep";
|
||||||
|
|
||||||
|
# Run this before the system goes to sleep. It should then be
|
||||||
|
# shutdown after the system wakes up.
|
||||||
|
Before = [ "sleep.target" ];
|
||||||
|
StopWhenUnneeded = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
Service = {
|
||||||
|
Type = "oneshot";
|
||||||
|
# The service will remain after it runs so that it stays in the
|
||||||
|
# service registry as active.
|
||||||
|
RemainAfterExit = true;
|
||||||
|
ExecStart = unmountArchive;
|
||||||
|
ExecStop = mountArchive;
|
||||||
|
};
|
||||||
|
|
||||||
|
Install = {
|
||||||
|
WantedBy = [ "sleep.target" ];
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user