queuectl.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/usr/bin/env php
  2. <?php
  3. /*
  4. * StatusNet - the distributed open-source microblogging tool
  5. * Copyright (C) 2010, StatusNet, Inc.
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * Sends control signals to running queue daemons.
  22. *
  23. * @author Brion Vibber <brion@status.net>
  24. * @package QueueHandler
  25. */
  26. define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
  27. $shortoptions = 'ur';
  28. $longoptions = array('update', 'restart', 'stop');
  29. $helptext = <<<END_OF_QUEUECTL_HELP
  30. Send broadcast events to control any running queue handlers.
  31. (Currently for Stomp queues only.)
  32. Events relating to current site (as selected with -s etc)
  33. -u --update Announce new site or updated configuration. Running
  34. daemons will start subscribing to any new queues needed
  35. for this site.
  36. Global events:
  37. -r --restart Graceful restart of all threads
  38. --stop Graceful shutdown of all threads
  39. END_OF_QUEUECTL_HELP;
  40. require_once INSTALLDIR.'/scripts/commandline.inc';
  41. function doSendControl($message, $event, $param='')
  42. {
  43. print $message;
  44. $qm = QueueManager::get();
  45. if ($qm->sendControlSignal($event, $param)) {
  46. print " sent.\n";
  47. } else {
  48. print " FAILED.\n";
  49. }
  50. }
  51. $actions = 0;
  52. if (have_option('u') || have_option('--update')) {
  53. $nickname = common_config('site', 'nickname');
  54. doSendControl("Sending site update signal to queue daemons for $nickname",
  55. "update", $nickname);
  56. $actions++;
  57. }
  58. if (have_option('r') || have_option('--restart')) {
  59. doSendControl("Sending graceful restart signal to queue daemons...",
  60. "restart");
  61. $actions++;
  62. }
  63. if (have_option('--stop')) {
  64. doSendControl("Sending graceful shutdown signal to queue daemons...",
  65. "shutdown");
  66. $actions++;
  67. }
  68. if (!$actions) {
  69. show_help();
  70. }