cms.pl 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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;
  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 $verbose = 4; # Log up to LOG_WARNING as default
  22. my $user = 'nobody';
  23. my $chroot;
  24. GetOptions(
  25. 'host|h=s' => \$listen_addr,
  26. 'port|p=i' => \$listen_port,
  27. 'cms-root|r=s' => \$cms_root,
  28. 'help|?' => \$help,
  29. 'daemon!' => \$daemon,
  30. 'chroot|c=s' => \$chroot,
  31. 'verbose|v+' => \$verbose,
  32. 'D' => sub { $daemon = undef },
  33. ) || pod2usage(2);
  34. pod2usage(1) if ($help);
  35. my @loglevels = ( LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING,
  36. LOG_NOTICE, LOG_INFO, LOG_DEBUG );
  37. $verbose = scalar @loglevels if ($verbose >= scalar @loglevels);
  38. openlog('CMS', 'nofatal,ndelay,pid', LOG_DAEMON);
  39. setlogmask(LOG_UPTO($loglevels[$verbose]));
  40. ##############################################################################
  41. my $cms_config = CMS::Config->new({CMS_ROOT => $cms_root});
  42. my $rootdir = $cms_config->translate_cmsroot($chroot);
  43. die "The chroot directory does not contain CMS root directory.\n"
  44. unless $rootdir;
  45. if ($chroot) {
  46. # Add the leading slash, so we have an absolut path under the chroot again
  47. $rootdir = '/' . $rootdir unless $rootdir =~ m/^\//x;
  48. }
  49. my $cms_handler = CMS->new({
  50. CMS_ROOT => $rootdir,
  51. CHROOT => $chroot,
  52. CONFIG => $cms_config->config(),
  53. });
  54. my $fcgi_handler = CMS::FCGI->new({
  55. HANDLER => $cms_handler,
  56. PORT => $listen_port,
  57. HOST => $listen_addr,
  58. });
  59. $0 = 'CMS: master process ' . $cms_root;
  60. daemonize() if ($daemon);
  61. $fcgi_handler->main({
  62. 'runas' => $user,
  63. 'chroot' => $chroot,
  64. 'processname' => 'CMS: slave process ' . $cms_root,
  65. });
  66. __END__
  67. =head1 NAME
  68. Google sitemap.xml generator for the CMS system
  69. =head1 SYNOPSIS
  70. Sitemap.pl [options]
  71. Options:
  72. --help brief help message
  73. --hostname hostname for link generation
  74. --cms-root root of the CMS data directory
  75. --host listen address for the FCGI TCP listener
  76. --port listen port for the FCGI TCP listener
  77. --nodaemon don't daemonize
  78. =head1 OPTIONS
  79. =over 8
  80. =item B<--help>
  81. Print a brief help message and exits.
  82. =item B<--hostname>
  83. Hostname used for link generation. If not specified the result of hostname()
  84. will be used.
  85. =item B<--cms-root>
  86. Root directory of the CMS data. Defaults to /var/www/cms
  87. =item B<--host>
  88. Listen address of the FCGI TCP listener. The B<--port> option is required to
  89. enable the TCP listener.
  90. =item B<--port>
  91. Port the TCP listener should use.
  92. =item B<--nodaemon>
  93. Stay on the terminal after start, don't daemonize.
  94. =back
  95. =head1 DESCRIPTION
  96. B<Sitemap.pl> will read the contents of the CMS data directory and generate
  97. a link list with the time of the last change to one of the linked pages in
  98. the google sitemap format.
  99. =cut