2009-03-06 13:26:29 +01:00
|
|
|
{pkgs, config, ...}:
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
let
|
|
|
|
inherit (pkgs.lib) mkOption mkIf;
|
|
|
|
|
|
|
|
options = {
|
|
|
|
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";
|
|
|
|
};
|
|
|
|
|
|
|
|
virtualHosts = mkOption {
|
|
|
|
default = "\"localhost\"";
|
|
|
|
description = "Virtualhosts that ejabberd should host. Hostnames are surrounded with doublequotes and separated by commas";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
|
|
|
|
###### implementation
|
2008-02-04 14:40:01 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.ejabberd;
|
|
|
|
|
|
|
|
in
|
2009-03-06 13:26:29 +01:00
|
|
|
|
|
|
|
mkIf config.services.ejabberd.enable {
|
|
|
|
|
|
|
|
require = [
|
|
|
|
options
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
services = {
|
|
|
|
extraJobs = [{
|
|
|
|
name = "ejabberd";
|
|
|
|
|
|
|
|
job = ''
|
|
|
|
description "EJabberd server"
|
|
|
|
|
|
|
|
start on network-interface/started
|
|
|
|
stop on network-interfaces/stop
|
2008-07-06 12:30:53 +02:00
|
|
|
|
2009-03-06 13:26:29 +01:00
|
|
|
start script
|
|
|
|
# Initialise state data
|
|
|
|
mkdir -p ${cfg.logsDir}
|
|
|
|
|
|
|
|
if ! test -d ${cfg.spoolDir}
|
|
|
|
then
|
|
|
|
cp -av ${pkgs.ejabberd}/var/lib/ejabberd /var/lib
|
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir -p ${cfg.confDir}
|
2009-04-13 13:15:19 +02:00
|
|
|
test -f ${cfg.confDir}/ejabberd.cfg || sed -e 's|{hosts, \["localhost"\]}.|{hosts, \[${cfg.virtualHosts}\]}.|' ${pkgs.ejabberd}/etc/ejabberd/ejabberd.cfg > ${cfg.confDir}/ejabberd.cfg
|
2009-03-06 13:26:29 +01:00
|
|
|
end script
|
|
|
|
|
2009-05-20 01:46:25 +02:00
|
|
|
respawn ${pkgs.bash}/bin/sh -c 'export PATH=$PATH:${pkgs.ejabberd}/sbin:${pkgs.coreutils}/bin:${pkgs.bash}/bin; cd ~; ejabberdctl --logs ${cfg.logsDir} --spool ${cfg.spoolDir} --config ${cfg.confDir}/ejabberd.cfg start; sleep 1d'
|
2009-03-06 13:26:29 +01:00
|
|
|
|
|
|
|
stop script
|
|
|
|
${pkgs.ejabberd}/sbin/ejabberdctl stop
|
|
|
|
end script
|
|
|
|
'';
|
|
|
|
}];
|
|
|
|
};
|
2008-02-04 14:40:01 +01:00
|
|
|
}
|