daemon-overlord 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/overlord +37 -6
- data/lib/overlord/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 521ddd1331345101eedb6032742cbe4b4e7d1768
|
4
|
+
data.tar.gz: 2699ee4f39ceb970f0193f9cb9c12ff9263d050c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2dc467f19f9151915fa620c1b15be74883efea61eee8645b836ac511e8025616fcf5334936d3d7b851aec980d9523b5eaaae40a6dc448f1aa4748384ac31707b
|
7
|
+
data.tar.gz: 0676fc557c4c39ed201cd00ca71e1ab70e6563c95ca38de8464c7dec7f6ac5f1eadc42139e11d4bfd5059d2959f2313b4dd4c1b9e8c5377c482e701b2f2c5d0c
|
data/exe/overlord
CHANGED
@@ -6,12 +6,18 @@ require 'process_runner'
|
|
6
6
|
|
7
7
|
module Overlord
|
8
8
|
|
9
|
-
DEFAULT_CONFIG_FILE_PATH = File.
|
10
|
-
DEFAULT_PIDS_FILE_PATH = File.
|
9
|
+
DEFAULT_CONFIG_FILE_PATH = File.join(Dir.pwd, 'config/overlord.yml')
|
10
|
+
DEFAULT_PIDS_FILE_PATH = File.join(Dir.pwd, 'tmp/pids')
|
11
|
+
DEFAULT_LOGS_FILE_PATH = File.join(Dir.pwd, 'log')
|
11
12
|
|
12
13
|
def self.with_config_and_pids_files(options)
|
13
14
|
config_path = File.absolute_path options[:config]
|
14
15
|
pids_path = File.absolute_path options[:pids]
|
16
|
+
|
17
|
+
if !File.directory?(File.dirname(pids_path))
|
18
|
+
Dir.mkdir File.dirname(pids_path)
|
19
|
+
end
|
20
|
+
|
15
21
|
File.open(config_path, 'r') do |config_file|
|
16
22
|
config = YAML.load(config_file) || {}
|
17
23
|
if !File.exists?(pids_path)
|
@@ -40,7 +46,7 @@ module Overlord
|
|
40
46
|
def self.force_kill_process(pid) Process.kill('KILL', pid) end
|
41
47
|
|
42
48
|
module Actions
|
43
|
-
def start_daemon(app, config, pids, pids_file_path)
|
49
|
+
def start_daemon(app, config, pids, pids_file_path, log_directory = nil, merge_out_and_err = nil)
|
44
50
|
if pids[app]
|
45
51
|
if Overlord.process_exists?(pids[app])
|
46
52
|
say "WARNING: #{app} is already started (PID: #{pids[app]})."
|
@@ -52,10 +58,25 @@ module Overlord
|
|
52
58
|
end
|
53
59
|
command = config[app]
|
54
60
|
|
61
|
+
options = {}
|
62
|
+
if log_directory
|
63
|
+
if !File.directory?(log_directory)
|
64
|
+
say_status :mkdir, "Creating log directory, \"#{log_directory}\"."
|
65
|
+
Dir.mkdir log_directory
|
66
|
+
end
|
67
|
+
if merge_out_and_err
|
68
|
+
options[:err] = :out
|
69
|
+
options[:out] = [File.join(log_directory, "#{app}.log"), 'a']
|
70
|
+
else
|
71
|
+
options[:err] = [File.join(log_directory, "#{app}.log.e"), 'a']
|
72
|
+
options[:out] = [File.join(log_directory, "#{app}.log.o"), 'a']
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
55
76
|
desc = "`#{command}` from #{Dir.pwd}"
|
56
77
|
|
57
78
|
say_status :run_as_daemon, desc
|
58
|
-
pid = Process.detach(Process.spawn(command)).pid
|
79
|
+
pid = Process.detach(Process.spawn(command, options)).pid
|
59
80
|
pids[app] = pid
|
60
81
|
say_status :start, "#{app} started with PID #{pid}."
|
61
82
|
end
|
@@ -95,6 +116,12 @@ module Overlord
|
|
95
116
|
def self.with_pids
|
96
117
|
method_option :pids, :aliases => ['-p'], :default => DEFAULT_PIDS_FILE_PATH, :desc => "Path to SSV file where application PIDs will be saved."
|
97
118
|
end
|
119
|
+
def self.with_logs
|
120
|
+
method_option :logs, :aliases => ['-l'], :default => DEFAULT_LOGS_FILE_PATH, :desc => "Path to a directory where application standard out and error will be logged."
|
121
|
+
end
|
122
|
+
def self.with_merge_stdout_and_stderr
|
123
|
+
method_option :merge, :type => :boolean, :aliases => ['-m'], :default => true, :desc => "Log application standard out and error together."
|
124
|
+
end
|
98
125
|
|
99
126
|
desc "status", "Show the status of managed applications."
|
100
127
|
with_config
|
@@ -120,14 +147,16 @@ module Overlord
|
|
120
147
|
desc "start", "Start an application."
|
121
148
|
with_config
|
122
149
|
with_pids
|
150
|
+
with_logs
|
151
|
+
with_merge_stdout_and_stderr
|
123
152
|
method_option :app, :aliases => ['-a'], :desc => "Application to start. Starts all if none specified."
|
124
153
|
def start
|
125
154
|
Overlord.with_config_and_pids_files(options) do |config_file, config, pids_file, pids|
|
126
155
|
if options[:app]
|
127
|
-
start_daemon(options[:app], config, pids, pids_file.path)
|
156
|
+
start_daemon(options[:app], config, pids, pids_file.path, options[:logs], options[:merge])
|
128
157
|
else
|
129
158
|
config.keys.each do |app|
|
130
|
-
start_daemon(app, config, pids, pids_file.path)
|
159
|
+
start_daemon(app, config, pids, pids_file.path, options[:logs], options[:merge])
|
131
160
|
end
|
132
161
|
end
|
133
162
|
pids_file.write(YAML.dump(pids)) unless pids.empty?
|
@@ -154,6 +183,8 @@ module Overlord
|
|
154
183
|
desc "restart", "Restart an application."
|
155
184
|
with_config
|
156
185
|
with_pids
|
186
|
+
with_logs
|
187
|
+
with_merge_stdout_and_stderr
|
157
188
|
method_option :app, :aliases => ['-a'], :desc => "Application to restart. Restarts all if none specified."
|
158
189
|
def restart
|
159
190
|
stop
|
data/lib/overlord/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daemon-overlord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dustin Morrill
|
@@ -125,3 +125,4 @@ signing_key:
|
|
125
125
|
specification_version: 4
|
126
126
|
summary: Start and stop daemons with minimal monitoring.
|
127
127
|
test_files: []
|
128
|
+
has_rdoc:
|