From 56bdce1441b5b273480adf3a1b63a044f8871f1f Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Wed, 4 Apr 2018 21:14:21 +0200 Subject: 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. --- machines/profpatsch/katara.nix | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'machines/profpatsch/katara.nix') 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" ]; }; }) -- cgit 1.4.1