From 0f59901b57eb2ac9e3bb43b252415657b9a98277 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Fri, 12 Aug 2016 04:31:02 +0300 Subject: ejabberd service: move service to foreground --- nixos/modules/services/networking/ejabberd.nix | 29 +++++++++++--------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/nixos/modules/services/networking/ejabberd.nix b/nixos/modules/services/networking/ejabberd.nix index 8ecc16257db..82ed7fc4a83 100644 --- a/nixos/modules/services/networking/ejabberd.nix +++ b/nixos/modules/services/networking/ejabberd.nix @@ -111,10 +111,10 @@ in { description = "ejabberd server"; wantedBy = [ "multi-user.target" ]; after = [ "network.target" ]; - path = [ pkgs.findutils pkgs.coreutils ] ++ lib.optional cfg.imagemagick pkgs.imagemagick; + path = [ pkgs.findutils pkgs.coreutils pkgs.runit ] ++ lib.optional cfg.imagemagick pkgs.imagemagick; serviceConfig = { - Type = "forking"; + ExecStart = ''${ectl} foreground''; # FIXME: runit is used for `chpst` -- can we get rid of this? ExecStop = ''${pkgs.runit}/bin/chpst -u "${cfg.user}:${cfg.group}" ${ectl} stop''; ExecReload = ''${pkgs.runit}/bin/chpst -u "${cfg.user}:${cfg.group}" ${ectl} reload_config''; @@ -132,29 +132,24 @@ in { mkdir -p -m750 "${cfg.spoolDir}" chown -R "${cfg.user}:${cfg.group}" "${cfg.spoolDir}" - ''; - - script = '' - [ -z "$(ls -A '${cfg.spoolDir}')" ] && firstRun=1 - ${ectl} start + if [ -z "$(ls -A '${cfg.spoolDir}')" ]; then + touch "${cfg.spoolDir}/.firstRun" + fi + ''; - count=0 + postStart = '' while ! ${ectl} status >/dev/null 2>&1; do - if [ $count -eq 30 ]; then - echo "ejabberd server hasn't started in 30 seconds, giving up" - exit 1 - fi - - count=$((count++)) - sleep 1 + if ! kill -0 "$MAINPID"; then exit 1; fi + sleep 0.1 done - if [ -n "$firstRun" ]; then + if [ -e "${cfg.spoolDir}/.firstRun" ]; then + rm "${cfg.spoolDir}/.firstRun" for src in ${dumps}; do find "$src" -type f | while read dump; do echo "Loading configuration dump at $dump" - ${ectl} load "$dump" + chpst -u "${cfg.user}:${cfg.group}" ${ectl} load "$dump" done done fi -- cgit 1.4.1