فهرست منبع

Support auto-da-fe in nginx-unit, harakiri etc

George Baugh 2 سال پیش
والد
کامیت
b622d017ff
5فایلهای تغییر یافته به همراه35 افزوده شده و 4 حذف شده
  1. 1 0
      Makefile.PL
  2. 2 0
      config/default.cfg
  3. 3 2
      config/nginx-unit/Makefile
  4. 11 2
      config/nginx-unit/config.json.tmpl
  5. 18 0
      lib/Trog/Utils.pm

+ 1 - 0
Makefile.PL

@@ -61,6 +61,7 @@ WriteMakefile(
     'URI'                       => '0',
     'FindBin::libs'             => '0',
     'Carp::Always'              => '0',
+    'HTTP::Tiny::UNIX'          => '0',
   },
   test => {TESTS => 't/*.t'}
 );

+ 2 - 0
config/default.cfg

@@ -5,3 +5,5 @@
     secret=OverrideMeInYourConfigPlease!
 [security]
     allow_embeds_from=vimeo.com *.vimeo.com youtube.com *.youtube.com www.youtube-nocookie.com
+[nginx-unit]
+    socket=/var/run/control.unit.sock

+ 3 - 2
config/nginx-unit/Makefile

@@ -1,5 +1,6 @@
 .PHONY: install
 install:
+	sudo chmod 0660 /var/run/control.unit.sock
 	export WD=`realpath "$$PWD/../.."`
 	[ -n "$$WD" ] || ( echo "cannot determine path to TCMS directory" && /bin/false )
 	[ -n "$$PERSON" ] || ( echo "Please set the PERSON environment variable before running (user to run tcms as)" && /bin/false )
@@ -7,8 +8,8 @@ install:
 	sed -e 's|__WD__|'$$WD'|g' config.json.tmp1 > config.json
 	rm config.json.tmp1
 	/bin/false
-	sudo curl -X PUT --data-binary @config.json --unix-socket /var/run/control.unit.sock http://localhost/config
+	curl -X PUT --data-binary @config.json --unix-socket /var/run/control.unit.sock http://localhost/config
 
 .PHONY: restart
 restart:
-	sudo curl -X GET --data-binary @config.json --unix-socket /var/run/control.unit.sock http://localhost/control/applications/tcms/restart
+	curl -X GET --unix-socket /var/run/control.unit.sock http://localhost/control/applications/tcms/restart

+ 11 - 2
config/nginx-unit/config.json.tmpl

@@ -2,11 +2,20 @@
    "applications" : {
       "tcms" : {
          "group" : "__USER__",
-         "processes" : 5,
          "script" : "__WD__/www/server.psgi",
          "type" : "perl",
          "user" : "__USER__",
-         "working_directory" : "__WD__"
+         "working_directory" : "__WD__",
+         "environment": {
+            "PSGI_ENGINE":"nginx-unit"
+         },
+         "limits": {
+            "requests": 1000
+         "processes": {
+            "spare": 5,
+            "max": 100,
+            "idle_timeout": 30
+         }
       }
    },
    "listeners" : {

+ 18 - 0
lib/Trog/Utils.pm

@@ -6,6 +6,10 @@ use warnings;
 no warnings 'experimental';
 use feature qw{signatures};
 
+use HTTP::Tiny::UNIX();
+use Trog::Log qw{WARN};
+use Trog::Config();
+
 # Deal with Params which may or may not be arrays
 sub coerce_array ($param) {
     my $p = $param || [];
@@ -19,4 +23,18 @@ sub strip_and_trunc ($s) {
     return substr $s, 0, 280;
 }
 
+# Instruct the parent to restart.  Normally this is HUP, but nginx-unit decides to be special.
+sub restart_parent ( $env ) {
+    if ($env->{PSGI_ENGINE} && $env->{PSGI_ENGINE} eq 'nginx-unit') {
+        my $conf = Trog::Config->get();
+        my $nginx_socket = $conf->param('nginx-unit.socket');
+        my $client = HTTP::Tiny::UNIX->new();
+        my $res = $client->request('GET', "http:$nginx_socket//control/applications/tcms/restart" );
+        WARN("could not reload application (got $res->{status} from nginx-unit)!") unless $res->{status} == 200;
+        return 1;
+    }
+    my $parent = getppid;
+    kill 'HUP', $parent;
+}
+
 1;