syslogify 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/syslogify/forker.rb +39 -19
- data/lib/syslogify/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ff824b514a7b5f41ea8d6cae842dbb316d47d0a
|
4
|
+
data.tar.gz: fe71fcb5d549727cd8671d117612fe00469d13a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 761199098e7713764ec677c0e83f304c5b7a5a0d05eca888822c54f30459c0c8db962040cbb53b2dea72a294907da72693c52bdb4222de3d62e6759dc1e7a6fd
|
7
|
+
data.tar.gz: 18b68acc82d09618ea770c653c3510fe8dad89a78ba9c25a555643c4d38333eb0c57ce330ebd4ba8eb0be8666200e2590171e0f4daca6ab00c7fe3372f1864aa
|
data/lib/syslogify/forker.rb
CHANGED
@@ -16,19 +16,25 @@ module Syslogify
|
|
16
16
|
@pid = nil
|
17
17
|
end
|
18
18
|
|
19
|
+
# causes standard output and error to be redirected to syslog
|
20
|
+
# (through a subprocess)
|
19
21
|
def start
|
20
|
-
return if @
|
22
|
+
return if @sink
|
21
23
|
|
22
|
-
|
24
|
+
drain, @sink = IO.pipe
|
23
25
|
@old_stdout = STDOUT.dup
|
24
26
|
@old_stderr = STDERR.dup
|
25
27
|
|
28
|
+
# Test connection to syslog in the parent process
|
26
29
|
Syslog.open(_identity, Syslog::LOG_CONS | Syslog::LOG_NDELAY)
|
27
30
|
Syslog.log(Syslog::LOG_NOTICE, 'Diverting logs to syslog')
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
+
# spawn a subprocess which pipes from its standard input to syslog
|
33
|
+
pid = fork do
|
34
|
+
Process.daemon # otherwise we'll intercept signals
|
35
|
+
$PROGRAM_NAME = "#{Syslog.ident}.syslogify"
|
36
|
+
STDIN.reopen(drain)
|
37
|
+
@sink.close
|
32
38
|
|
33
39
|
while line = STDIN.gets
|
34
40
|
Syslog.log(Syslog::LOG_NOTICE, line.gsub('%', '%%'))
|
@@ -36,33 +42,47 @@ module Syslogify
|
|
36
42
|
Syslog.log(Syslog::LOG_NOTICE, 'Shutting down')
|
37
43
|
end
|
38
44
|
|
39
|
-
|
45
|
+
Process.detach(pid) # the subprocess will shut down on its own once starved of input
|
46
|
+
Syslog.close # the parent does not need syslog access
|
40
47
|
|
41
|
-
|
42
|
-
|
43
|
-
|
48
|
+
# redirect stdout/err to the subprocess
|
49
|
+
drain.close
|
50
|
+
STDOUT.reopen(@sink)
|
51
|
+
STDERR.reopen(@sink)
|
44
52
|
STDOUT.sync = STDERR.sync = true
|
45
|
-
|
46
|
-
|
53
|
+
|
54
|
+
begin
|
55
|
+
@old_stderr.puts('Check syslog for further messages')
|
56
|
+
rescue Errno::EPIPE
|
57
|
+
# this can happen if something else tampered with our @old streams,
|
58
|
+
# e.g. the daemons library
|
59
|
+
end
|
47
60
|
self
|
48
61
|
end
|
49
62
|
|
63
|
+
# cancels the outout redirection
|
50
64
|
def stop
|
51
|
-
return unless @
|
52
|
-
|
53
|
-
|
65
|
+
return unless @sink
|
66
|
+
# NOTE: we shouldn't kill the subprocess (which can be shared igqf the parent
|
67
|
+
# forked after #start), and it'll shut down on its own anyways.
|
68
|
+
STDOUT.reopen(@old_stdout) unless @old_stdout.closed?
|
69
|
+
STDERR.reopen(@old_stderr) unless @old_stderr.closed?
|
70
|
+
@sink.close unless @sink.closed?
|
54
71
|
@old_stdout = @old_stderr = nil
|
55
|
-
|
56
|
-
Process.kill('TERM', @pid)
|
57
|
-
Process.wait(@pid)
|
58
|
-
@pid = nil
|
72
|
+
@sink = nil
|
59
73
|
self
|
60
74
|
end
|
61
75
|
|
76
|
+
# useful when e.g. the process name changes, and/or after forking
|
77
|
+
def restart
|
78
|
+
stop
|
79
|
+
start
|
80
|
+
end
|
81
|
+
|
62
82
|
private
|
63
83
|
|
64
84
|
def _identity
|
65
|
-
|
85
|
+
ENV.fetch('SYSLOG_IDENTITY', File.basename($PROGRAM_NAME))
|
66
86
|
end
|
67
87
|
end
|
68
88
|
end
|
data/lib/syslogify/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syslogify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julien Letessier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|