nixos/ejabberd: update service
This commit is contained in:
parent
757857613a
commit
d0510febe1
@ -240,6 +240,7 @@
|
|||||||
pumpio = 216;
|
pumpio = 216;
|
||||||
nm-openvpn = 217;
|
nm-openvpn = 217;
|
||||||
mathics = 218;
|
mathics = 218;
|
||||||
|
ejabberd = 219;
|
||||||
|
|
||||||
# When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
|
# When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
|
||||||
|
|
||||||
@ -457,6 +458,7 @@
|
|||||||
pumpio = 216;
|
pumpio = 216;
|
||||||
nm-openvpn = 217;
|
nm-openvpn = 217;
|
||||||
mathics = 218;
|
mathics = 218;
|
||||||
|
ejabberd = 219;
|
||||||
|
|
||||||
# When adding a gid, make sure it doesn't match an existing
|
# When adding a gid, make sure it doesn't match an existing
|
||||||
# uid. Users and groups with the same name should have equal
|
# uid. Users and groups with the same name should have equal
|
||||||
|
@ -6,9 +6,16 @@ let
|
|||||||
|
|
||||||
cfg = config.services.ejabberd;
|
cfg = config.services.ejabberd;
|
||||||
|
|
||||||
in
|
ctlcfg = pkgs.writeText "ejabberdctl.cfg" ''
|
||||||
|
ERL_EPMD_ADDRESS=127.0.0.1
|
||||||
|
${cfg.ctlConfig}
|
||||||
|
'';
|
||||||
|
|
||||||
{
|
ectl = ''${cfg.package}/bin/ejabberdctl --config "${cfg.configFile}" --ctl-config "${ctlcfg}" --spool "${cfg.spoolDir}" --logs "${cfg.logsDir}"'';
|
||||||
|
|
||||||
|
dumps = lib.concatMapStringsSep " " lib.escapeShellArg cfg.loadDumps;
|
||||||
|
|
||||||
|
in {
|
||||||
|
|
||||||
###### interface
|
###### interface
|
||||||
|
|
||||||
@ -17,33 +24,56 @@ in
|
|||||||
services.ejabberd = {
|
services.ejabberd = {
|
||||||
|
|
||||||
enable = mkOption {
|
enable = mkOption {
|
||||||
|
type = types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
description = "Whether to enable ejabberd server";
|
description = "Whether to enable ejabberd server";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
package = mkOption {
|
||||||
|
type = types.package;
|
||||||
|
default = pkgs.ejabberd;
|
||||||
|
description = "ejabberd server package to use";
|
||||||
|
};
|
||||||
|
|
||||||
|
user = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "ejabberd";
|
||||||
|
description = "User under which ejabberd is ran";
|
||||||
|
};
|
||||||
|
|
||||||
|
group = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "ejabberd";
|
||||||
|
description = "Group under which ejabberd is ran";
|
||||||
|
};
|
||||||
|
|
||||||
spoolDir = mkOption {
|
spoolDir = mkOption {
|
||||||
|
type = types.path;
|
||||||
default = "/var/lib/ejabberd";
|
default = "/var/lib/ejabberd";
|
||||||
description = "Location of the spooldir of ejabberd";
|
description = "Location of the spooldir of ejabberd";
|
||||||
};
|
};
|
||||||
|
|
||||||
logsDir = mkOption {
|
logsDir = mkOption {
|
||||||
|
type = types.path;
|
||||||
default = "/var/log/ejabberd";
|
default = "/var/log/ejabberd";
|
||||||
description = "Location of the logfile directory of ejabberd";
|
description = "Location of the logfile directory of ejabberd";
|
||||||
};
|
};
|
||||||
|
|
||||||
confDir = mkOption {
|
configFile = mkOption {
|
||||||
default = "/var/ejabberd";
|
type = types.path;
|
||||||
description = "Location of the config directory of ejabberd";
|
description = "Configuration file for ejabberd in YAML format";
|
||||||
};
|
};
|
||||||
|
|
||||||
virtualHosts = mkOption {
|
ctlConfig = mkOption {
|
||||||
default = "\"localhost\"";
|
type = types.lines;
|
||||||
description = "Virtualhosts that ejabberd should host. Hostnames are surrounded with doublequotes and separated by commas";
|
default = "";
|
||||||
|
description = "Configuration of ejabberdctl";
|
||||||
};
|
};
|
||||||
|
|
||||||
loadDumps = mkOption {
|
loadDumps = mkOption {
|
||||||
|
type = types.listOf types.path;
|
||||||
default = [];
|
default = [];
|
||||||
description = "Configuration dump that should be loaded on the first startup";
|
description = "Configuration dumps that should be loaded on the first startup";
|
||||||
example = literalExample "[ ./myejabberd.dump ]";
|
example = literalExample "[ ./myejabberd.dump ]";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -54,73 +84,72 @@ in
|
|||||||
###### implementation
|
###### implementation
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
environment.systemPackages = [ pkgs.ejabberd ];
|
environment.systemPackages = [ cfg.package ];
|
||||||
|
|
||||||
|
users.extraUsers = optionalAttrs (cfg.user == "ejabberd") (singleton
|
||||||
|
{ name = "ejabberd";
|
||||||
|
group = cfg.group;
|
||||||
|
home = cfg.spoolDir;
|
||||||
|
createHome = true;
|
||||||
|
uid = config.ids.uids.ejabberd;
|
||||||
|
});
|
||||||
|
|
||||||
|
users.extraGroups = optionalAttrs (cfg.group == "ejabberd") (singleton
|
||||||
|
{ name = "ejabberd";
|
||||||
|
gid = config.ids.gids.ejabberd;
|
||||||
|
});
|
||||||
|
|
||||||
systemd.services.ejabberd = {
|
systemd.services.ejabberd = {
|
||||||
description = "EJabberd server";
|
description = "ejabberd server";
|
||||||
after = [ "network-interfaces.target" ];
|
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
path = with pkgs; [ ejabberd coreutils bash gnused ];
|
after = [ "network.target" ];
|
||||||
|
path = [ pkgs.findutils pkgs.coreutils ];
|
||||||
|
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "forking";
|
||||||
|
# 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'';
|
||||||
|
User = cfg.user;
|
||||||
|
Group = cfg.group;
|
||||||
|
PermissionsStartOnly = true;
|
||||||
|
};
|
||||||
|
|
||||||
preStart = ''
|
preStart = ''
|
||||||
# Initialise state data
|
mkdir -p -m750 "${cfg.logsDir}"
|
||||||
mkdir -p ${cfg.logsDir}
|
chown "${cfg.user}:${cfg.group}" "${cfg.logsDir}"
|
||||||
|
|
||||||
if ! test -d ${cfg.spoolDir}
|
mkdir -p -m750 "/var/lock/ejabberdctl"
|
||||||
then
|
chown "${cfg.user}:${cfg.group}" "/var/lock/ejabberdctl"
|
||||||
initialize=1
|
|
||||||
cp -av ${pkgs.ejabberd}/var/lib/ejabberd /var/lib
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! test -d ${cfg.confDir}
|
mkdir -p -m750 "${cfg.spoolDir}"
|
||||||
then
|
chown -R "${cfg.user}:${cfg.group}" "${cfg.spoolDir}"
|
||||||
mkdir -p ${cfg.confDir}
|
|
||||||
cp ${pkgs.ejabberd}/etc/ejabberd/* ${cfg.confDir}
|
|
||||||
sed -e 's|{hosts, \["localhost"\]}.|{hosts, \[${cfg.virtualHosts}\]}.|' ${pkgs.ejabberd}/etc/ejabberd/ejabberd.cfg > ${cfg.confDir}/ejabberd.cfg
|
|
||||||
fi
|
|
||||||
|
|
||||||
ejabberdctl --config-dir ${cfg.confDir} --logs ${cfg.logsDir} --spool ${cfg.spoolDir} start
|
|
||||||
|
|
||||||
${if cfg.loadDumps == [] then "" else
|
|
||||||
''
|
|
||||||
if [ "$initialize" = "1" ]
|
|
||||||
then
|
|
||||||
# Wait until the ejabberd server is available for use
|
|
||||||
count=0
|
|
||||||
while ! ejabberdctl --config-dir ${cfg.confDir} --logs ${cfg.logsDir} --spool ${cfg.spoolDir} status
|
|
||||||
do
|
|
||||||
if [ $count -eq 30 ]
|
|
||||||
then
|
|
||||||
echo "Tried 30 times, giving up..."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Ejabberd daemon not yet started. Waiting for 1 second..."
|
|
||||||
count=$((count++))
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
|
|
||||||
${concatMapStrings (dump:
|
|
||||||
''
|
|
||||||
echo "Importing dump: ${dump}"
|
|
||||||
|
|
||||||
if [ -f ${dump} ]
|
|
||||||
then
|
|
||||||
ejabberdctl --config-dir ${cfg.confDir} --logs ${cfg.logsDir} --spool ${cfg.spoolDir} load ${dump}
|
|
||||||
elif [ -d ${dump} ]
|
|
||||||
then
|
|
||||||
for i in ${dump}/ejabberd-dump/*
|
|
||||||
do
|
|
||||||
ejabberdctl --config-dir ${cfg.confDir} --logs ${cfg.logsDir} --spool ${cfg.spoolDir} load $i
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
'') cfg.loadDumps}
|
|
||||||
fi
|
|
||||||
''}
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
postStop = ''
|
script = ''
|
||||||
ejabberdctl --config-dir ${cfg.confDir} --logs ${cfg.logsDir} --spool ${cfg.spoolDir} stop
|
[ -z "$(ls -A '${cfg.spoolDir}')" ] && firstRun=1
|
||||||
|
|
||||||
|
${ectl} start
|
||||||
|
|
||||||
|
count=0
|
||||||
|
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
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -n "$firstRun" ]; then
|
||||||
|
for src in ${dumps}; do
|
||||||
|
find "$src" -type f | while read dump; do
|
||||||
|
echo "Loading configuration dump at $dump"
|
||||||
|
${ectl} load "$dump"
|
||||||
|
done
|
||||||
|
done
|
||||||
|
fi
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user