taskclient 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/bin/taskclient +16 -0
- data/lib/taskclient/task_client.rb +87 -0
- data/lib/taskclient/worker/backup_worker.rb +31 -0
- data/lib/taskclient.rb +2 -0
- data/test/helper.rb +10 -0
- data/test/test_taskclient.rb +7 -0
- metadata +70 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Alexandre da Silva
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= taskclient
|
2
|
+
|
3
|
+
A client XMPP task runner for remote administration of any remote stuff.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Alexandre da Silva. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "taskclient"
|
8
|
+
gem.summary = "Execute admin tasks on client"
|
9
|
+
gem.description = "Remotely admin client machines using XMPP"
|
10
|
+
gem.email = "lexrupy@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/lexrupy/taskclient"
|
12
|
+
gem.authors = ["Alexandre da Silva"]
|
13
|
+
gem.files = FileList["[A-Z]*", "{lib}/**/*"]
|
14
|
+
#gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
Rake::TestTask.new(:test) do |test|
|
24
|
+
test.libs << 'lib' << 'test'
|
25
|
+
test.pattern = 'test/**/test_*.rb'
|
26
|
+
test.verbose = true
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
require 'rcov/rcovtask'
|
31
|
+
Rcov::RcovTask.new do |test|
|
32
|
+
test.libs << 'test'
|
33
|
+
test.pattern = 'test/**/test_*.rb'
|
34
|
+
test.verbose = true
|
35
|
+
end
|
36
|
+
rescue LoadError
|
37
|
+
task :rcov do
|
38
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
task :test => :check_dependencies
|
43
|
+
|
44
|
+
task :default => :test
|
45
|
+
|
46
|
+
require 'rake/rdoctask'
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
49
|
+
|
50
|
+
rdoc.rdoc_dir = 'rdoc'
|
51
|
+
rdoc.title = "taskclient #{version}"
|
52
|
+
rdoc.rdoc_files.include('README*')
|
53
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
data/bin/taskclient
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
3
|
+
require 'rubygems'
|
4
|
+
require 'taskclient'
|
5
|
+
|
6
|
+
# Load the configuration
|
7
|
+
TaskClient.load_config(ARGV[0])
|
8
|
+
|
9
|
+
# Create the client instance
|
10
|
+
task_client = TaskClient.new
|
11
|
+
# Trap Interrupt signal
|
12
|
+
trap("INT") { task_client.finalize }
|
13
|
+
# Start the client process
|
14
|
+
task_client.listen
|
15
|
+
# Go away
|
16
|
+
puts "Bye..."
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'xmpp4r-simple'
|
2
|
+
require 'eventmachine'
|
3
|
+
require 'yaml'
|
4
|
+
require "taskclient/worker/backup_worker"
|
5
|
+
|
6
|
+
class TaskClient
|
7
|
+
|
8
|
+
include Jabber
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
log 'Initializing check client...'
|
12
|
+
@jb_client = Simple.new(TaskClient.config('user'), TaskClient.config('password'))
|
13
|
+
at_exit do
|
14
|
+
@jb_client.status(:away, "Done all jobs for now...")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.load_config(file)
|
19
|
+
@@config = YAML.load_file(file)
|
20
|
+
end
|
21
|
+
|
22
|
+
def log(str)
|
23
|
+
puts str
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.config(conf)
|
27
|
+
if conf.is_a? Array
|
28
|
+
conf.map {|c| @@config[c] }
|
29
|
+
else
|
30
|
+
@@config[conf]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def finalize
|
35
|
+
@jb_client.status(:away, "finalizing...")
|
36
|
+
sleep 2
|
37
|
+
EM.stop
|
38
|
+
end
|
39
|
+
|
40
|
+
def listen
|
41
|
+
log "start listening..."
|
42
|
+
EM.run do
|
43
|
+
EM::PeriodicTimer.new(60) do
|
44
|
+
puts "update status"
|
45
|
+
@jb_client.status nil, ""
|
46
|
+
end
|
47
|
+
EM::PeriodicTimer.new(1) do
|
48
|
+
@jb_client.received_messages do |message|
|
49
|
+
client = @jb_client
|
50
|
+
command = message.body.split('|').first
|
51
|
+
doit, task_name = command.first.split('_')
|
52
|
+
args = command[1..-1]
|
53
|
+
if doit == 'do'
|
54
|
+
method = 'task'
|
55
|
+
begin
|
56
|
+
worker_class = Object.module_eval("::#{task_name.capitalize}Worker")
|
57
|
+
rescue
|
58
|
+
method = "invalid"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
case method
|
62
|
+
when "exit": EM.stop
|
63
|
+
when "task":
|
64
|
+
log "#{task_name} command received"
|
65
|
+
EM.spawn do
|
66
|
+
worker = worker_class.new
|
67
|
+
worker.callback do
|
68
|
+
client.deliver(message.from, "#{doit}_#{task_name}.DONE")
|
69
|
+
end
|
70
|
+
begin
|
71
|
+
worker.do
|
72
|
+
rescue => e
|
73
|
+
client.deliver(message.from, "#{doit}_#{task_name}.ERROR")
|
74
|
+
client.deliver(message.from, "#{e.message}\n#{e.backtrace}")
|
75
|
+
end
|
76
|
+
end.notify
|
77
|
+
client.deliver message.from, "#{doit}_#{task_name}.OK"
|
78
|
+
else
|
79
|
+
log "invalid command received: #{doit}_#{task_name}"
|
80
|
+
client.deliver(message.from, "invalid command [ #{message.body} ] ERROR")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'net/ftp'
|
2
|
+
|
3
|
+
class BackupWorker
|
4
|
+
include EM::Deferrable
|
5
|
+
|
6
|
+
def do
|
7
|
+
db, bkp = TaskClient.config(["database","bkpfile"])
|
8
|
+
bkp7z = "#{bkp}.7z"
|
9
|
+
usr, pwd, ftps, ftpu, ftpp = TaskClient.config(['dbuser','dbpassword','ftpserver','ftpuser','ftppassword'])
|
10
|
+
backup_cmd = "gbak -B #{db} #{bkp} -USER #{usr} -PAS #{pwd}"
|
11
|
+
compress_cmd = "7z a #{bkp7z} #{bkp}"
|
12
|
+
if File.exists? bkp
|
13
|
+
File.delete bkp
|
14
|
+
end
|
15
|
+
system backup_cmd
|
16
|
+
system compress_cmd
|
17
|
+
puts "Starting file transfer...."
|
18
|
+
Net::FTP.open(ftps) do |ftp|
|
19
|
+
ftp.login(ftpu,ftpp)
|
20
|
+
ftp.passive = true
|
21
|
+
ftp.putbinaryfile(bkp7z)
|
22
|
+
ftp.quit
|
23
|
+
end
|
24
|
+
puts "delete local backup file..."
|
25
|
+
File.delete bkp
|
26
|
+
File.delete bkp7z
|
27
|
+
puts 'DONE'
|
28
|
+
set_deferred_status :succeeded
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/lib/taskclient.rb
ADDED
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: taskclient
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Alexandre da Silva
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-03-21 00:00:00 -03:00
|
18
|
+
default_executable: taskclient
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Remotely admin client machines using XMPP
|
22
|
+
email: lexrupy@gmail.com
|
23
|
+
executables:
|
24
|
+
- taskclient
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- LICENSE
|
29
|
+
- README.rdoc
|
30
|
+
files:
|
31
|
+
- LICENSE
|
32
|
+
- README.rdoc
|
33
|
+
- Rakefile
|
34
|
+
- VERSION
|
35
|
+
- lib/taskclient.rb
|
36
|
+
- lib/taskclient/task_client.rb
|
37
|
+
- lib/taskclient/worker/backup_worker.rb
|
38
|
+
has_rdoc: true
|
39
|
+
homepage: http://github.com/lexrupy/taskclient
|
40
|
+
licenses: []
|
41
|
+
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options:
|
44
|
+
- --charset=UTF-8
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.3.6
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Execute admin tasks on client
|
68
|
+
test_files:
|
69
|
+
- test/helper.rb
|
70
|
+
- test/test_taskclient.rb
|