systemd: convert gogoclient job to service unit

This commit is contained in:
Mathijs Kwik 2012-12-26 23:49:22 +01:00
parent f61f0c139b
commit 3456f3b232

View File

@ -56,22 +56,36 @@ in
config = mkIf cfg.enable { config = mkIf cfg.enable {
boot.kernelModules = [ "tun" ]; boot.kernelModules = [ "tun" ];
# environment.systemPackages = [pkgs.gogoclient];
networking.enableIPv6 = true; networking.enableIPv6 = true;
jobs.gogoclient = { boot.systemd.services.gogoclient = {
name = "gogoclient";
description = "ipv6 tunnel"; description = "ipv6 tunnel";
startOn = optionalString cfg.autorun "starting networking";
stopOn = "stopping network-interfaces"; after = [ "network.target" ];
preStart = ''
mkdir -p /var/lib/gogoc preStart = let authMethod = if cfg.password == "" then "anonymous" else "any"; in
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 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" ];
}; };
}; };