multi_daemons 0.1.0
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.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +75 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +28 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +91 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/multi_daemons/controller.rb +34 -0
- data/lib/multi_daemons/daemon.rb +95 -0
- data/lib/multi_daemons/pid.rb +54 -0
- data/lib/multi_daemons/pid_store.rb +28 -0
- data/lib/multi_daemons/validate.rb +43 -0
- data/lib/multi_daemons/version.rb +3 -0
- data/lib/multi_daemons.rb +32 -0
- data/multi_daemons.gemspec +38 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e9f3fa45368cb760d0004b51bcda3081d1856597b8c14d717acf84031ec618c7
|
4
|
+
data.tar.gz: c01dc7b03c4980d62533a2c74e12b9f41995083d79b9a5c77622802c37cbdda5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7f8b14e13ab996ab4e0b74d13cf833926a0818be37484b9e3330fc83fe5b723190a3d417e1de3dcd231a4fbeb48d330cf54bf76345ac13bb230800039c0788d2
|
7
|
+
data.tar.gz: dfc6fc3bfce2bd7b6e19641a6d8215f6b664e227aefdc643dbe39a6688f1d73ffcff09f581cddec1fb4627ae30f02cfafcd21f403304fd7d5e006d64bc86120d
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at
|
59
|
+
santhanakarthikeyan.s@gmail.com. All
|
60
|
+
complaints will be reviewed and investigated and will result in a response that
|
61
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
62
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
63
|
+
Further details of specific enforcement policies may be posted separately.
|
64
|
+
|
65
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
66
|
+
faith may face temporary or permanent repercussions as determined by other
|
67
|
+
members of the project's leadership.
|
68
|
+
|
69
|
+
## Attribution
|
70
|
+
|
71
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
72
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
73
|
+
|
74
|
+
[homepage]: http://contributor-covenant.org
|
75
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
multi_daemons (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
byebug (10.0.2)
|
10
|
+
metaclass (0.0.4)
|
11
|
+
minitest (5.11.3)
|
12
|
+
mocha (1.7.0)
|
13
|
+
metaclass (~> 0.0.1)
|
14
|
+
rake (10.5.0)
|
15
|
+
|
16
|
+
PLATFORMS
|
17
|
+
ruby
|
18
|
+
|
19
|
+
DEPENDENCIES
|
20
|
+
bundler (~> 1.16)
|
21
|
+
byebug (~> 10.0)
|
22
|
+
minitest (~> 5.0)
|
23
|
+
mocha (~> 1.7)
|
24
|
+
multi_daemons!
|
25
|
+
rake (~> 10.0)
|
26
|
+
|
27
|
+
BUNDLED WITH
|
28
|
+
1.16.2
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 santhanakarthikeyan
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 santhanakarthikeyan
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# MultiDaemons
|
2
|
+
|
3
|
+
It provides an easy way to run multiple ruby scripts as daemon. Daemon can be controlled by start, stop and restart. It also supports blocks as daemons. It even supports running single daemon process like other popular daemonzing gems.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'multi_daemons'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install multi_daemons
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
To run multiple daemons.
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
# this is server.rb
|
26
|
+
|
27
|
+
proc_code = Proc do
|
28
|
+
loop do
|
29
|
+
sleep 5
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
scheduler = MultiDaemons::Daemon.new('scripts/scheduler', name: 'scheduler', type: :script, {})
|
34
|
+
looper = MultiDaemons::Daemon.new(proc_code, name: 'looper', type: :proc, {})
|
35
|
+
MultiDaemons.runner([scheduler, looper], { force_kill_timeout: 60 })
|
36
|
+
```
|
37
|
+
|
38
|
+
To run as daemon
|
39
|
+
```ruby
|
40
|
+
ruby server.rb start
|
41
|
+
ruby server.rb stop
|
42
|
+
ruby server.rb restart
|
43
|
+
```
|
44
|
+
|
45
|
+
To run single daemon within a script.
|
46
|
+
```ruby
|
47
|
+
proc_code = Proc do
|
48
|
+
loop do
|
49
|
+
sleep 5
|
50
|
+
end
|
51
|
+
end
|
52
|
+
looper = MultiDaemons::Daemon.new(proc_code, name: 'looper', type: :proc, {})
|
53
|
+
looper.start # start daemon
|
54
|
+
# Do some other activity
|
55
|
+
looper.stop # stop daemon
|
56
|
+
```
|
57
|
+
|
58
|
+
To run single daemon.
|
59
|
+
```ruby
|
60
|
+
proc_code = Proc do
|
61
|
+
loop do
|
62
|
+
sleep 5
|
63
|
+
end
|
64
|
+
end
|
65
|
+
looper = MultiDaemons::Daemon.new(proc_code, name: 'looper', type: :proc, {})
|
66
|
+
MultiDaemons.runner([looper], { force_kill_timeout: 60 })
|
67
|
+
```
|
68
|
+
|
69
|
+
### Supported options for runner:
|
70
|
+
force_kill_timeout: <integer> # To kill all running daemons within the specified time.
|
71
|
+
|
72
|
+
### Supported option for Daemon:
|
73
|
+
force_kill_timeout, log_dir, pid_dir
|
74
|
+
|
75
|
+
## Development
|
76
|
+
|
77
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
78
|
+
|
79
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
80
|
+
|
81
|
+
## Contributing
|
82
|
+
|
83
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/santhanakarthikeyan/multi_daemons. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
84
|
+
|
85
|
+
## License
|
86
|
+
|
87
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
88
|
+
|
89
|
+
## Code of Conduct
|
90
|
+
|
91
|
+
Everyone interacting in the MultiDaemons project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/multi_daemons/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'multi_daemons'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module MultiDaemons
|
2
|
+
# To control daemons
|
3
|
+
class Controller
|
4
|
+
attr_accessor :daemons, :options
|
5
|
+
|
6
|
+
def initialize(daemons, options = {})
|
7
|
+
@daemons = daemons
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def start
|
12
|
+
daemons.each(&:start)
|
13
|
+
end
|
14
|
+
|
15
|
+
def stop
|
16
|
+
pids = []
|
17
|
+
pid_files = []
|
18
|
+
daemons.each do |daemon|
|
19
|
+
daemon.multiple = true
|
20
|
+
daemon.stop
|
21
|
+
pids << daemon.pids
|
22
|
+
pid_files << daemon.pid_file
|
23
|
+
end
|
24
|
+
Pid.force_kill(pids.flatten, force_kill_timeout)
|
25
|
+
PidStore.cleanup(pid_files)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def force_kill_timeout
|
31
|
+
options[:force_kill_timeout] || 30
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
module MultiDaemons
|
2
|
+
class Daemon
|
3
|
+
KILL_TIMEOUT = 30
|
4
|
+
attr_accessor :daemon, :type, :name, :options, :multiple, :errors
|
5
|
+
|
6
|
+
def initialize(daemon, name:, type:, options: {})
|
7
|
+
@daemon = daemon
|
8
|
+
@name = name
|
9
|
+
@type = type
|
10
|
+
@options = options
|
11
|
+
raise unless Validate.valid_daemon?(self)
|
12
|
+
end
|
13
|
+
|
14
|
+
def start
|
15
|
+
case type
|
16
|
+
when :proc, 'proc'
|
17
|
+
safe_fork do
|
18
|
+
daemon.call
|
19
|
+
end
|
20
|
+
when :script, 'script'
|
21
|
+
safe_fork do
|
22
|
+
Kernel.exec(daemon)
|
23
|
+
end
|
24
|
+
else
|
25
|
+
puts 'Unsupported type'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def stop
|
30
|
+
if File.file?(pid_file)
|
31
|
+
pids.each do |pid|
|
32
|
+
begin
|
33
|
+
Process.kill('TERM', pid)
|
34
|
+
rescue Errno::ESRCH => e
|
35
|
+
puts "#{e} #{pid}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
return if multiple
|
40
|
+
|
41
|
+
Pid.force_kill(pids, options[:force_kill_timeout])
|
42
|
+
PidStore.cleanup(pid_file)
|
43
|
+
else
|
44
|
+
puts 'Pid file not found. Is daemon running?'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def pids
|
49
|
+
PidStore.get(pid_file)
|
50
|
+
end
|
51
|
+
|
52
|
+
def pid_file
|
53
|
+
"#{pid_dir}#{name}.pid"
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def log_file
|
59
|
+
"#{log_dir}#{name}.log"
|
60
|
+
end
|
61
|
+
|
62
|
+
def safe_fork
|
63
|
+
Process.fork do
|
64
|
+
begin
|
65
|
+
Process.setsid
|
66
|
+
|
67
|
+
$0 = name || $PROGRAM_NAME
|
68
|
+
|
69
|
+
PidStore.store(pid_file, Process.pid)
|
70
|
+
|
71
|
+
log = File.new(log_file, 'a')
|
72
|
+
STDIN.reopen '/dev/null'
|
73
|
+
STDOUT.reopen log
|
74
|
+
STDERR.reopen STDOUT
|
75
|
+
|
76
|
+
yield
|
77
|
+
rescue Exception => e
|
78
|
+
puts e
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def log_dir
|
84
|
+
return '' if options[:log_dir].to_s.empty?
|
85
|
+
|
86
|
+
options[:log_dir][-1] == '/' ? options[:log_dir] : "#{options[:log_dir]}/"
|
87
|
+
end
|
88
|
+
|
89
|
+
def pid_dir
|
90
|
+
return '' if options[:pid_dir].to_s.empty?
|
91
|
+
|
92
|
+
options[:pid_dir][-1] == '/' ? options[:pid_dir] : "#{options[:pid_dir]}/"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module MultiDaemons
|
2
|
+
class Pid
|
3
|
+
KILL_TIMEOUT = 30
|
4
|
+
|
5
|
+
def self.running?(pid)
|
6
|
+
return false unless pid
|
7
|
+
|
8
|
+
begin
|
9
|
+
Process.kill(0, pid)
|
10
|
+
return true
|
11
|
+
rescue Errno::ESRCH
|
12
|
+
return false
|
13
|
+
rescue Exception
|
14
|
+
return true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.force_kill(pids, timeout = KILL_TIMEOUT)
|
19
|
+
Timeout.timeout(force_kill_timeout(timeout), Timeout::Error) do
|
20
|
+
pids.each do |pid|
|
21
|
+
sleep(0.5) while Pid.running?(pid)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
true
|
25
|
+
rescue Timeout::Error
|
26
|
+
puts 'Force stopping processes'
|
27
|
+
pids.each do |pid|
|
28
|
+
begin
|
29
|
+
Process.kill('KILL', pid)
|
30
|
+
rescue Errno::ESRCH
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
begin
|
35
|
+
Timeout.timeout(default_timeout, Timeout::Error) do
|
36
|
+
pids.each do |pid|
|
37
|
+
sleep 1 while Pid.running?(pid)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
rescue Timeout::Error
|
41
|
+
puts 'Can not stop processes'
|
42
|
+
return false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.force_kill_timeout(timeout)
|
47
|
+
timeout || KILL_TIMEOUT
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.default_timeout
|
51
|
+
KILL_TIMEOUT
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module MultiDaemons
|
2
|
+
module PidStore
|
3
|
+
def self.store(file_name, pid)
|
4
|
+
File.open(file_name, 'a') { |f| f << "#{pid}\n" }
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.get(file_name)
|
8
|
+
[].tap do |pids|
|
9
|
+
unless File.exist?(file_name)
|
10
|
+
pids << nil
|
11
|
+
next
|
12
|
+
end
|
13
|
+
File.read(file_name).each_line do |line|
|
14
|
+
pids << line.to_i
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.cleanup(file_names)
|
20
|
+
file_names = [file_names].flatten
|
21
|
+
file_names.each do |file_name|
|
22
|
+
next unless File.exist?(file_name)
|
23
|
+
|
24
|
+
FileUtils.rm(file_name)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module MultiDaemons
|
2
|
+
class Validate
|
3
|
+
class << self
|
4
|
+
def valid_daemon?(daemon)
|
5
|
+
name = daemon.name
|
6
|
+
return daemon_name_error unless name && name.length > 1
|
7
|
+
|
8
|
+
daemon.name = name.to_s if name.is_a?(Symbol)
|
9
|
+
case daemon.type
|
10
|
+
when :proc, 'proc'
|
11
|
+
return daemon_proc_error unless daemon.daemon.is_a?(Proc)
|
12
|
+
end
|
13
|
+
true
|
14
|
+
end
|
15
|
+
|
16
|
+
def valid_multi_daemon?(multi_daemon)
|
17
|
+
if multi_daemon.is_a?(Array) && !multi_daemon.empty?
|
18
|
+
if multi_daemon.all? { |daemon| daemon.is_a?(MultiDaemons::Daemon) }
|
19
|
+
return true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
invalid_multi_daemon_option
|
23
|
+
false
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def invalid_multi_daemon_option
|
29
|
+
puts 'Daemons are not present or invalid'
|
30
|
+
end
|
31
|
+
|
32
|
+
def daemon_name_error
|
33
|
+
puts 'Daemon name should not be empty'
|
34
|
+
false
|
35
|
+
end
|
36
|
+
|
37
|
+
def daemon_proc_error
|
38
|
+
puts 'Daemons type is proc but proc block has not been passed'
|
39
|
+
false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# require 'multi_daemons/version'
|
2
|
+
require_relative 'multi_daemons/controller'
|
3
|
+
require_relative 'multi_daemons/pid_store'
|
4
|
+
require_relative 'multi_daemons/pid'
|
5
|
+
require_relative 'multi_daemons/daemon'
|
6
|
+
require_relative 'multi_daemons/validate'
|
7
|
+
require 'fileutils'
|
8
|
+
require 'byebug'
|
9
|
+
require 'timeout'
|
10
|
+
|
11
|
+
module MultiDaemons
|
12
|
+
def self.runner(daemons, options = {})
|
13
|
+
raise unless Validate.valid_multi_daemon?(daemons)
|
14
|
+
|
15
|
+
controller = Controller.new(daemons, options)
|
16
|
+
daemonize(controller)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.daemonize(controller)
|
20
|
+
case !ARGV.empty? && ARGV[0]
|
21
|
+
when 'start'
|
22
|
+
controller.start
|
23
|
+
when 'stop'
|
24
|
+
controller.stop
|
25
|
+
when 'restart'
|
26
|
+
controller.stop
|
27
|
+
controller.start
|
28
|
+
else
|
29
|
+
raise 'Invalid argument. Specify start, stop or restart'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'multi_daemons/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'multi_daemons'
|
7
|
+
spec.version = MultiDaemons::VERSION
|
8
|
+
spec.authors = ['santhanakarthikeyan']
|
9
|
+
spec.email = ['santhanakarthikeyan.s@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'MultiDaemon provides an wrapper to run multiple daemon scripts'
|
12
|
+
spec.description = 'MultiDaemon provides an warpper to run multiple daemon scripts which can be controlled by start/stop and restart commands'
|
13
|
+
spec.homepage = %q{https://github.com/santhanakarthikeyan/multi_daemons}
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
else
|
20
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
21
|
+
'public gem pushes.'
|
22
|
+
end
|
23
|
+
|
24
|
+
# Specify which files should be added to the gem when it is released.
|
25
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
26
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
27
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
28
|
+
end
|
29
|
+
spec.bindir = 'exe'
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ['lib']
|
32
|
+
|
33
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
34
|
+
spec.add_development_dependency 'byebug', ' ~> 10.0'
|
35
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
36
|
+
spec.add_development_dependency 'mocha', '~> 1.7'
|
37
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: multi_daemons
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- santhanakarthikeyan
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: byebug
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mocha
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
description: MultiDaemon provides an warpper to run multiple daemon scripts which
|
84
|
+
can be controlled by start/stop and restart commands
|
85
|
+
email:
|
86
|
+
- santhanakarthikeyan.s@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- CODE_OF_CONDUCT.md
|
92
|
+
- Gemfile
|
93
|
+
- Gemfile.lock
|
94
|
+
- LICENSE
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- lib/multi_daemons.rb
|
101
|
+
- lib/multi_daemons/controller.rb
|
102
|
+
- lib/multi_daemons/daemon.rb
|
103
|
+
- lib/multi_daemons/pid.rb
|
104
|
+
- lib/multi_daemons/pid_store.rb
|
105
|
+
- lib/multi_daemons/validate.rb
|
106
|
+
- lib/multi_daemons/version.rb
|
107
|
+
- multi_daemons.gemspec
|
108
|
+
homepage: https://github.com/santhanakarthikeyan/multi_daemons
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.7.7
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: MultiDaemon provides an wrapper to run multiple daemon scripts
|
132
|
+
test_files: []
|