George Baugh 1 anno fa
parent
commit
1093004d9b
5 ha cambiato i file con 81 aggiunte e 32 eliminazioni
  1. 1 0
      .gitignore
  2. 2 32
      bin/tpsgi
  3. 24 0
      bin/tpsgi-hostname
  4. 30 0
      lib/TPSGI.pm
  5. 24 0
      service/tpsgi.sh

+ 1 - 0
.gitignore

@@ -1,2 +1,3 @@
 log/*
 www/*
+.tpsgi.ini

+ 2 - 32
bin/tpsgi

@@ -11,9 +11,6 @@ use FindBin::libs;
 
 use TPSGI;
 
-use Getopt::Long qw{GetOptionsFromArray};
-use Config::Simple;
-
 my %options = main(@ARGV);
 
 =head1 USAGE
@@ -28,6 +25,7 @@ tpsgi obeys a config file, ~/.tpsgi.ini which is in Config::Simple (key=value) f
     indices     # Dirindex files.  In addition to index.html, index.htm, index.cgi
     loggers     # Logger module(s), separate with comma
     auth        # Authentication module
+    domain      # Domain name of the application, used by things like service files
 
 The idea is that this application is going to be run in a chroot with the user's homedir being the application dir.
 
@@ -36,35 +34,7 @@ The idea is that this application is going to be run in a chroot with the user's
 sub main {
     my (@args) = @_;
 
-    my %options = _get_from_config();
-    return %options;
-}
-
-sub _get_from_config {
-    my %options = (
-        verbose    => 0,
-        custom_log => undef,
-        routers    => [],
-        loggers    => [],
-        auth       => undef,
-    );
-   	my $config_file = "$ENV{HOME}/.tpsgi.ini";
-	if (-f $config_file) {
-		my $conf = Config::Simple->new($config_file);
-		my %config;
-		%config = %{$conf->param(-block => 'default')} if $conf;
-
-		# Merge the configuration with the options
-		foreach my $opt (keys(%options)) {
-			if ( ref $options{$opt} eq 'ARRAY' ) {
-				next unless exists $config{$opt};
-				my @arrayed = ref $config{$opt} eq 'ARRAY' ? @{$config{$opt}} : ($config{$opt});
-				push(@{$options{$opt}}, @arrayed);
-				next;
-			}
-			$options{$opt} = $config{$opt} if exists $config{$opt};
-		}
-	}
+    my %options = TPSGI::get_config();
     return %options;
 }
 

+ 24 - 0
bin/tpsgi-hostname

@@ -0,0 +1,24 @@
+#!/usr/bin/env perl
+
+package TPSGI::Hostname;
+
+use strict;
+use warnings;
+
+use FindBin::libs;
+
+use TPSGI;
+
+sub main {
+    my @args = @_;
+
+    my %config = TPSGI::get_config();
+
+    die "Could not get hostname" unless $config{domain};
+    print "$config{domain}\n";
+    return 0;
+}
+
+exit main(@ARGV) unless caller;
+
+1;

+ 30 - 0
lib/TPSGI.pm

@@ -35,6 +35,8 @@ use Log::Dispatch;
 use Log::Dispatch::Screen;
 use Log::Dispatch::FileRotate;
 
+use Config::Simple;
+
 #1MB chunks
 our $CHUNK_SEP  = 'perlfsSep666YOLO42069';
 our $CHUNK_SIZE = 1024000;
@@ -747,5 +749,33 @@ sub static {
     return $self->forbidden($self->{current_query});
 }
 
+sub get_config {
+    my %options = (
+        verbose    => 0,
+        custom_log => undef,
+        routers    => [],
+        loggers    => [],
+        auth       => undef,
+        domain     => '',
+    );
+   	my $config_file = "$ENV{HOME}/.tpsgi.ini";
+	if (-f $config_file) {
+		my $conf = Config::Simple->new($config_file);
+		my %config;
+		%config = %{$conf->param(-block => 'default')} if $conf;
+
+		# Merge the configuration with the options
+		foreach my $opt (keys(%options)) {
+			if ( ref $options{$opt} eq 'ARRAY' ) {
+				next unless exists $config{$opt};
+				my @arrayed = ref $config{$opt} eq 'ARRAY' ? @{$config{$opt}} : ($config{$opt});
+				push(@{$options{$opt}}, @arrayed);
+				next;
+			}
+			$options{$opt} = $config{$opt} if exists $config{$opt};
+		}
+	}
+    return %options;
+}
 
 1;

+ 24 - 0
service/tpsgi.sh

@@ -0,0 +1,24 @@
+#!/bin/bash
+USERNAME=$(bin/tpsgi-hostname --user)
+echo "tCMS running as user $USERNAME"
+[[ -e run/tcms.pid ]] && sudo pkill -F run/tcms.pid
+source perl5/perlbrew/etc/bashrc
+PERL=$(sudo -u $USERNAME perlbrew exec which perl)
+STARMAN=$(sudo -u $USERNAME perlbrew exec which starman)
+sudo $PERL $STARMAN www/server.psgi --listen run/tcms.sock --workers 20 --user "$USERNAME" --daemonize --pid run/tcms.pid --chroot $(pwd)
+
+# Wait until the socket file is ready
+until [ -e run/tcms.sock ]
+do
+    echo "Waiting for sock to be ready..."
+    sleep 1
+done
+
+# Fix ownership of socket so nginx can see it
+sudo chown $USERNAME:www-data run/tcms.sock
+sudo chmod 0770 run/tcms.sock
+
+echo "tCMS running as PID "`cat run/tcms.pid`
+
+# TODO Run reloader process
+#$PERL bin/tcms_monitor