sitemap.pl 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #! /usr/bin/perl
  2. # vi: set tabstop=4 expandtab shiftwidth=4:
  3. ##############################################################################
  4. use strict;
  5. use warnings;
  6. use Getopt::Long;
  7. use Pod::Usage;
  8. use Sys::Syslog qw(:standard :macros);
  9. use CMS::FCGI;
  10. use CMS::Sitemap;
  11. use CMS::Daemon qw(daemonize);
  12. use CMS::Config;
  13. ##############################################################################
  14. # Parameters
  15. my $hostname = undef;
  16. my $cms_root = '/var/www/cms';
  17. my $listen_addr = 'localhost';
  18. my $listen_port = undef;
  19. my $help = undef;
  20. my $daemon = 1;
  21. my $user = 'nobody';
  22. my $chroot;
  23. GetOptions(
  24. 'host|h=s' => \$listen_addr,
  25. 'port|p=i' => \$listen_port,
  26. 'cms-root|r=s' => \$cms_root,
  27. 'help|?' => \$help,
  28. 'daemon!' => \$daemon,
  29. 'chroot|c=s' => \$chroot,
  30. 'D' => sub { $daemon = undef },
  31. ) || pod2usage(2);
  32. pod2usage(1) if ($help);
  33. ##############################################################################
  34. my $cms_config = CMS::Config->new({CMS_ROOT => $cms_root});
  35. my $sitemap_handler = CMS::Sitemap->new({
  36. CMS_ROOT => $cms_root,
  37. HOSTNAME => $cms_config->config()->{hostname}->{plain},
  38. SSLHOSTNAME => $cms_config->config()->{hostname}->{ssl},
  39. });
  40. my $fcgi_handler = CMS::FCGI->new({
  41. HANDLER => $sitemap_handler,
  42. PORT => $listen_port,
  43. HOST => $listen_addr,
  44. });
  45. $0 = 'Sitemap: master process ' . $cms_root;
  46. daemonize() if ($daemon);
  47. openlog('Sitemap', 'nofatal,ndelay,pid', LOG_DAEMON);
  48. $fcgi_handler->main({
  49. 'runas' => $user,
  50. 'chroot' => $chroot,
  51. 'processname' => 'Sitemap: slave process ' . $cms_root,
  52. });
  53. __END__
  54. =pod
  55. =head1 NAME
  56. Google sitemap.xml generator for the CMS system
  57. =head1 SYNOPSIS
  58. Sitemap.pl [options]
  59. Options:
  60. --help brief help message
  61. --hostname hostname for link generation
  62. --cms-root root of the CMS data directory
  63. --host listen address for the FCGI TCP listener
  64. --port listen port for the FCGI TCP listener
  65. --nodaemon don't daemonize, -D is an alias for this option
  66. --chroot chroot into the given directory
  67. =head1 OPTIONS
  68. =over 8
  69. =item B<--help>
  70. Print a brief help message and exits.
  71. =item B<--cms-root>
  72. Root directory of the CMS data. Defaults to /var/www/cms
  73. =item B<--host>
  74. Listen address of the FCGI TCP listener. The B<--port> option is required to
  75. enable the TCP listener.
  76. =item B<--port>
  77. Port the TCP listener should use.
  78. =item B<--nodaemon>
  79. Stay on the terminal after start, don't daemonize.
  80. =item B<--chroot>
  81. Change the root directory upon start. Note that the path of B<--cms-root> has
  82. to be relative to this directory.
  83. =back
  84. =head1 DESCRIPTION
  85. B<Sitemap.pl> will read the contents of the CMS data directory and generate
  86. a link list with the time of the last change to one of the linked pages in
  87. the google sitemap format.
  88. =cut