diff --git a/cassandane/Cassandane/Instance.pm b/cassandane/Cassandane/Instance.pm index 07529592dd..a9c7f4d98a 100644 --- a/cassandane/Cassandane/Instance.pm +++ b/cassandane/Cassandane/Instance.pm @@ -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; @@ -104,6 +105,7 @@ sub new starts => [], services => {}, events => [], + daemons => {}, generic_listeners => {}, re_use_dir => 0, setup_mailbox => 1, @@ -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) = @_; @@ -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; } @@ -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; @@ -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(); @@ -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) { diff --git a/cassandane/Cassandane/MasterDaemon.pm b/cassandane/Cassandane/MasterDaemon.pm new file mode 100644 index 0000000000..379cd66a25 --- /dev/null +++ b/cassandane/Cassandane/MasterDaemon.pm @@ -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;