sockd 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/README.md +1 -1
- data/examples/piglatin.rb +36 -0
- data/lib/sockd/optparse.rb +6 -7
- data/lib/sockd/runner.rb +11 -10
- data/lib/sockd/version.rb +1 -1
- data/lib/sockd.rb +3 -2
- metadata +3 -9
- data/.vagrant/machines/default/virtualbox/action_provision +0 -1
- data/.vagrant/machines/default/virtualbox/action_set_name +0 -1
- data/.vagrant/machines/default/virtualbox/id +0 -1
- data/.vagrant/machines/default/virtualbox/index_uuid +0 -1
- data/.vagrant/machines/default/virtualbox/private_key +0 -27
- data/.vagrant/machines/default/virtualbox/synced_folders +0 -1
- data/Vagrantfile +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c93b6cac5618173e86c540e2446d38951fe8d850
|
4
|
+
data.tar.gz: 8fec53e267e784fff36b0590f29d229ab2f5cec1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a194fe567ce9591b13df3148a7f4f10b388e13bd3c70a95477db1e0f575113b2e5555d7fe1a326a9d2d0402028e930e20da5ee7cb5a0cca437c0d8faa82136bc
|
7
|
+
data.tar.gz: ea83519987f2cffe4798a6e7622cc93304e2c61abf24b4396f3e47a8965ffec6c2e5222ec0ecc73c19da360a8b7a48ea3674786ffb30aa2a1977eaa62dc0e4cc
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -24,7 +24,7 @@ TODO: Write usage instructions here
|
|
24
24
|
|
25
25
|
## Contributing
|
26
26
|
|
27
|
-
1. Fork it ( https://github.com/
|
27
|
+
1. Fork it ( https://github.com/pixelcog/sockd/fork )
|
28
28
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
29
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
30
|
4. Push to the branch (`git push origin my-new-feature`)
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'sockd'
|
4
|
+
|
5
|
+
# run a daemon bound to localhost port 23456
|
6
|
+
Sockd.run 'piglatin', pid_path: '/tmp/piglatin.pid', port: 23456 do |sockd|
|
7
|
+
|
8
|
+
sockd.options = {
|
9
|
+
port: 12123
|
10
|
+
}
|
11
|
+
|
12
|
+
sockd.handle do |message, socket|
|
13
|
+
|
14
|
+
# translate a message into pig-latin
|
15
|
+
translated = message.chomp.split(' ').map do |str|
|
16
|
+
alpha = ('a'..'z').to_a
|
17
|
+
vowels = %w[a e i o u]
|
18
|
+
consonants = alpha - vowels
|
19
|
+
|
20
|
+
if vowels.include?(str[0])
|
21
|
+
str + 'ay'
|
22
|
+
elsif consonants.include?(str[0]) && consonants.include?(str[1])
|
23
|
+
str[2..-1] + str[0..1] + 'ay'
|
24
|
+
elsif consonants.include?(str[0])
|
25
|
+
str[1..-1] + str[0] + 'ay'
|
26
|
+
else
|
27
|
+
str # return unchanged
|
28
|
+
end
|
29
|
+
end.join(' ')
|
30
|
+
|
31
|
+
# log and return the translation
|
32
|
+
sockd.log "received message: #{message}"
|
33
|
+
sockd.log "returning pig latin: #{translated}"
|
34
|
+
socket.print translated + "\r\n"
|
35
|
+
end
|
36
|
+
end
|
data/lib/sockd/optparse.rb
CHANGED
@@ -18,9 +18,8 @@ module Sockd
|
|
18
18
|
pid_path: "/var/run/#{safe_name}.pid",
|
19
19
|
log_path: false,
|
20
20
|
force: false,
|
21
|
-
user:
|
22
|
-
group:
|
23
|
-
verbose: false
|
21
|
+
user: false,
|
22
|
+
group: false
|
24
23
|
}.merge(defaults))
|
25
24
|
@callback = block if block_given?
|
26
25
|
end
|
@@ -41,7 +40,7 @@ module Sockd
|
|
41
40
|
#{name} stop [-f] stop a running daemon
|
42
41
|
#{name} restart stop, then start the daemon
|
43
42
|
#{name} send <message> send a message to a running daemon
|
44
|
-
#{name} <message> send a message (command implied)
|
43
|
+
#{name} <message> send a message (send command implied)
|
45
44
|
|
46
45
|
Options:
|
47
46
|
EOF
|
@@ -60,7 +59,7 @@ module Sockd
|
|
60
59
|
options[:socket] = nil
|
61
60
|
end
|
62
61
|
|
63
|
-
opts.on("-s", "--socket
|
62
|
+
opts.on("-s", "--socket SOCKET", String, "Listen on Unix socket path (disables network support)", "(default: #{options[:socket]})") do |x|
|
64
63
|
options[:socket] = File.expand_path(x)
|
65
64
|
end
|
66
65
|
|
@@ -72,11 +71,11 @@ module Sockd
|
|
72
71
|
options[:log_path] = File.expand_path(x)
|
73
72
|
end
|
74
73
|
|
75
|
-
opts.on("-u", "--user USER", String, "Assume the identity of USER when running as a daemon (default: #{options[:user]})") do |x|
|
74
|
+
opts.on("-u", "--user USER", String, "Assume the identity of USER when running as a daemon", "(default: #{options[:user]})") do |x|
|
76
75
|
options[:user] = x
|
77
76
|
end
|
78
77
|
|
79
|
-
opts.on("-g", "--group GROUP", String, "Assume group GROUP when running as a daemon (default: #{options[:group]})") do |x|
|
78
|
+
opts.on("-g", "--group GROUP", String, "Assume group GROUP when running as a daemon", "(default: #{options[:group]})") do |x|
|
80
79
|
options[:group] = x
|
81
80
|
end
|
82
81
|
|
data/lib/sockd/runner.rb
CHANGED
@@ -25,8 +25,8 @@ module Sockd
|
|
25
25
|
:pid_path => "/var/run/#{safe_name}.pid",
|
26
26
|
:log_path => false,
|
27
27
|
:force => false,
|
28
|
-
:user =>
|
29
|
-
:group =>
|
28
|
+
:user => false,
|
29
|
+
:group => false
|
30
30
|
}.merge(options)
|
31
31
|
|
32
32
|
[:setup, :teardown, :handle].each do |opt|
|
@@ -88,7 +88,7 @@ module Sockd
|
|
88
88
|
if options[:daemonize]
|
89
89
|
pid = daemon_running?
|
90
90
|
raise ProcError, "#{name} process already running (#{pid})" if pid
|
91
|
-
|
91
|
+
puts "starting #{name} process..."
|
92
92
|
return self unless daemonize
|
93
93
|
end
|
94
94
|
|
@@ -111,14 +111,14 @@ module Sockd
|
|
111
111
|
if daemon_running?
|
112
112
|
pid = stored_pid
|
113
113
|
Process.kill('TERM', pid)
|
114
|
-
|
114
|
+
puts "SIGTERM sent to #{name} (#{pid})"
|
115
115
|
if !wait_until(2) { daemon_stopped? pid } && options[:force]
|
116
116
|
Process.kill('KILL', pid)
|
117
|
-
|
117
|
+
puts "SIGKILL sent to #{name} (#{pid})"
|
118
118
|
end
|
119
119
|
raise ProcError.new("unable to stop #{name} process") if daemon_running?
|
120
120
|
else
|
121
|
-
|
121
|
+
warn "#{name} process not running"
|
122
122
|
end
|
123
123
|
self
|
124
124
|
end
|
@@ -148,6 +148,11 @@ module Sockd
|
|
148
148
|
puts response
|
149
149
|
end
|
150
150
|
|
151
|
+
# output a timestamped log message
|
152
|
+
def log(message)
|
153
|
+
puts Time.now.strftime('[%d-%b-%Y %H:%M:%S] ') + message
|
154
|
+
end
|
155
|
+
|
151
156
|
protected
|
152
157
|
|
153
158
|
# run a server loop, passing data off to our handler
|
@@ -334,9 +339,5 @@ module Sockd
|
|
334
339
|
end
|
335
340
|
timer > 0
|
336
341
|
end
|
337
|
-
|
338
|
-
def log(message)
|
339
|
-
puts Time.now.strftime('%Y-%m-%d %H:%M:%S: ') + message
|
340
|
-
end
|
341
342
|
end
|
342
343
|
end
|
data/lib/sockd/version.rb
CHANGED
data/lib/sockd.rb
CHANGED
@@ -17,9 +17,10 @@ module Sockd
|
|
17
17
|
|
18
18
|
# instantiate and run a sockd service using command line arguments
|
19
19
|
def self.run(name, options = {}, &block)
|
20
|
-
|
20
|
+
runner = define(name, options, &block)
|
21
|
+
parser = optparse(runner.name, runner.options)
|
21
22
|
argv = parser.parse!
|
22
|
-
|
23
|
+
runner.run(*argv)
|
23
24
|
rescue OptionParserError, BadCommandError => e
|
24
25
|
warn "Error: #{e.message}"
|
25
26
|
warn "#{parser}\n"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sockd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Greiling
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -46,17 +46,11 @@ extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
48
|
- .gitignore
|
49
|
-
- .vagrant/machines/default/virtualbox/action_provision
|
50
|
-
- .vagrant/machines/default/virtualbox/action_set_name
|
51
|
-
- .vagrant/machines/default/virtualbox/id
|
52
|
-
- .vagrant/machines/default/virtualbox/index_uuid
|
53
|
-
- .vagrant/machines/default/virtualbox/private_key
|
54
|
-
- .vagrant/machines/default/virtualbox/synced_folders
|
55
49
|
- Gemfile
|
56
50
|
- LICENSE
|
57
51
|
- README.md
|
58
52
|
- Rakefile
|
59
|
-
-
|
53
|
+
- examples/piglatin.rb
|
60
54
|
- lib/sockd.rb
|
61
55
|
- lib/sockd/errors.rb
|
62
56
|
- lib/sockd/optparse.rb
|
@@ -1 +0,0 @@
|
|
1
|
-
1.5:5b9af9bc-a6a4-4a38-bcee-3dd882a77565
|
@@ -1 +0,0 @@
|
|
1
|
-
1426302069
|
@@ -1 +0,0 @@
|
|
1
|
-
5b9af9bc-a6a4-4a38-bcee-3dd882a77565
|
@@ -1 +0,0 @@
|
|
1
|
-
c2db229506d4472b8fb6d1e0d697d20f
|
@@ -1,27 +0,0 @@
|
|
1
|
-
-----BEGIN RSA PRIVATE KEY-----
|
2
|
-
MIIEowIBAAKCAQEA7xjuC39O1pFg27/RWTeSTOwaGWqCYka1WpLBRd1nr/2mZw81
|
3
|
-
yjBGmWRwkD686TMZR+id5x+4b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AACZW56jBCH8TIo1WyYbgnFsi5br9W/JrABiiHAoGAaaTKsVWttSH0Xd9bbAd1
|
19
|
-
ngCtPCGqJkwwvBW6HHzJ9Al6Sk3DELCk0CDPSAWqfqaxCmgJHxp3Ad4Z3yertZo1
|
20
|
-
tTIKEUcRODWAzgx5owgqxNOuKzIOjCChDsCOIVLLmaIdQPeaYJF/x8qWtzZbS9Im
|
21
|
-
K/0V70sMfA457sr/GOLiWMkCgYBG4tTBm4q+2n7CZcd7G0KBE/lpgQhzU2u3vHFZ
|
22
|
-
9HLlQwpm3FEfFO0RLC4nGwVvwz1REzQymt9/wSEueZsfpdSc5PuaKPM9RnxHxoAX
|
23
|
-
Fuwl6B+uDtYs/6boLCnS5z6Oan2mkeXjKn+jPkiUaSMlypKMZKtU1IpDmIoeifFF
|
24
|
-
ytmCTQKBgHOzJIaY5b/s0mRbBGKYPT7idRWT0a1XVvAsJOTTuYNsbzGpWGcNPr+n
|
25
|
-
YmO2cl10W4YntFG3+U7uZYdEIqNK+mc1hs801dKmGdJqeBGwf0N6memJMLRZG+HX
|
26
|
-
FI8PY96eiNVJfIjG/tORr443ziJTlWJJf//pOvHEtQE54erC6ocI
|
27
|
-
-----END RSA PRIVATE KEY-----
|
@@ -1 +0,0 @@
|
|
1
|
-
{"virtualbox":{"/tmp/vagrant-opsworks":{"guestpath":"/tmp/vagrant-opsworks","hostpath":"/Users/mike/.vagrant.d/boxes/ubuntu1404-opsworks/0/virtualbox","disabled":false},"/vagrant":{"guestpath":"/vagrant","hostpath":"/Users/mike/Projects/sockd","disabled":false}}}
|
data/Vagrantfile
DELETED