2009-10-12 18:36:19 +02:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
2009-03-06 13:26:29 +01:00
|
|
|
|
|
|
|
let
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
cfg = config.services.ejabberd;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2009-03-06 13:26:29 +01:00
|
|
|
|
|
|
|
options = {
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
services.ejabberd = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable ejabberd server";
|
|
|
|
};
|
|
|
|
|
|
|
|
spoolDir = mkOption {
|
|
|
|
default = "/var/lib/ejabberd";
|
|
|
|
description = "Location of the spooldir of ejabberd";
|
|
|
|
};
|
|
|
|
|
|
|
|
logsDir = mkOption {
|
|
|
|
default = "/var/log/ejabberd";
|
|
|
|
description = "Location of the logfile directory of ejabberd";
|
|
|
|
};
|
|
|
|
|
|
|
|
confDir = mkOption {
|
|
|
|
default = "/var/ejabberd";
|
|
|
|
description = "Location of the config directory of ejabberd";
|
2009-03-06 13:26:29 +01:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
virtualHosts = mkOption {
|
|
|
|
default = "\"localhost\"";
|
|
|
|
description = "Virtualhosts that ejabberd should host. Hostnames are surrounded with doublequotes and separated by commas";
|
|
|
|
};
|
|
|
|
|
2009-11-19 16:12:05 +01:00
|
|
|
loadDumps = mkOption {
|
|
|
|
default = [];
|
|
|
|
description = "Configuration dump that should be loaded on the first startup";
|
|
|
|
example = [ ./myejabberd.dump ];
|
|
|
|
};
|
2009-03-06 13:26:29 +01:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2009-03-06 13:26:29 +01:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2009-03-06 13:26:29 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
###### implementation
|
2008-02-04 14:40:01 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
config = mkIf cfg.enable {
|
2009-11-02 13:13:09 +01:00
|
|
|
environment.systemPackages = [ pkgs.ejabberd ];
|
2008-02-04 14:40:01 +01:00
|
|
|
|
2009-10-12 20:09:34 +02:00
|
|
|
jobs.ejabberd =
|
2009-10-12 18:36:19 +02:00
|
|
|
{ description = "EJabberd server";
|
2008-02-04 14:40:01 +01:00
|
|
|
|
2009-11-23 14:29:47 +01:00
|
|
|
startOn = "started network-interfaces";
|
2009-11-06 23:19:17 +01:00
|
|
|
stopOn = "stopping network-interfaces";
|
2009-11-19 14:15:15 +01:00
|
|
|
|
|
|
|
environment = {
|
|
|
|
PATH = "$PATH:${pkgs.ejabberd}/sbin:${pkgs.ejabberd}/bin:${pkgs.coreutils}/bin:${pkgs.bash}/bin:${pkgs.gnused}/bin";
|
|
|
|
};
|
2009-03-06 13:26:29 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
# Initialise state data
|
|
|
|
mkdir -p ${cfg.logsDir}
|
|
|
|
|
|
|
|
if ! test -d ${cfg.spoolDir}
|
|
|
|
then
|
2009-11-19 16:12:05 +01:00
|
|
|
initialize=1
|
2009-10-12 18:36:19 +02:00
|
|
|
cp -av ${pkgs.ejabberd}/var/lib/ejabberd /var/lib
|
|
|
|
fi
|
2009-11-02 13:13:09 +01:00
|
|
|
|
|
|
|
if ! test -d ${cfg.confDir}
|
|
|
|
then
|
|
|
|
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
|
2009-11-19 14:15:15 +01:00
|
|
|
|
|
|
|
ejabberdctl --config-dir ${cfg.confDir} --logs ${cfg.logsDir} --spool ${cfg.spoolDir} start
|
2009-11-19 16:12:05 +01:00
|
|
|
|
|
|
|
${if cfg.loadDumps == [] then "" else
|
2009-11-19 16:17:04 +01:00
|
|
|
''
|
2009-11-19 16:12:05 +01:00
|
|
|
if [ "$initialize" = "1" ]
|
|
|
|
then
|
2009-11-19 16:17:04 +01:00
|
|
|
# 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
|
|
|
|
|
2009-11-19 16:12:05 +01:00
|
|
|
${concatMapStrings (dump:
|
|
|
|
''
|
|
|
|
echo "Importing dump: ${dump}"
|
2009-11-20 16:35:01 +01:00
|
|
|
|
|
|
|
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
|
2009-11-19 16:12:05 +01:00
|
|
|
'') cfg.loadDumps}
|
|
|
|
fi
|
|
|
|
''}
|
2009-10-12 18:36:19 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
postStop =
|
|
|
|
''
|
2009-11-19 14:15:15 +01:00
|
|
|
ejabberdctl --config-dir ${cfg.confDir} --logs ${cfg.logsDir} --spool ${cfg.spoolDir} stop
|
2009-10-12 18:36:19 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2009-03-06 13:26:29 +01:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2008-02-04 14:40:01 +01:00
|
|
|
}
|