2008-06-27 00:03:36 +09:00
|
|
|
#!/usr/bin/env php
|
2008-06-23 11:27:10 +09:00
|
|
|
<?php
|
|
|
|
/*
|
2009-08-26 07:14:12 +09:00
|
|
|
* StatusNet - the distributed open-source microblogging tool
|
2009-08-26 07:12:20 +09:00
|
|
|
* Copyright (C) 2008, 2009, StatusNet, Inc.
|
2008-06-23 11:27:10 +09:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-08-14 00:46:03 +09:00
|
|
|
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
|
2008-08-27 23:23:36 +09:00
|
|
|
|
2010-02-17 02:01:59 +09:00
|
|
|
$shortoptions = 'fi::a';
|
|
|
|
$longoptions = array('id::', 'foreground', 'all');
|
2009-06-23 09:07:14 +09:00
|
|
|
|
|
|
|
$helptext = <<<END_OF_XMPP_HELP
|
|
|
|
Daemon script for receiving new notices from Jabber users.
|
2009-06-21 06:58:47 +09:00
|
|
|
|
2009-06-25 11:31:12 +09:00
|
|
|
-i --id Identity (default none)
|
2010-02-17 02:01:59 +09:00
|
|
|
-a --all Handle XMPP for all local sites
|
|
|
|
(requires Stomp queue handler, status_network setup)
|
2009-06-29 05:13:08 +09:00
|
|
|
-f --foreground Stay in the foreground (default background)
|
2009-06-21 06:58:47 +09:00
|
|
|
|
2009-06-23 09:07:14 +09:00
|
|
|
END_OF_XMPP_HELP;
|
2008-06-23 11:27:10 +09:00
|
|
|
|
2009-06-23 09:07:14 +09:00
|
|
|
require_once INSTALLDIR.'/scripts/commandline.inc';
|
|
|
|
|
|
|
|
require_once INSTALLDIR . '/lib/jabber.php';
|
2008-08-28 05:54:07 +09:00
|
|
|
|
2010-01-22 09:42:50 +09:00
|
|
|
class XMPPDaemon extends SpawningDaemon
|
2008-12-24 04:49:23 +09:00
|
|
|
{
|
2010-02-17 02:01:59 +09:00
|
|
|
protected $allsites = false;
|
|
|
|
|
|
|
|
function __construct($id=null, $daemonize=true, $threads=1, $allsites=false)
|
2008-12-24 04:33:23 +09:00
|
|
|
{
|
2010-01-22 09:42:50 +09:00
|
|
|
if ($threads != 1) {
|
|
|
|
// This should never happen. :)
|
|
|
|
throw new Exception("XMPPDaemon can must run single-threaded");
|
2009-07-09 22:31:10 +09:00
|
|
|
}
|
2010-01-22 09:42:50 +09:00
|
|
|
parent::__construct($id, $daemonize, $threads);
|
2010-02-17 02:01:59 +09:00
|
|
|
$this->allsites = $allsites;
|
2009-07-09 22:31:10 +09:00
|
|
|
}
|
|
|
|
|
2010-01-22 09:42:50 +09:00
|
|
|
function runThread()
|
2009-07-09 22:31:10 +09:00
|
|
|
{
|
2010-01-22 09:42:50 +09:00
|
|
|
common_log(LOG_INFO, 'Waiting to listen to XMPP and queues');
|
2009-07-09 22:31:10 +09:00
|
|
|
|
2010-01-22 09:42:50 +09:00
|
|
|
$master = new XmppMaster($this->get_id());
|
2010-02-17 02:01:59 +09:00
|
|
|
$master->init($this->allsites);
|
2010-01-22 09:42:50 +09:00
|
|
|
$master->service();
|
2009-07-09 22:31:10 +09:00
|
|
|
|
2010-01-22 09:42:50 +09:00
|
|
|
common_log(LOG_INFO, 'terminating normally');
|
2008-12-24 04:19:07 +09:00
|
|
|
|
2010-01-27 04:49:49 +09:00
|
|
|
return $master->respawn ? self::EXIT_RESTART : self::EXIT_SHUTDOWN;
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
|
|
|
|
2010-01-22 09:42:50 +09:00
|
|
|
}
|
2008-12-24 04:19:07 +09:00
|
|
|
|
2010-01-22 09:42:50 +09:00
|
|
|
class XmppMaster extends IoMaster
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Initialize IoManagers for the currently configured site
|
|
|
|
* which are appropriate to this instance.
|
|
|
|
*/
|
|
|
|
function initManagers()
|
|
|
|
{
|
2010-02-17 02:01:59 +09:00
|
|
|
if (common_config('xmpp', 'enabled')) {
|
|
|
|
$qm = QueueManager::get();
|
|
|
|
$qm->setActiveGroup('xmpp');
|
|
|
|
$this->instantiate($qm);
|
|
|
|
$this->instantiate(XmppManager::get());
|
|
|
|
}
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
2008-06-23 11:27:10 +09:00
|
|
|
}
|
|
|
|
|
2009-04-17 05:07:59 +09:00
|
|
|
// Abort immediately if xmpp is not enabled, otherwise the daemon chews up
|
|
|
|
// lots of CPU trying to connect to unconfigured servers
|
2010-02-17 02:01:59 +09:00
|
|
|
// @fixme do this check after we've run through the site list so we
|
|
|
|
// don't have to find an XMPP site to start up when using --all mode.
|
2009-04-17 05:07:59 +09:00
|
|
|
if (common_config('xmpp','enabled')==false) {
|
|
|
|
print "Aborting daemon - xmpp is disabled\n";
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2009-06-29 05:13:08 +09:00
|
|
|
if (have_option('i', 'id')) {
|
|
|
|
$id = get_option_value('i', 'id');
|
2009-06-23 09:07:14 +09:00
|
|
|
} else if (count($args) > 0) {
|
2009-06-25 11:31:12 +09:00
|
|
|
$id = $args[0];
|
2009-06-23 09:07:14 +09:00
|
|
|
} else {
|
2009-06-25 11:31:12 +09:00
|
|
|
$id = null;
|
2009-06-23 09:07:14 +09:00
|
|
|
}
|
2008-06-27 00:03:36 +09:00
|
|
|
|
2009-06-29 05:13:08 +09:00
|
|
|
$foreground = have_option('f', 'foreground');
|
2010-02-17 02:01:59 +09:00
|
|
|
$all = have_option('a') || have_option('--all');
|
2009-06-29 05:13:08 +09:00
|
|
|
|
2010-02-17 02:01:59 +09:00
|
|
|
$daemon = new XMPPDaemon($id, !$foreground, 1, $all);
|
2008-06-23 11:27:10 +09:00
|
|
|
|
2008-09-17 06:08:13 +09:00
|
|
|
$daemon->runOnce();
|