Skip to content

Commit

Permalink
Instance: add support for cyrus.conf DAEMON entries
Browse files Browse the repository at this point in the history
  • Loading branch information
elliefm committed Jun 26, 2023
1 parent 6830341 commit 10ff8d4
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
30 changes: 29 additions & 1 deletion cassandane/Cassandane/Instance.pm
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ use Cassandane::ServiceFactory;
use Cassandane::GenericListener;
use Cassandane::MasterStart;
use Cassandane::MasterEvent;
use Cassandane::MasterDaemon;
use Cassandane::Cassini;
use Cassandane::PortManager;
use Cassandane::Net::SMTPServer;
Expand Down Expand Up @@ -104,6 +105,7 @@ sub new
starts => [],
services => {},
events => [],
daemons => {},
generic_listeners => {},
re_use_dir => 0,
setup_mailbox => 1,
Expand Down Expand Up @@ -465,6 +467,19 @@ sub add_event
push(@{$self->{events}}, Cassandane::MasterEvent->new(%params));
}

sub add_daemon
{
my ($self, %params) = @_;

my $name = $params{name};
die "Missing parameter 'name'"
unless defined $name;
die "Already have a daemon named \"$name\""
if defined $self->{daemons}->{$name};

$self->{daemons}->{$name} = Cassandane::MasterDaemon->new(%params);
}

sub add_generic_listener
{
my ($self, %params) = @_;
Expand Down Expand Up @@ -786,6 +801,13 @@ sub _generate_master_conf
print MASTER "}\n";
}

if (scalar %{$self->{daemons}})
{
print MASTER "DAEMON {\n";
$self->_emit_master_entry($_) for values %{$self->{daemons}};
print MASTER "}\n";
}

close MASTER;
}

Expand All @@ -803,7 +825,7 @@ sub _add_services_from_cyrus_conf
chomp;
s/\s*#.*//; # strip comments
next if m/^\s*$/; # skip empty lines
my ($m) = m/^(START|SERVICES|EVENTS)\s*{/;
my ($m) = m/^(START|SERVICES|EVENTS|DAEMON)\s*{/;
if ($m)
{
$in = $m;
Expand Down Expand Up @@ -1207,6 +1229,10 @@ sub start
elsif (!scalar $self->{services})
{
$self->_add_services_from_cyrus_conf();
# XXX START, EVENTS, DAEMON entries will be missed here if reusing
# XXX the directory. Does it matter? Maybe not, since the master
# XXX conf already contains them, so they'll still run, just
# XXX cassandane won't know about it.
}
$self->setup_syslog_replacement();
$self->_start_notifyd();
Expand All @@ -1217,6 +1243,8 @@ sub start

# give fakesaslauthd a moment (but not more than 2s) to set up its
# socket before anything starts trying to connect to services
# XXX if this were a DAEMON with wait=y, this would be unnecessary,
# XXX though those didn't exist until 3.4
if ($self->{authdaemon}) {
my $tries = 0;
while (not -S $fakesaslauthd_socket && $tries < 2_000_000) {
Expand Down
58 changes: 58 additions & 0 deletions cassandane/Cassandane/MasterDaemon.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/perl
#
# Copyright (c) 2011-2023 FastMail Pty Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# 3. The name "Fastmail Pty Ltd" must not be used to
# endorse or promote products derived from this software without
# prior written permission. For permission or any legal
# details, please contact
# FastMail Pty Ltd
# PO Box 234
# Collins St West 8007
# Victoria
# Australia
#
# 4. Redistributions of any form whatsoever must retain the following
# acknowledgment:
# "This product includes software developed by Fastmail Pty. Ltd."
#
# FASTMAIL PTY LTD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
# EVENT SHALL OPERA SOFTWARE AUSTRALIA BE LIABLE FOR ANY SPECIAL, INDIRECT
# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
# USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
# OF THIS SOFTWARE.
#

package Cassandane::MasterDaemon;
use strict;
use warnings;

use lib '.';
use base qw(Cassandane::MasterEntry);

sub new
{
return shift->SUPER::new(@_);
}

sub _otherparams
{
my ($self) = @_;
return ( qw(wait) );
}

1;

0 comments on commit 10ff8d4

Please sign in to comment.