mnky 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/mnky +3 -0
- data/bin/monkey +3 -0
- data/lib/helpers/computer.rb +62 -0
- data/lib/helpers/file_paths.rb +18 -0
- data/lib/helpers/init.rb +2 -0
- data/lib/monkey.rb +144 -0
- data/lib/monkey/clock.rb +32 -0
- data/lib/monkey/config.rb +40 -0
- data/lib/monkey/service.rb +16 -0
- data/lib/monkey/task.rb +35 -0
- data/lib/monkey/triggers.rb +41 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2dc248b9fa03c3713992dbcd3e8ed6a159d80715
|
4
|
+
data.tar.gz: ad5219227fb825d06e71a45a4f0b0e9c1e7faf84
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1100f26fafcaba1eedaa1e5473bdcb8353ca4aeb038aaa9d6c6d34e974e1ccc43c662552a5c104f52f31861c9fd705d2493923c2da1fa27311538e996aa9ed9c
|
7
|
+
data.tar.gz: 96113594de413f3767ea0989c5d363b6ababd4b902bd49a993075cd0919a9b4704f0851e109e80720a9d1a000ed7671733599f61862c07df083b3e613bf68520
|
data/bin/mnky
ADDED
data/bin/monkey
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
3
|
+
module Monkey
|
4
|
+
|
5
|
+
class Computer
|
6
|
+
def self.os
|
7
|
+
return :windows if /cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM
|
8
|
+
return :osx if /darwin/ =~ RUBY_PLATFORM
|
9
|
+
return nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.windows?
|
13
|
+
os == :windows
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.osx?
|
17
|
+
os == :osx
|
18
|
+
end
|
19
|
+
|
20
|
+
self.singleton_class.send(:alias_method, :mac?, :osx?)
|
21
|
+
|
22
|
+
def self.os_version_number
|
23
|
+
if windows?
|
24
|
+
win_ver = `ver`
|
25
|
+
return win_ver.scan(/[\d.]+/).first
|
26
|
+
end
|
27
|
+
return `sw_vers -productVersion` if mac?
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.os_major_version
|
31
|
+
ver = os_version_number
|
32
|
+
return :windows8 if (ver.include? '6.3') || (ver.include? '6.2')
|
33
|
+
return :windows7 if ver.include? '6.1'
|
34
|
+
return :windowsvista if ver.include? '6.0'
|
35
|
+
return :windowsxp if (ver.include? '5.2') || (ver.include? '5.1')
|
36
|
+
return :windows2000 if ver.include? '5.00'
|
37
|
+
|
38
|
+
return :osxmavericks if ver.include? '10.9'
|
39
|
+
return :osxmountainlion if ver.include? '10.8'
|
40
|
+
return :osxlion if ver.include? '10.7'
|
41
|
+
return :osxsnowleopard if ver.include? '10.6'
|
42
|
+
return :osxleopard if ver.include? '10.5'
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.name
|
46
|
+
Socket.gethostname
|
47
|
+
end
|
48
|
+
|
49
|
+
# From http://coderrr.wordpress.com/2008/05/28/get-your-local-ip-address/
|
50
|
+
def self.ip
|
51
|
+
orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true # turn off reverse DNS resolution temporarily
|
52
|
+
|
53
|
+
UDPSocket.open do |s|
|
54
|
+
s.connect '64.233.187.99', 1
|
55
|
+
s.addr.last
|
56
|
+
end
|
57
|
+
ensure
|
58
|
+
Socket.do_not_reverse_lookup = orig
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Monkey
|
2
|
+
|
3
|
+
class FilePaths
|
4
|
+
def self.root
|
5
|
+
if Computer.windows?
|
6
|
+
Dir.pwd.scan(/\w:\//).first
|
7
|
+
else
|
8
|
+
'/'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.hosts_file
|
13
|
+
return File.join(root, 'windows/system32/drivers/etc/hosts') if Computer.windows?
|
14
|
+
return '/private/etc/hosts' if Computer.mac?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/lib/helpers/init.rb
ADDED
data/lib/monkey.rb
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'active_support/core_ext/string/inflections'
|
3
|
+
|
4
|
+
require_relative 'monkey/config.rb'
|
5
|
+
|
6
|
+
module Monkey
|
7
|
+
|
8
|
+
# def self.init_win_service
|
9
|
+
# require 'win32/service'
|
10
|
+
# include Win32
|
11
|
+
# end
|
12
|
+
|
13
|
+
# def self.init_win_task_scheduler
|
14
|
+
# require 'win32/taskscheduler'
|
15
|
+
# include Win32
|
16
|
+
# end
|
17
|
+
|
18
|
+
class CLI < Thor
|
19
|
+
include Thor::Actions
|
20
|
+
|
21
|
+
def self.exit_on_failure?; true; end
|
22
|
+
|
23
|
+
desc 'see [DIRECTORY]', 'Register DIRECTORY as a task suite'
|
24
|
+
def see(dir='')
|
25
|
+
full_dir = File.expand_path(dir)
|
26
|
+
|
27
|
+
config = Config.new
|
28
|
+
|
29
|
+
if config.empty?
|
30
|
+
config['task_suites'] = [ full_dir ]
|
31
|
+
else
|
32
|
+
task_suites = config['task_suites']
|
33
|
+
exit if task_suites.include? full_dir
|
34
|
+
task_suites << full_dir
|
35
|
+
end
|
36
|
+
|
37
|
+
config.save!
|
38
|
+
end
|
39
|
+
|
40
|
+
desc 'unsee [DIRECTORY]', 'Deregister DIRECTORY as a task suite'
|
41
|
+
def unsee(dir='')
|
42
|
+
full_dir = File.expand_path(dir)
|
43
|
+
|
44
|
+
config = Config.new
|
45
|
+
|
46
|
+
unless config.empty?
|
47
|
+
task_suites = config['task_suites']
|
48
|
+
task_suites.delete full_dir
|
49
|
+
end
|
50
|
+
|
51
|
+
config.save!
|
52
|
+
end
|
53
|
+
|
54
|
+
desc 'do [TASKS]', 'Run TASKS in sequence'
|
55
|
+
def do(*tasks)
|
56
|
+
require_relative 'monkey/clock.rb'
|
57
|
+
|
58
|
+
tasks = Task.tasks if tasks.empty?
|
59
|
+
|
60
|
+
tasks.each do |task|
|
61
|
+
Monkey.const_get(task.to_s.camelize).new
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
desc 'start', 'Start Monkey process, running tasks when triggered'
|
66
|
+
def start
|
67
|
+
current_dir = File.expand_path(File.dirname(__FILE__))
|
68
|
+
Dir.chdir current_dir
|
69
|
+
exec("clockwork monkey/clock.rb")
|
70
|
+
end
|
71
|
+
|
72
|
+
# desc 'startup', 'Setup Monkey to run at startup.'
|
73
|
+
# def startup
|
74
|
+
# require_relative 'helpers/computer.rb'
|
75
|
+
|
76
|
+
# abort 'This is only supported on Windows for now.' unless Computer.windows?
|
77
|
+
# Monkey.init_win_task_scheduler
|
78
|
+
# current_dir = File.expand_path(File.dirname(__FILE__))
|
79
|
+
|
80
|
+
# #username = ask('What user account would you like to use to run Monkey?')
|
81
|
+
# #domain = ask('What domain is the user account in?')
|
82
|
+
|
83
|
+
# ts = Monkey::TaskScheduler.new
|
84
|
+
# now = Time.now
|
85
|
+
# trigger = {
|
86
|
+
# start_year: now.year,
|
87
|
+
# start_month: now.month,
|
88
|
+
# start_day: now.day,
|
89
|
+
# start_hour: now.hour,
|
90
|
+
# start_minute: now.min,
|
91
|
+
# trigger_type: Monkey::TaskScheduler::TASK_EVENT_TRIGGER_AT_SYSTEMSTART
|
92
|
+
# }
|
93
|
+
# ts.new_work_item('Monkey', trigger)
|
94
|
+
# ts.application_name = "#{`where ruby`.chomp}"
|
95
|
+
# ts.parameters = "-C #{current_dir} monkey.rb start"
|
96
|
+
# #ts.set_machine(Socket.gethostname, username, domain)
|
97
|
+
# p ts.set_account_information('Moo', 'test')
|
98
|
+
# ts.activate('Monkey')
|
99
|
+
# end
|
100
|
+
|
101
|
+
# desc 'bg', 'Run Monkey as a daemon or Windows service, configured to run automatically at start up'
|
102
|
+
# def bg
|
103
|
+
# require_relative 'helpers/computer.rb'
|
104
|
+
|
105
|
+
# abort 'This is only supported on Windows for now.' unless Computer.windows?
|
106
|
+
# Monkey.init_win_service
|
107
|
+
# current_dir = File.expand_path(File.dirname(__FILE__))
|
108
|
+
# monkey_dir = File.join(current_dir, 'monkey')
|
109
|
+
|
110
|
+
# Monkey::Service.create({
|
111
|
+
# service_name: 'Monkey',
|
112
|
+
# host: nil,
|
113
|
+
# service_type: Monkey::Service::WIN32_OWN_PROCESS,
|
114
|
+
# description: 'Monkey is an IT automation and scripting framework for Ruby.',
|
115
|
+
# start_type: Monkey::Service::AUTO_START,
|
116
|
+
# error_control: Monkey::Service::ERROR_NORMAL,
|
117
|
+
# binary_path_name: "#{`where ruby`.chomp} -C #{monkey_dir} service.rb",
|
118
|
+
# load_order_group: 'Network',
|
119
|
+
# dependencies: nil,
|
120
|
+
# display_name: 'Monkey'
|
121
|
+
# })
|
122
|
+
|
123
|
+
# Monkey::Service.start 'Monkey'
|
124
|
+
# end
|
125
|
+
|
126
|
+
# desc 'bgpause', 'Stop the Monkey daemon until it is started again'
|
127
|
+
# def bgpause
|
128
|
+
|
129
|
+
# end
|
130
|
+
|
131
|
+
# desc 'bgstop', 'Deregister the daemon or Windows service'
|
132
|
+
# def bgstop
|
133
|
+
# require_relative 'helpers/computer.rb'
|
134
|
+
# abort 'This is only supported on Windows for now.' unless Computer.windows?
|
135
|
+
# Monkey.init_win_service
|
136
|
+
# `sc stop testservice`
|
137
|
+
# Monkey::Service.delete 'Monkey'
|
138
|
+
# end
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
Monkey::CLI.start(ARGV)
|
data/lib/monkey/clock.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'clockwork'
|
2
|
+
require 'active_support/core_ext/string/inflections'
|
3
|
+
|
4
|
+
require_relative 'config.rb'
|
5
|
+
|
6
|
+
module Clockwork
|
7
|
+
handler do |task_name|
|
8
|
+
Kernel.const_get(task_name.camelize).new
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module Monkey
|
13
|
+
def self.init_task_suite
|
14
|
+
dirs = [ Dir.pwd ]
|
15
|
+
|
16
|
+
config = Config.new
|
17
|
+
dirs.concat(config['task_suites']) unless config['task_suites'].nil?
|
18
|
+
|
19
|
+
dirs.each do |dir|
|
20
|
+
helpers_path = File.join(dir, 'helpers/**/*.rb')
|
21
|
+
tasks_path = File.join(dir, 'tasks/**/*.rb')
|
22
|
+
files = Dir[helpers_path] + Dir[tasks_path]
|
23
|
+
files.each {|file| require_relative file }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
require_relative 'task.rb'
|
29
|
+
require_relative 'triggers.rb'
|
30
|
+
require_relative '../helpers/init.rb'
|
31
|
+
|
32
|
+
Monkey.init_task_suite
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Monkey
|
4
|
+
class Config
|
5
|
+
|
6
|
+
current_dir = File.dirname(__FILE__)
|
7
|
+
CONFIG_PATH = File.join(current_dir, '../../config.yml')
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
FileUtils.touch(CONFIG_PATH)
|
11
|
+
config_file = File.open(CONFIG_PATH, "rt")
|
12
|
+
hash = YAML.load(config_file)
|
13
|
+
if hash
|
14
|
+
@hash = hash
|
15
|
+
else
|
16
|
+
@hash = {}
|
17
|
+
end
|
18
|
+
config_file.close
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_reader :hash
|
22
|
+
|
23
|
+
def empty?
|
24
|
+
@hash.empty?
|
25
|
+
end
|
26
|
+
|
27
|
+
def [](option)
|
28
|
+
@hash[option]
|
29
|
+
end
|
30
|
+
|
31
|
+
def []=(option, val)
|
32
|
+
@hash[option] = val
|
33
|
+
end
|
34
|
+
|
35
|
+
def save!
|
36
|
+
File.open(CONFIG_PATH, "w") {|f| f.write(@hash.to_yaml) }
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# require 'win32/daemon'
|
2
|
+
# include Win32
|
3
|
+
|
4
|
+
# class MonkeyService < Daemon
|
5
|
+
# def service_main
|
6
|
+
# current_dir = File.dirname(__FILE__)
|
7
|
+
# clock_path = File.join(current_dir, 'monkey/clock.rb')
|
8
|
+
# exec("clockwork #{clock_path}")
|
9
|
+
# end
|
10
|
+
|
11
|
+
# def service_stop
|
12
|
+
# exit!
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
|
16
|
+
# MonkeyService.mainloop
|
data/lib/monkey/task.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'active_support/core_ext/string/inflections'
|
2
|
+
|
3
|
+
module Monkey
|
4
|
+
|
5
|
+
module Task
|
6
|
+
|
7
|
+
@@tasks = []
|
8
|
+
|
9
|
+
def self.included(base)
|
10
|
+
base.extend ClassMethods
|
11
|
+
@@tasks.push base.name.underscore
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.tasks
|
15
|
+
@@tasks
|
16
|
+
end
|
17
|
+
|
18
|
+
# CLASS METHODS
|
19
|
+
|
20
|
+
module ClassMethods
|
21
|
+
|
22
|
+
def trigger(name, *options)
|
23
|
+
trigger_class_name = name.to_s.camelize + 'Trigger'
|
24
|
+
@trigger = Monkey.const_get(trigger_class_name).new(self, *options)
|
25
|
+
end
|
26
|
+
|
27
|
+
def task_name
|
28
|
+
self.name.underscore
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Monkey
|
2
|
+
|
3
|
+
class Trigger
|
4
|
+
def initialize(task_class)
|
5
|
+
@task = task_class
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class EveryTrigger < Trigger
|
10
|
+
def initialize(task_class, interval, time=nil)
|
11
|
+
@interval = interval
|
12
|
+
@time = time
|
13
|
+
super(task_class)
|
14
|
+
start
|
15
|
+
end
|
16
|
+
|
17
|
+
def start
|
18
|
+
interval = @interval
|
19
|
+
time = @time
|
20
|
+
task_name = @task.task_name
|
21
|
+
if time
|
22
|
+
Clockwork.class_eval { every(interval, task_name, time) }
|
23
|
+
else
|
24
|
+
Clockwork.class_eval { every(interval, task_name) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class StartUpTrigger < Trigger
|
30
|
+
def initialize(task_class)
|
31
|
+
super(task_class)
|
32
|
+
start
|
33
|
+
end
|
34
|
+
|
35
|
+
def start
|
36
|
+
task_name = @task.task_name
|
37
|
+
Clockwork.class_eval { every(24.months, task_name) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mnky
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jean Snyman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.19.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.19.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.1.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.1.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: clockwork
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.7.5
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.7.5
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: win32-service
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.8.4
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.8.4
|
69
|
+
description: Monkey is a super simple framework for automating workstation configuration
|
70
|
+
and deployment. Tasks are written in Ruby with a cross-platform API for fetching
|
71
|
+
data and making changes to the system. These can be set to run on a schedule or
|
72
|
+
based on other triggers.
|
73
|
+
email: me@jsnyman.com
|
74
|
+
executables:
|
75
|
+
- monkey
|
76
|
+
- mnky
|
77
|
+
extensions: []
|
78
|
+
extra_rdoc_files: []
|
79
|
+
files:
|
80
|
+
- bin/mnky
|
81
|
+
- bin/monkey
|
82
|
+
- lib/helpers/computer.rb
|
83
|
+
- lib/helpers/file_paths.rb
|
84
|
+
- lib/helpers/init.rb
|
85
|
+
- lib/monkey/clock.rb
|
86
|
+
- lib/monkey/config.rb
|
87
|
+
- lib/monkey/service.rb
|
88
|
+
- lib/monkey/task.rb
|
89
|
+
- lib/monkey/triggers.rb
|
90
|
+
- lib/monkey.rb
|
91
|
+
homepage: http://monkeyrb.com
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.1.5
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: IT automation and scripting framework.
|
115
|
+
test_files: []
|