ejabberd service: move service to foreground

This commit is contained in:
Nikolay Amiantov 2016-08-12 04:31:02 +03:00
parent 5524d29f1b
commit 0f59901b57

View File

@ -111,10 +111,10 @@ in {
description = "ejabberd server"; description = "ejabberd server";
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
after = [ "network.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 = { serviceConfig = {
Type = "forking"; ExecStart = ''${ectl} foreground'';
# FIXME: runit is used for `chpst` -- can we get rid of this? # FIXME: runit is used for `chpst` -- can we get rid of this?
ExecStop = ''${pkgs.runit}/bin/chpst -u "${cfg.user}:${cfg.group}" ${ectl} stop''; 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''; ExecReload = ''${pkgs.runit}/bin/chpst -u "${cfg.user}:${cfg.group}" ${ectl} reload_config'';
@ -132,29 +132,24 @@ in {
mkdir -p -m750 "${cfg.spoolDir}" mkdir -p -m750 "${cfg.spoolDir}"
chown -R "${cfg.user}:${cfg.group}" "${cfg.spoolDir}" chown -R "${cfg.user}:${cfg.group}" "${cfg.spoolDir}"
if [ -z "$(ls -A '${cfg.spoolDir}')" ]; then
touch "${cfg.spoolDir}/.firstRun"
fi
''; '';
script = '' postStart = ''
[ -z "$(ls -A '${cfg.spoolDir}')" ] && firstRun=1
${ectl} start
count=0
while ! ${ectl} status >/dev/null 2>&1; do while ! ${ectl} status >/dev/null 2>&1; do
if [ $count -eq 30 ]; then if ! kill -0 "$MAINPID"; then exit 1; fi
echo "ejabberd server hasn't started in 30 seconds, giving up" sleep 0.1
exit 1
fi
count=$((count++))
sleep 1
done done
if [ -n "$firstRun" ]; then if [ -e "${cfg.spoolDir}/.firstRun" ]; then
rm "${cfg.spoolDir}/.firstRun"
for src in ${dumps}; do for src in ${dumps}; do
find "$src" -type f | while read dump; do find "$src" -type f | while read dump; do
echo "Loading configuration dump at $dump" echo "Loading configuration dump at $dump"
${ectl} load "$dump" chpst -u "${cfg.user}:${cfg.group}" ${ectl} load "$dump"
done done
done done
fi fi