cms.pl 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 $cms_handler = CMS->new({
  43. CMS_ROOT => $cms_root,
  44. CONFIG => $cms_config->config(),
  45. });
  46. my $fcgi_handler = CMS::FCGI->new({
  47. HANDLER => $cms_handler,
  48. PORT => $listen_port,
  49. HOST => $listen_addr,
  50. });
  51. $0 = 'CMS: master process ' . $cms_root;
  52. daemonize() if ($daemon);
  53. $fcgi_handler->main({
  54. 'runas' => $user,
  55. 'chroot' => $chroot,
  56. 'processname' => 'CMS: slave process ' . $cms_root,
  57. });
  58. __END__
  59. =head1 NAME
  60. Google sitemap.xml generator for the CMS system
  61. =head1 SYNOPSIS
  62. Sitemap.pl [options]
  63. Options:
  64. --help brief help message
  65. --hostname hostname for link generation
  66. --cms-root root of the CMS data directory
  67. --host listen address for the FCGI TCP listener
  68. --port listen port for the FCGI TCP listener
  69. --nodaemon don't daemonize
  70. =head1 OPTIONS
  71. =over 8
  72. =item B<--help>
  73. Print a brief help message and exits.
  74. =item B<--hostname>
  75. Hostname used for link generation. If not specified the result of hostname()
  76. will be used.
  77. =item B<--cms-root>
  78. Root directory of the CMS data. Defaults to /var/www/cms
  79. =item B<--host>
  80. Listen address of the FCGI TCP listener. The B<--port> option is required to
  81. enable the TCP listener.
  82. =item B<--port>
  83. Port the TCP listener should use.
  84. =item B<--nodaemon>
  85. Stay on the terminal after start, don't daemonize.
  86. =back
  87. =head1 DESCRIPTION
  88. B<Sitemap.pl> will read the contents of the CMS data directory and generate
  89. a link list with the time of the last change to one of the linked pages in
  90. the google sitemap format.
  91. =cut