process_controller 0.0.6 → 0.0.7
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 +4 -4
- data/lib/control/version.rb +1 -1
- data/lib/control_helper.rb +17 -2
- data/lib/process_controller.rb +9 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c500f9338466a353da79e0b1e9474924ebb47952
|
4
|
+
data.tar.gz: 0c709ceb07406b33e958166871449e8caeb44cff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d0aa3e759821bcf3eb63db5f181d5d7a395b58c59064552d2045419680fa575fe64eecac63fdf685b86cfbc2068907eeaefaa25a42d54e73830b029a617f1eb
|
7
|
+
data.tar.gz: 4be27cb4761086a65b0325caacc653852e029657756df52083fb5d17f8f20c1f46984e06f12d3d921bcefcdf76b9e0bca0a7dc801ac6a11d7fc08bc92bb767de
|
data/lib/control/version.rb
CHANGED
data/lib/control_helper.rb
CHANGED
@@ -2,7 +2,7 @@ module ControlHelper
|
|
2
2
|
extend self
|
3
3
|
|
4
4
|
def find_app_pid(options)
|
5
|
-
pid_filename = options.fetch(Control_P::OPTIONS_ATTRIBUTES[:
|
5
|
+
pid_filename = options.fetch(Control_P::OPTIONS_ATTRIBUTES[:pid_filename], nil)
|
6
6
|
|
7
7
|
if pid_filename
|
8
8
|
get_pid_from_file(pid_filename)
|
@@ -29,7 +29,7 @@ module ControlHelper
|
|
29
29
|
|
30
30
|
def find_pid_with_ps(search_by_string)
|
31
31
|
pid = nil
|
32
|
-
procs = `ps aux`
|
32
|
+
procs = `ps aux | grep #{search_by_string}` # todo add grep
|
33
33
|
|
34
34
|
procs.each_line do |proc|
|
35
35
|
if proc.include?(search_by_string)
|
@@ -124,6 +124,7 @@ module ControlHelper
|
|
124
124
|
pid = find_app_pid(options)
|
125
125
|
if pid
|
126
126
|
p "#{prefix} Ok, Restarted. new pid #{pid}"
|
127
|
+
print_workers_started_and_stopped(options) if http_server?(options)
|
127
128
|
exit(0)
|
128
129
|
else
|
129
130
|
p "#{prefix} problem restarting. Check your code. #{pid}"
|
@@ -131,6 +132,20 @@ module ControlHelper
|
|
131
132
|
end
|
132
133
|
end
|
133
134
|
|
135
|
+
#TODO add option to overwrite the file names
|
136
|
+
def print_workers_started_and_stopped(options)
|
137
|
+
print_file('workers_started', Control_P::WORKERS_STARTED_EXTENTION)
|
138
|
+
print_file('workers_closed', Control_P::WORKERS_CLOSED_EXTENTION)
|
139
|
+
end
|
140
|
+
|
141
|
+
def print_file(type, file_name)
|
142
|
+
p type + Dir["*.closed"].length
|
143
|
+
end
|
144
|
+
|
145
|
+
def http_server?(options)
|
146
|
+
true == options.fetch(OPTIONS_ATTRIBUTES[:http_server], false)
|
147
|
+
end
|
148
|
+
|
134
149
|
def kill_the_old_process_if_needed(options)
|
135
150
|
|
136
151
|
old_pid = find_app_pid(options)
|
data/lib/process_controller.rb
CHANGED
@@ -3,13 +3,16 @@ require 'control_helper'
|
|
3
3
|
require 'active_support/core_ext/hash/indifferent_access'
|
4
4
|
|
5
5
|
class Control_P
|
6
|
-
OPTIONS_ATTRIBUTES = {action: 'action',
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
OPTIONS_ATTRIBUTES = {action: 'action', pid_filename: 'pid_filename', find_pid_by: 'find_pid_by',
|
7
|
+
app_name: 'app_name', port_num: 'port_num', app_filename: 'app_filename',
|
8
|
+
http_server: 'http_server', kill_command: 'kill_command',
|
9
|
+
restart_command: 'restart_command', environment: 'environment',
|
10
|
+
start_command: 'start_command'}.with_indifferent_access
|
11
11
|
|
12
12
|
FIND_BY_OPTIONS = {app_filename: 'app_filename', port_num: 'port_num', app_name: 'app_name', pid_file: 'pid_file'}.with_indifferent_access
|
13
|
+
WORKERS_STARTED_EXTENTION = 'started'
|
14
|
+
WORKERS_CLOSED_EXTENTION = 'closed'
|
15
|
+
|
13
16
|
HOSTNAME = Socket.gethostname
|
14
17
|
|
15
18
|
# Main Method for all actions
|
@@ -50,6 +53,7 @@ class Control_P
|
|
50
53
|
#means it's seamless, just need to send a kill signal and it will restart it self
|
51
54
|
if http_server
|
52
55
|
helper.restart_the_app!(options)
|
56
|
+
sleep(5)
|
53
57
|
else
|
54
58
|
helper.kill_the_old_process_if_needed(options)
|
55
59
|
helper.start_a_new_process!(options)
|