tpsgi 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!bin/tarbaby
  2. #ABSTRACT: PSGI application which simplifies migrating legacy/cgi applications to PSGI, but also has advanced features for normal psgi apps
  3. use strict;
  4. use warnings;
  5. use Cwd;
  6. use FindBin::libs;
  7. use File::Basename qw{dirname};
  8. use TPSGI;
  9. my %options = main(@ARGV);
  10. =head1 USAGE
  11. tpsgi ... starman options
  12. tpsgi obeys a config file, ~/.tpsgi.ini which is in Config::Simple (key=value) format, with the keys being:
  13. verbose # Whether to print all log messages or not
  14. custom_log # Custom location for default (rotated) log
  15. routers # Router module(s), separate with comma. Relative to TPSGI install dir.
  16. indices # Dirindex files. In addition to index.html, index.htm, index.cgi
  17. loggers # Logger module(s), separate with comma
  18. auth # Authentication module
  19. domain # Domain name of the application, used by things like service files
  20. basedir # Directory you want to chdir into on startup. Relative to TPSGI install dir. Default '.'
  21. user # Who to run as
  22. http_user # Who's proxying this application (used for statics)
  23. autoreload # Whether or not to automatically reload the application when library files change. Default 0.
  24. The idea is that this application is going to be run in a chroot with the user's homedir being the application dir.
  25. This is why the various paths asked for are relative to the tPSGI install dir.
  26. =cut
  27. sub main {
  28. my (@args) = @_;
  29. my %options = TPSGI::get_config();
  30. foreach my $route (@{$options{routers}}) {
  31. my $libdir = dirname($route);
  32. push(@INC, $libdir);
  33. }
  34. return %options;
  35. }
  36. our $app = sub {
  37. umask 0022;
  38. # Change your dir into whatever basedir you need to be in
  39. chdir("$options{tpsgi_dir}/$options{basedir}") or die "Can't chdir into $options{tpsgi_dir}/$options{'basedir'}: $!";
  40. # If we have manually set the NYTPROF var, use it and don't try to control
  41. # When to stop or start it.
  42. $ENV{NYTPROF} ||= "sigexit=1:savesrc=0:start=no:file=$options{tpsgi_dir}/prof/nytprof.out";
  43. require Devel::NYTProf;
  44. mkdir "$options{tpsgi_dir}/prof";
  45. my $self = TPSGI->new(%options);
  46. return $self->app(@_);
  47. };