From 3456f3b2328eddee4e34c5807959bdd32efd70da Mon Sep 17 00:00:00 2001 From: Mathijs Kwik Date: Wed, 26 Dec 2012 23:49:22 +0100 Subject: [PATCH] systemd: convert gogoclient job to service unit --- modules/services/networking/gogoclient.nix | 38 +++++++++++++++------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/modules/services/networking/gogoclient.nix b/modules/services/networking/gogoclient.nix index 593f2436a39..519c45a385a 100644 --- a/modules/services/networking/gogoclient.nix +++ b/modules/services/networking/gogoclient.nix @@ -56,22 +56,36 @@ in config = mkIf cfg.enable { boot.kernelModules = [ "tun" ]; - # environment.systemPackages = [pkgs.gogoclient]; - networking.enableIPv6 = true; - jobs.gogoclient = { - name = "gogoclient"; + boot.systemd.services.gogoclient = { + description = "ipv6 tunnel"; - startOn = optionalString cfg.autorun "starting networking"; - stopOn = "stopping network-interfaces"; - preStart = '' - mkdir -p /var/lib/gogoc - chmod 700 /var/lib/gogoc - cat ${pkgs.gogoclient}/share/${pkgs.gogoclient.name}/gogoc.conf.sample | ${pkgs.gnused}/bin/sed -e "s|^userid=|&${cfg.username}|;s|^passwd=|&${if cfg.password == "" then "" else "$(cat ${cfg.password})"}|;s|^server=.*|server=${cfg.server}|;s|^auth_method=.*|auth_method=${if cfg.password == "" then "anonymous" else "any"}|;s|^#log_file=|log_file=1|" > /var/lib/gogoc/gogoc.conf + + after = [ "network.target" ]; + + preStart = let authMethod = if cfg.password == "" then "anonymous" else "any"; in + '' + mkdir -p -m 700 /var/lib/gogoc + cat ${pkgs.gogoclient}/share/${pkgs.gogoclient.name}/gogoc.conf.sample | \ + ${pkgs.gnused}/bin/sed \ + -e "s|^userid=|&${cfg.username}|" \ + -e "s|^passwd=|&${optionalString (cfg.password != "") "$(cat ${cfg.password})"}|" \ + -e "s|^server=.*|server=${cfg.server}|" \ + -e "s|^auth_method=.*|auth_method=${authMethod}|" \ + -e "s|^#log_file=|log_file=1|" > /var/lib/gogoc/gogoc.conf ''; - script = "cd /var/lib/gogoc; exec gogoc -y -f ./gogoc.conf"; - path = [pkgs.gogoclient]; + + serviceConfig.ExecStart = "${pkgs.gogoclient}/bin/gogoc -y -f /var/lib/gogoc/gogoc.conf"; + + restartTriggers = attrValues cfg; + + } // optionalAttrs cfg.autorun { + + wantedBy = [ "ip-up.target" ]; + + partOf = [ "ip-up.target" ]; + }; };