systemd: convert samba jobs to systemd services (samba.target)

This commit is contained in:
Mathijs Kwik 2012-12-27 00:54:37 +01:00
parent 90fa68cf32
commit dc58c2ea37

View File

@ -26,18 +26,14 @@ let
mkdir -p /var/samba/locks /var/samba/cores/nmbd /var/samba/cores/smbd /var/samba/cores/winbindd mkdir -p /var/samba/locks /var/samba/cores/nmbd /var/samba/cores/smbd /var/samba/cores/winbindd
fi fi
passwdFile="$(sed -n 's/^.*smb[ ]\+passwd[ ]\+file[ ]\+=[ ]\+\(.*\)/\1/p' ${configFile})" passwdFile="$(${pkgs.gnused}/bin/sed -n 's/^.*smb[ ]\+passwd[ ]\+file[ ]\+=[ ]\+\(.*\)/\1/p' ${configFile})"
if [ -n "$passwdFile" ]; then if [ -n "$passwdFile" ]; then
echo 'INFO: creating directory containing passwd file' echo 'INFO: [samba] creating directory containing passwd file'
mkdir -p "$(dirname "$passwdFile")" mkdir -p "$(dirname "$passwdFile")"
fi fi
mkdir -p ${logDir} mkdir -p ${logDir}
mkdir -p ${privateDir} mkdir -p ${privateDir}
# The following line is to trigger a restart of the daemons when
# the configuration changes:
# ${configFile}
''; '';
configFile = pkgs.writeText "smb.conf" configFile = pkgs.writeText "smb.conf"
@ -60,12 +56,11 @@ let
# This may include nss_ldap, needed for samba if it has to use ldap. # This may include nss_ldap, needed for samba if it has to use ldap.
nssModulesPath = config.system.nssModules.path; nssModulesPath = config.system.nssModules.path;
daemonJob = appName: args: daemonService = appName: args:
{ name = "samba-${appName}"; { description = "Samba Service daemon ${appName}";
description = "Samba Service daemon ${appName}";
startOn = "started samba"; wantedBy = [ "samba.target" ];
stopOn = "stopping samba"; partOf = [ "samba.target" ];
environment = { environment = {
LD_LIBRARY_PATH = nssModulesPath; LD_LIBRARY_PATH = nssModulesPath;
@ -73,9 +68,12 @@ let
LOCALE_ARCHIVE = "/run/current-system/sw/lib/locale/locale-archive"; LOCALE_ARCHIVE = "/run/current-system/sw/lib/locale/locale-archive";
}; };
daemonType = "fork"; serviceConfig = {
ExecStart = "${samba}/sbin/${appName} ${args}";
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
};
exec = "${samba}/sbin/${appName} ${args}"; restartTriggers = [ configFile ];
}; };
in in
@ -202,22 +200,26 @@ in
}; };
# Dummy job to start the real Samba daemons (nmbd, smbd, winbindd). boot.systemd = {
jobs.sambaControl = targets.samba = {
{ name = "samba";
description = "Samba server"; description = "Samba server";
requires = [ "samba-setup.service" ];
startOn = "started network-interfaces"; after = [ "samba-setup.service" "network.target" ];
stopOn = "stopping network-interfaces"; wantedBy = [ "multi-user.target" ];
preStart = setupScript;
}; };
jobs.nmbd = daemonJob "nmbd" "-D"; services = {
"samba-nmbd" = daemonService "nmbd" "-F";
"samba-smbd" = daemonService "smbd" "-F";
"samba-winbindd" = daemonService "winbindd" "-F";
"samba-setup" = {
description = "Samba setup task";
script = setupScript;
unitConfig.RequiresMountsFor = "/home/smbd /var/samba /var/log/samba";
};
};
};
jobs.smbd = daemonJob "smbd" "-D";
jobs.winbindd = daemonJob "winbindd" "-D";
}) })
]; ];