about summary refs log tree commit diff
path: root/machines/profpatsch
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2018-04-04 21:14:21 +0200
committerProfpatsch <mail@profpatsch.de>2018-05-01 21:28:02 +0200
commit56bdce1441b5b273480adf3a1b63a044f8871f1f (patch)
treeb9be269e4d4caa3e7d80afb1562a0b2f96c38f5f /machines/profpatsch
parent94f989ec0e94beb9668581ddc08d67af6f667484 (diff)
machines/katara: weechat notification script user service
weechat is running on my server with a script enabled that pushes notifications
to a unix socket. This user service opens an ssh connection and forwards the
socket to a local script, which pushes to libnotify when a message arrives.
Diffstat (limited to 'machines/profpatsch')
-rw-r--r--machines/profpatsch/katara.nix27
1 files changed, 21 insertions, 6 deletions
diff --git a/machines/profpatsch/katara.nix b/machines/profpatsch/katara.nix
index 4b1cf4e3..9a1fe88d 100644
--- a/machines/profpatsch/katara.nix
+++ b/machines/profpatsch/katara.nix
@@ -372,6 +372,7 @@ in {
         timers.unlock-password-store = {
           description = "unlock password store on system start";
           wantedBy = [ "timers.target" ];
+          # run ~five seconds after user logs in
           timerConfig.OnStartupSec = "5s";
         };
        })
@@ -424,29 +425,43 @@ in {
         services.pyrnotify-ssh-connection = {
           description = "ssh connection to make pyrnotify work";
           serviceConfig = {
+            # TODO: get out of the gpg-agent service directly
             Environment = ''"SSH_AUTH_SOCK=%t/gnupg/S.gpg-agent.ssh"'';
-            # forwards the remote socket over ssh, restarts every 5 minutes
             ExecStart = pkgs.writeScript "pyrnotify-start-ssh" ''
               #!${pkgs.stdenv.shell}
+              set -e
+              # first delete the socket file if it exists
+              # otherwise the forward doesn’t work
               ${lib.getBin pkgs.openssh}/bin/ssh \
                 bigmac \
                 "rm /home/bigmac/.weechat/pyrnotify.socket"
+              # forwards the remote socket over ssh
+              # thE options make it disconnect after 45 sec
+              # by sending a keepalive packet every 15 seconds
+              # and retrying 3 times
               ${lib.getBin pkgs.openssh}/bin/ssh \
+                -o ServerAliveInterval=15 \
+                -o ServerAliveCountMax=3 \
+                -o ExitOnForwardFailure=yes \
                 -R /home/bigmac/.weechat/pyrnotify.socket:localhost:8099 \
-                bigmac \
-                "sleep 300"
+                -N \
+                bigmac
             '';
-            Restart = "on-failure";
           };
+          requires = [ "gpg-agent.service" ];
+          after = [ "gpg-agent.service" ];
         };
         services.pyrnotify-listen = rec {
           description = "get notified about weechat messages";
           serviceConfig = {
             ExecStart = "${lib.getBin pkgs.python
               }/bin/python ${myPkgs.pyrnotify} 8099";
+            Restart = "on-failure";
+            RestartSec = "5s";
           };
-          requires = [ "pyrnotify-ssh-connection.service" ];
-          after = requires;
+          bindsTo = [ "pyrnotify-ssh-connection.service" ];
+          after = [ "pyrnotify-ssh-connection.service" ];
+          wantedBy = [ "default.target" ];
         };
       })