queuectl.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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', dirname(__DIR__));
  27. define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
  28. $shortoptions = 'ur';
  29. $longoptions = array('update', 'restart', 'stop');
  30. $helptext = <<<END_OF_QUEUECTL_HELP
  31. Send broadcast events to control any running queue handlers.
  32. (Currently for Stomp queues only.)
  33. Events relating to current site (as selected with -s etc)
  34. -u --update Announce new site or updated configuration. Running
  35. daemons will start subscribing to any new queues needed
  36. for this site.
  37. Global events:
  38. -r --restart Graceful restart of all threads
  39. --stop Graceful shutdown of all threads
  40. END_OF_QUEUECTL_HELP;
  41. require_once INSTALLDIR.'/scripts/commandline.inc';
  42. function doSendControl($message, $event, $param='')
  43. {
  44. print $message;
  45. $qm = QueueManager::get();
  46. if ($qm->sendControlSignal($event, $param)) {
  47. print " sent.\n";
  48. } else {
  49. print " FAILED.\n";
  50. }
  51. }
  52. $actions = 0;
  53. if (have_option('u') || have_option('--update')) {
  54. $nickname = common_config('site', 'nickname');
  55. doSendControl("Sending site update signal to queue daemons for $nickname",
  56. "update", $nickname);
  57. $actions++;
  58. }
  59. if (have_option('r') || have_option('--restart')) {
  60. doSendControl("Sending graceful restart signal to queue daemons...",
  61. "restart");
  62. $actions++;
  63. }
  64. if (have_option('--stop')) {
  65. doSendControl("Sending graceful shutdown signal to queue daemons...",
  66. "shutdown");
  67. $actions++;
  68. }
  69. if (!$actions) {
  70. show_help();
  71. }