gen_config.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/usr/bin/env php
  2. <?php
  3. /*
  4. * StatusNet - the distributed open-source microblogging tool
  5. * Copyright (C) 2009, 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. define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
  21. $longoptions = array('base=', 'network');
  22. $helptext = <<<END_OF_TRIM_HELP
  23. Generates sphinx.conf file based on StatusNet configuration.
  24. --base Base dir to Sphinx install
  25. (default /usr/local)
  26. --network Use status_network global config table
  27. (non-functional at present)
  28. END_OF_TRIM_HELP;
  29. require_once INSTALLDIR . '/scripts/commandline.inc';
  30. require dirname(__FILE__) . '/sphinx-utils.php';
  31. $timestamp = date('r');
  32. print <<<END
  33. #
  34. # Sphinx configuration for StatusNet
  35. # Generated {$timestamp}
  36. #
  37. END;
  38. sphinx_iterate_sites('sphinx_site_template');
  39. print <<<END
  40. indexer
  41. {
  42. mem_limit = 300M
  43. }
  44. searchd
  45. {
  46. port = 3312
  47. log = {$base}/log/searchd.log
  48. query_log = {$base}/log/query.log
  49. read_timeout = 5
  50. max_children = 30
  51. pid_file = {$base}/log/searchd.pid
  52. max_matches = 1000
  53. seamless_rotate = 1
  54. preopen_indexes = 0
  55. unlink_old = 1
  56. }
  57. END;
  58. /**
  59. * Build config entries for a single site
  60. * @fixme we only seem to have master DB currently available...
  61. */
  62. function sphinx_site_template($sn)
  63. {
  64. return
  65. sphinx_template($sn,
  66. 'profile',
  67. 'SELECT id, UNIX_TIMESTAMP(created) as created_ts, nickname, fullname, location, bio, homepage FROM profile',
  68. 'SELECT * FROM profile where id = $id') .
  69. sphinx_template($sn,
  70. 'notice',
  71. 'SELECT id, UNIX_TIMESTAMP(created) as created_ts, content FROM notice',
  72. 'SELECT * FROM notice where notice.id = $id AND notice.is_local != -2');
  73. }
  74. function sphinx_template($sn, $table, $query, $query_info)
  75. {
  76. $base = sphinx_base();
  77. $dbtype = common_config('db', 'type');
  78. print <<<END
  79. #
  80. # {$sn->sitename}
  81. #
  82. source {$sn->dbname}_src_{$table}
  83. {
  84. type = {$dbtype}
  85. sql_host = {$sn->dbhost}
  86. sql_user = {$sn->dbuser}
  87. sql_pass = {$sn->dbpass}
  88. sql_db = {$sn->dbname}
  89. sql_query_pre = SET NAMES utf8;
  90. sql_query = {$query}
  91. sql_query_info = {$query_info}
  92. sql_attr_timestamp = created_ts
  93. }
  94. index {$sn->dbname}_{$table}
  95. {
  96. source = {$sn->dbname}_src_{$table}
  97. path = {$base}/data/{$sn->dbname}_{$table}
  98. docinfo = extern
  99. charset_type = utf-8
  100. min_word_len = 3
  101. }
  102. END;
  103. }