Package: libserver-starter-perl / 0.17-2

0002-Fix-loading-envdir.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
From 6d965848ff8905f82da0f1ac142000b12a05905e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Mon, 16 Jun 2014 17:25:08 +0200
Subject: [PATCH 2/2] Fix loading envdir
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The envdir was scanned each second regardless of signal received. This
caused random failures of the 'removed env' t/07-envdir.t test.

This patch fixes it by loading the environment only just before
intended restart. It also documents this start_server() option.

Signed-off-by: Petr Písař <ppisar@redhat.com>
---
 lib/Server/Starter.pm | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/lib/Server/Starter.pm b/lib/Server/Starter.pm
index 47bc18a..c171307 100644
--- a/lib/Server/Starter.pm
+++ b/lib/Server/Starter.pm
@@ -179,15 +179,13 @@ sub start_server {
     
     # the main loop
     my $term_signal = 0;
-    $current_worker = _start_worker($opts);
+    my %loaded_env;
+    $current_worker = _start_worker($opts, \%loaded_env);
     $update_status->();
     my $auto_restart_interval = 0;
     my $last_restart_time = time();
     my $restart_flag = 0;
     while (1) {
-        my %loaded_env = _reload_env();
-        my @loaded_env_keys = keys %loaded_env;
-        local @ENV{@loaded_env_keys} = map { $loaded_env{$_} } (@loaded_env_keys);
         if ($ENV{ENABLE_AUTO_RESTART}) {
             # restart workers periodically
             $auto_restart_interval = $ENV{AUTO_RESTART_INTERVAL} ||= 360;
@@ -201,7 +199,7 @@ sub start_server {
             last if ($died_worker <= 0);
             if ($died_worker == $current_worker) {
                 print STDERR "worker $died_worker died unexpectedly with status:$status, restarting\n";
-                $current_worker = _start_worker($opts);
+                $current_worker = _start_worker($opts, \%loaded_env);
                 $last_restart_time = time();
             } else {
                 print STDERR "old worker $died_worker died, status:$status\n";
@@ -232,9 +230,10 @@ sub start_server {
             }
         }
         if ($restart_flag > 1 || ($restart_flag > 0 && $num_old_workers == 0)) {
+            %loaded_env = _reload_env();
             print STDERR "spawning a new worker (num_old_workers=$num_old_workers)\n";
             $old_workers{$current_worker} = $ENV{SERVER_STARTER_GENERATION};
-            $current_worker = _start_worker($opts);
+            $current_worker = _start_worker($opts, \%loaded_env);
             $last_restart_time = time();
             $restart_flag = 0;
             $update_status->();
@@ -342,7 +341,7 @@ sub _reload_env {
 }
 
 sub _start_worker {
-    my $opts = shift;
+    my ($opts, $loaded_env) = @_;
     my $pid;
     while (1) {
         $ENV{SERVER_STARTER_GENERATION}++;
@@ -350,6 +349,8 @@ sub _start_worker {
         die "fork(2) failed:$!"
             unless defined $pid;
         if ($pid == 0) {
+            my @loaded_env_keys = keys %$loaded_env;
+            @ENV{@loaded_env_keys} = map { $loaded_env->{$_} } (@loaded_env_keys);
             my @args = @{$opts->{exec}};
             # child process
             if (defined $opts->{dir}) {
@@ -418,9 +419,21 @@ A Net::Server personality that can be run under L<Server::Starter> exists under
 
 Returns zero or more file descriptors on which the server program should call accept(2) in a hashref.  Each element of the hashref is: (host:port|port|path_of_unix_socket) => file_descriptor.
 
-=item start_server
+=item start_server(%options)
 
-Starts the superdaemon.  Used by the C<start_server> script.
+Starts the superdaemon.  Used by the C<start_server> script. Options are:
+
+=over 4
+
+=item envdir
+
+Defines a directory whose content is added into server's environment. Each file name specifies an environment variable, the file's content specifies a value of the environment variable. Files with names starting with a dot are ignored.  
+
+The environment directory is scanned and read only on time-based autorestart or SIGHUP signal. The first server instances have default environment. To remove an enviroment variable added before, remove the file and send the signal.
+
+This option is not mandatory.
+
+=back
 
 =back
 
-- 
1.9.3