mobot 2013.08.1377443265 → 2013.08.1377443804
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/bin/mobot +4 -0
- data/bin/mobot-server +3 -0
- data/lib/mobot.rb +2 -0
- data/lib/mobot/client.rb +13 -0
- data/lib/mobot/server.rb +44 -0
- metadata +9 -5
- data/bin/mobot-server.rb +0 -41
- data/bin/mobot.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e7b6925b1110d96af50652e9cce69d0d682e7b6
|
4
|
+
data.tar.gz: 6edb85ed86783b5d57cf5273bbc201559f5dd9ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2703b747c09378b3d3c864e1e262a46f3fd7178aa5457a34d674eef6de99c9db150c0b7aaa365548e61502ea8128dd493fd9ad69fd79458480625801249c819
|
7
|
+
data.tar.gz: 78b93c693b2218c18e520e6bb65eeb667a44724cdcca329c084d35917977b8a8a7f4fd2d2ee57145337cb2bd25e4352f72803903c94e7e6b4100df09b29edc23
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
mobot
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0-p247
|
data/bin/mobot
ADDED
data/bin/mobot-server
ADDED
data/lib/mobot.rb
CHANGED
data/lib/mobot/client.rb
ADDED
data/lib/mobot/server.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require "socket"
|
2
|
+
|
3
|
+
module Mobot
|
4
|
+
class Server
|
5
|
+
SOCKET_FILE = '/tmp/mobot.sock'
|
6
|
+
def self.start
|
7
|
+
lock_file = File.open('/tmp/mobot.lock', 'w')
|
8
|
+
|
9
|
+
if lock_file.flock(File::LOCK_EX | File::LOCK_NB)
|
10
|
+
server = UNIXServer.new(SOCKET_FILE)
|
11
|
+
|
12
|
+
parent_process_id = Process.pid
|
13
|
+
at_exit do
|
14
|
+
File.unlink(SOCKET_FILE) if Process.pid == parent_process_id
|
15
|
+
end
|
16
|
+
|
17
|
+
trap(:INT) { exit }
|
18
|
+
|
19
|
+
puts "mobot reporting for duty"
|
20
|
+
|
21
|
+
loop do
|
22
|
+
client = server.accept
|
23
|
+
command = client.read
|
24
|
+
|
25
|
+
pid = fork do
|
26
|
+
$stdout.reopen(client)
|
27
|
+
puts "mobot received command: #{command}"
|
28
|
+
begin
|
29
|
+
exec(command)
|
30
|
+
rescue Exception => e
|
31
|
+
puts "something very bad happended. #{e.message}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
Process.wait(pid)
|
36
|
+
client.close
|
37
|
+
end
|
38
|
+
else
|
39
|
+
# exit
|
40
|
+
p "there can only be one. bye bye."
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mobot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2013.08.
|
4
|
+
version: 2013.08.1377443804
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mo khan
|
@@ -42,19 +42,23 @@ description: a simple robot
|
|
42
42
|
email:
|
43
43
|
- mo@mokhan.ca
|
44
44
|
executables:
|
45
|
-
- mobot
|
46
|
-
- mobot
|
45
|
+
- mobot
|
46
|
+
- mobot-server
|
47
47
|
extensions: []
|
48
48
|
extra_rdoc_files: []
|
49
49
|
files:
|
50
50
|
- .gitignore
|
51
|
+
- .ruby-gemset
|
52
|
+
- .ruby-version
|
51
53
|
- Gemfile
|
52
54
|
- LICENSE.txt
|
53
55
|
- README.md
|
54
56
|
- Rakefile
|
55
|
-
- bin/mobot
|
56
|
-
- bin/mobot
|
57
|
+
- bin/mobot
|
58
|
+
- bin/mobot-server
|
57
59
|
- lib/mobot.rb
|
60
|
+
- lib/mobot/client.rb
|
61
|
+
- lib/mobot/server.rb
|
58
62
|
- lib/mobot/version.rb
|
59
63
|
- mobot.gemspec
|
60
64
|
homepage: ''
|
data/bin/mobot-server.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require "socket"
|
3
|
-
|
4
|
-
SOCKET_FILE = '/tmp/mobot.sock'
|
5
|
-
|
6
|
-
lock_file = File.open('/tmp/mobot.lock', 'w')
|
7
|
-
|
8
|
-
if lock_file.flock(File::LOCK_EX | File::LOCK_NB)
|
9
|
-
server = UNIXServer.new(SOCKET_FILE)
|
10
|
-
|
11
|
-
parent_process_id = Process.pid
|
12
|
-
at_exit do
|
13
|
-
File.unlink(SOCKET_FILE) if Process.pid == parent_process_id
|
14
|
-
end
|
15
|
-
|
16
|
-
trap(:INT) { exit }
|
17
|
-
|
18
|
-
puts "mobot reporting for duty"
|
19
|
-
|
20
|
-
loop do
|
21
|
-
client = server.accept
|
22
|
-
command = client.read
|
23
|
-
|
24
|
-
pid = fork do
|
25
|
-
$stdout.reopen(client)
|
26
|
-
puts "mobot received command: #{command}"
|
27
|
-
begin
|
28
|
-
exec(command)
|
29
|
-
rescue Exception => e
|
30
|
-
puts "something very bad happended. #{e.message}"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
Process.wait(pid)
|
35
|
-
client.close
|
36
|
-
end
|
37
|
-
else
|
38
|
-
# exit
|
39
|
-
p "there can only be one. bye bye."
|
40
|
-
end
|
41
|
-
|