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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f68f3a2116561ffd7fc5101c67fda661e884e78a
4
- data.tar.gz: 46ebcbfd7636d55685c63b7de5a3afe983cbd6e1
3
+ metadata.gz: c93b6cac5618173e86c540e2446d38951fe8d850
4
+ data.tar.gz: 8fec53e267e784fff36b0590f29d229ab2f5cec1
5
5
  SHA512:
6
- metadata.gz: 0e6b7cc336524b6b8a0a83598be660fd361d53c704c496cec8637f57526c1b48c5fbebd1a3201722874ed45673bfdcd5ff6a4e662c20df7d860a6080721c6be5
7
- data.tar.gz: e04246c93263fd5f5571d33ab9ed87237f50c73c2c18cb2c88fe2bd3576926fa907ba183e34390673e1343a64d7b83286f21c20c28796c0fb942246642217d82
6
+ metadata.gz: a194fe567ce9591b13df3148a7f4f10b388e13bd3c70a95477db1e0f575113b2e5555d7fe1a326a9d2d0402028e930e20da5ee7cb5a0cca437c0d8faa82136bc
7
+ data.tar.gz: ea83519987f2cffe4798a6e7622cc93304e2c61abf24b4396f3e47a8965ffec6c2e5222ec0ecc73c19da360a8b7a48ea3674786ffb30aa2a1977eaa62dc0e4cc
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  /.bundle/
2
+ /.vagrant/
2
3
  /.yardoc
3
4
  /Gemfile.lock
4
5
  /_yardoc/
@@ -7,8 +8,9 @@
7
8
  /pkg/
8
9
  /spec/reports/
9
10
  /tmp/
11
+ Vagrantfile
10
12
  *.bundle
11
13
  *.so
12
14
  *.o
13
15
  *.a
14
- mkmf.log
16
+ mkmf.log
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/[my-github-username]/sockd/fork )
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
@@ -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: nil,
22
- group: nil,
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 [SOCKET]", String, "Listen on Unix socket path (disables network support)", "(default: #{options[:socket]})") do |x|
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 => nil,
29
- :group => nil
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
- log "starting #{name} process..."
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
- log "SIGTERM sent to #{name} (#{pid})"
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
- log "SIGKILL sent to #{name} (#{pid})"
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
- log "#{name} process not running"
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
@@ -1,3 +1,3 @@
1
1
  module Sockd
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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
- parser = optparse(name, options)
20
+ runner = define(name, options, &block)
21
+ parser = optparse(runner.name, runner.options)
21
22
  argv = parser.parse!
22
- define(name, options, &block).run(*argv)
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.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-18 00:00:00.000000000 Z
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
- - Vagrantfile
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+4bDTE9VasiZ3OU9EX6thL+8epVPdkBBRaQqluXHzW
4
- soLZ1sP8GprJkTMEzUJyBPiVEl/feVW55yzTHWAgDUWWrp4qd7VvRmk4e0W25NRF
5
- 69EMMvHMaFneHYJZ9BiDh2w2OAM1ehdyHU4ruWm8UTjwEzpT98fJSsUhBcColtZT
6
- J7+cN8ksSiaihUlbJjzSS36CWrX5jBXyE4RYCFSEoHzp3vdO756j9bQqfdqMLfS4
7
- 25C2azX6bQehlR3eSxK5CHixgzcWyyb2ZnT5TQIDAQABAoIBAQDB9BwuMXCXuEi1
8
- Gi5NzDmesqwdT/xCko9M0N19ujQBXKae1YTR5kVu6z4wlOQT3AK3BWkJ8v5csJXR
9
- WyUNYXjdHzHirOE+dmHTbfexI31wtBa1agOTvXfOsx8Pyd6XLabIhw0NIUV0KVeU
10
- CsmKUR9UpgR6H6gzMFTM1N5WZMaPn5VatDCv8/1n3wju+7CHClPuPdYfAoNNTPY0
11
- uIMkMVwguO9EjgNit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IVATE 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
@@ -1,4 +0,0 @@
1
- Vagrant.configure("2") do |config|
2
- config.vm.box = "ubuntu1404-opsworks"
3
- config.vm.network "private_network", ip: "10.10.10.11"
4
- end