spiderfw 0.6.5 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/CHANGELOG +10 -0
  2. data/VERSION +1 -1
  3. data/apps/app_server/config/options.rb +2 -2
  4. data/apps/core/components/assets.rb +1 -5
  5. data/apps/core/components/widgets/month_calendar/month_calendar.shtml +3 -3
  6. data/apps/core/components/widgets/table/table.rb +2 -0
  7. data/apps/core/components/widgets/tabs/tabs.rb +9 -3
  8. data/apps/core/components/widgets/tabs/tabs.shtml +1 -1
  9. data/apps/master/_init.rb +3 -1
  10. data/apps/master/cmd.rb +1 -1
  11. data/apps/master/controllers/master_controller.rb +107 -103
  12. data/apps/master/controllers/scout_controller.rb +7 -7
  13. data/apps/master/controllers/{servant_controller.rb → server_controller.rb} +3 -3
  14. data/apps/master/data/locale/it/LC_MESSAGES/master.mo +0 -0
  15. data/apps/master/master.rb +4 -4
  16. data/apps/master/models/customer.rb +0 -3
  17. data/apps/master/models/installation.rb +14 -3
  18. data/apps/master/models/remote_log.rb +11 -0
  19. data/apps/master/models/scout_plugin_instance.rb +9 -9
  20. data/apps/master/models/scout_plugin_trigger.rb +2 -2
  21. data/apps/master/models/{servant.rb → server.rb} +6 -6
  22. data/apps/master/po/it/{spider_master.po → master.po} +127 -54
  23. data/apps/master/po/master.pot +23 -23
  24. data/apps/master/templates/email/alert.html.erb +1 -1
  25. data/apps/master/views/customer.shtml +3 -3
  26. data/apps/master/views/index.shtml +1 -2
  27. data/apps/master/views/installation.shtml +28 -16
  28. data/apps/master/views/master.layout.shtml +2 -1
  29. data/apps/master/views/plugin_data.shtml +1 -1
  30. data/apps/master/views/{servant.shtml → server.shtml} +14 -14
  31. data/apps/master/views/servers.shtml +11 -0
  32. data/apps/master/views/site_edit.shtml +1 -1
  33. data/apps/master/views/trigger_edit.shtml +4 -4
  34. data/apps/messenger/controllers/mixins/messenger_helper.rb +3 -3
  35. data/apps/servant/Gemfile +1 -0
  36. data/apps/servant/_init.rb +5 -1
  37. data/apps/servant/cmd.rb +14 -45
  38. data/apps/servant/config/options.rb +1 -0
  39. data/apps/servant/controllers/servant_controller.rb +7 -1
  40. data/apps/servant/lib/client.rb +55 -0
  41. data/apps/servant/servant.appspec +1 -1
  42. data/apps/servant/servant.rb +90 -0
  43. data/apps/worker/cmd.rb +9 -4
  44. data/apps/worker/worker.rb +11 -6
  45. data/blueprints/bin/spider +7 -0
  46. data/blueprints/home/config/config.yml +2 -3
  47. data/blueprints/home/init.rb +1 -1
  48. data/lib/spiderfw/app.rb +50 -2
  49. data/lib/spiderfw/cmd/commands/app.rb +22 -12
  50. data/lib/spiderfw/cmd/commands/config.rb +2 -1
  51. data/lib/spiderfw/config/configuration_editor.rb +7 -4
  52. data/lib/spiderfw/config/options/spider.rb +3 -1
  53. data/lib/spiderfw/controller/helpers/widget_helper.rb +6 -3
  54. data/lib/spiderfw/controller/mixins/http_mixin.rb +2 -1
  55. data/lib/spiderfw/controller/mixins/visual.rb +12 -10
  56. data/lib/spiderfw/env.rb +8 -1
  57. data/lib/spiderfw/home.rb +31 -4
  58. data/lib/spiderfw/http/server.rb +32 -14
  59. data/lib/spiderfw/model/mappers/mapper.rb +2 -2
  60. data/lib/spiderfw/model/mixins/tree.rb +7 -5
  61. data/lib/spiderfw/model/storage/db/adapters/mysql.rb +55 -2
  62. data/lib/spiderfw/model/storage/db/adapters/oracle.rb +80 -3
  63. data/lib/spiderfw/model/storage/db/connectors/jdbc_oracle.rb +3 -2
  64. data/lib/spiderfw/model/storage/db/connectors/oci8.rb +3 -2
  65. data/lib/spiderfw/model/storage/db/db_storage.rb +22 -0
  66. data/lib/spiderfw/setup/app_manager.rb +6 -2
  67. data/lib/spiderfw/site.rb +3 -1
  68. data/lib/spiderfw/spider.rb +145 -18
  69. data/lib/spiderfw/templates/blocks/parent_context.rb +3 -1
  70. data/lib/spiderfw/templates/template.rb +14 -5
  71. data/lib/spiderfw/widget/widget.rb +1 -0
  72. data/lib/spiderfw/widget/widget_attributes.rb +2 -2
  73. metadata +16 -16
  74. data/apps/master/po/spider_master.pot +0 -331
  75. data/apps/master/views/servants.shtml +0 -11
  76. data/apps/servant/lib/commands/discovery.rb +0 -0
  77. data/apps/servant/lib/resource.rb +0 -14
  78. data/apps/servant/lib/resources/db/mysql.rb +0 -35
  79. data/apps/servant/lib/resources/db.rb +0 -55
  80. data/apps/servant/lib/servant.rb +0 -88
  81. data/apps/servant/var/log/error.log +0 -1
@@ -1,9 +1,9 @@
1
1
  <div>
2
- <div class="actions">
2
+ <div class="actions" sp:if="@customer">
3
3
  <a href="{ Master.url }/customers/{ @customer.id }">_(Back to customer)</a>
4
4
  </div>
5
5
  <div sp:if="!@installation">
6
- <h3>_(New installation for %s) % @customer.name</h3>
6
+ <h2>_(New installation for %s) % @customer.name</h2>
7
7
  <form action="" method="POST">
8
8
  <div class="row">
9
9
  <label for="installation_name">_(Name):</label>
@@ -12,24 +12,36 @@
12
12
  </div>
13
13
  </form>
14
14
  </div>
15
- <div sp:if="@installation">
16
- <h3 sp:if="@installation">_(Installation "%s" for %s) % [@installation.name, @customer.name] </h3>
17
- <core:tabs id="install_tabs">
18
- <tab id="edit" label="_(Edit installation)">
15
+ <tpl:pass sp:if="@edit">
16
+ <forms:form id="installation_form" model="Spider::Master::Installation" pk="@pk" auto_redirect="true"/>
17
+ </tpl:pass>
18
+ <div sp:if="@installation && !@edit">
19
+ <div class="page-title title-block">
20
+ <h2>_(Installation "%s") % [@installation]</h2>
21
+ <a href="?edit" class="manage edit">_(Edit)</a>
22
+ </div>
23
+ <core:tabs id="tabs">
24
+ <tab label="_(Apps)" id="apps">
19
25
  <div class="apps">
20
26
  <h4>_(Apps)</h4>
21
- <form action="" method="POST">
22
- <ul>
23
- <li sp:each="@apps |app|">
24
- <input type="checkbox" name="apps[{ app.app_id }]" value="true" sp:attr-if="@install_apps.include?(app.app_id),checked">
25
- { app.name }
26
- </li>
27
- </ul>
28
- <input type="submit" name="save_apps" value="_(Save)">
29
- </form>
27
+ <ul>
28
+ <li sp:each="@install_apps |id, details|">
29
+ { @apps[id].name } { details["version"] }
30
+ </li>
31
+ </ul>
30
32
  </div>
31
33
  </tab>
32
- <tab id="targets" label="_(Targets)">
34
+ <tab label="_(Configuration)" id="config">
35
+ <div class="config">
36
+ <h4>_(Configuration)</h4>
37
+ <textarea>{ @installation.configuration }</textarea>
38
+ </div>
39
+ </tab>
40
+ <tab label="_(Logs)" id="logs">
41
+ <div class="logs">
42
+ <h4>_(Logs)</h4>
43
+ <core:table id="logs_table" queryset="@logs" sort="time,desc" />
44
+ </div>
33
45
  </tab>
34
46
  </core:tabs>
35
47
  </div>
@@ -18,7 +18,8 @@
18
18
  <ul id="top-nav">
19
19
  <li><a href="{ Master.url }">_(Home)</a></li>
20
20
  <li><a href="{ Master.url }/customers" sp:if="@user.global?">_(Customers)</a></li>
21
- <li><a href="{ Master.url }/servants">_(Servants)</a></li>
21
+ <li><a href="{ Master.url }/servers">_(Servers)</a></li>
22
+ <li><a href="{ Master.url }/installs">_(Installs)</a></li>
22
23
  </ul>
23
24
  <ul id="navigation">
24
25
  <li sp:each_with_index="@navigation |nav, i|">
@@ -12,7 +12,7 @@
12
12
  <div id="chart_setup">
13
13
  <h5>_(Compare):</h5>
14
14
  <select id="chart_add_column" name="add_column">
15
- <tpl:pass sp:each="@servant.scout_plugins |plugin|">
15
+ <tpl:pass sp:each="@server.scout_plugins |plugin|">
16
16
  <option value="" disabled="disabled">{ plugin.name }</option>
17
17
  <option sp:each="plugin.plugin.metadata |k, d|"
18
18
  value="{ plugin.id }|{ k }">--- { (d["label"].blank? ? k : d["label"]) }</option>
@@ -1,36 +1,36 @@
1
1
  <div>
2
- <tpl:pass sp:if="@servant">
2
+ <tpl:pass sp:if="@server">
3
3
  <div class="page-title title-block">
4
- <h2>{ @servant.name }</h2>
4
+ <h2>{ @server.name }</h2>
5
5
  <tpl:pass sp:if="!@edit">
6
6
  <a href="?edit" class="manage edit">_(Edit)</a>
7
7
  </tpl:pass>
8
8
  </div>
9
9
  <div class="info-block main">
10
10
  <div class="row">
11
- <label>Uuid:</label> { @servant.uuid }
11
+ <label>Uuid:</label> { @server.uuid }
12
12
  </div>
13
- <div class="row" sp:if="@servant.customer">
13
+ <div class="row" sp:if="@server.customer">
14
14
  <label>_(Customer):</label>
15
- <a href="{ Master.url }/customers/{ @servant.customer.id }">
16
- { @servant.customer }
15
+ <a href="{ Master.url }/customers/{ @server.customer.id }">
16
+ { @server.customer }
17
17
  </a>
18
18
  </div>
19
19
  </div>
20
20
  </tpl:pass>
21
21
  <div class="page-title title-block">
22
- <h2 sp:if="!@servant">
23
- _(New servant) <tpl:pass sp:if="@customer">_(for customer %s) % @customer.name</tpl:pass>
22
+ <h2 sp:if="!@server">
23
+ _(New server) <tpl:pass sp:if="@customer">_(for customer %s) % @customer.name</tpl:pass>
24
24
  </h2>
25
25
  </div>
26
26
  <tpl:pass sp:if="@edit">
27
- <forms:form id="servant_form" model="Spider::Master::Servant" pk="@pk" auto_redirect="true"/>
27
+ <forms:form id="server_form" model="Spider::Master::Server" pk="@pk" auto_redirect="true"/>
28
28
  </tpl:pass>
29
29
  <tpl:pass sp:if="!@edit">
30
30
  <div class="list-title title-block">
31
31
  <h3>_(Sites)</h3>
32
- <a href="{ Master.url_for_servant(@servant) }/sites/create" class="add manage">_(New site)</a>
33
- <a href="{ Master.url_for_servant(@servant) }/sites/create" class="add manage">_(Add existing site)</a>
32
+ <a href="{ Master.url_for_server(@server) }/sites/create" class="add manage">_(New site)</a>
33
+ <a href="{ Master.url_for_server(@server) }/sites/create" class="add manage">_(Add existing site)</a>
34
34
  </div>
35
35
  <table class="list-table">
36
36
  <!-- <tr sp:each="@servant.scout_plugins |plugin|">
@@ -56,10 +56,10 @@
56
56
  </div>
57
57
  </div>
58
58
  <table class="list-table">
59
- <tr sp:each="@servant.scout_plugins |plugin|">
59
+ <tr sp:each="@server.scout_plugins |plugin|">
60
60
  <td>
61
- <a href="{ Master.url }/servants/{ @servant.id }/plugins/{ plugin.id }">{ plugin.name }</a>
62
- <a href="{ @servant.id }?remove_plugin={ plugin.id }" class="manage remove">_(Remove)</a>
61
+ <a href="{ Master.url }/server/{ @server.id }/plugins/{ plugin.id }">{ plugin.name }</a>
62
+ <a href="{ @server.id }?remove_plugin={ plugin.id }" class="manage remove">_(Remove)</a>
63
63
  </td>
64
64
  </tr>
65
65
  </table>
@@ -0,0 +1,11 @@
1
+ <div>
2
+ <h3>Servers</h3>
3
+ <div class="actions">
4
+ <a href="{ Master.url }/servers/new">_(New server)</a>
5
+ </div>
6
+ <ul>
7
+ <li sp:each="@servers |server|">
8
+ <a href="{ Master.url }/servers/{ servant.id }">{ server.name }</a>
9
+ </li>
10
+ </ul>
11
+ </div>
@@ -1,7 +1,7 @@
1
1
  <div class="site-edit">
2
2
  <div class="page-title title-block">
3
3
  <h2 sp:if="@site && @site.id">_(Edit Site %s) % @site.name</h2>
4
- <h2 sp:if="!@site || !@site.id">_(Create new Site for %s) % @servant.name</h2>
4
+ <h2 sp:if="!@site || !@site.id">_(Create new Site for %s) % @server.name</h2>
5
5
  </div>
6
6
  <div sp:if="!@site_type">
7
7
  _(Choose site type):
@@ -4,13 +4,13 @@
4
4
  <h2 sp:if="!@trigger.id">_(New Trigger for plugin %s) % @instance.name</h2>
5
5
  </div>
6
6
  <form method="post" class="spider forms form">
7
- <div class="row" sp:if="@servant.customer">
7
+ <div class="row" sp:if="@server.customer">
8
8
  <label>_(Customer):</label>
9
- <span class="data">{ @servant.customer.name }</span>
9
+ <span class="data">{ @server.customer.name }</span>
10
10
  </div>
11
11
  <div class="row">
12
- <label>_(Servant):</label>
13
- <span class="data">{ @servant.name }</span>
12
+ <label>_(Server):</label>
13
+ <span class="data">{ @server.name }</span>
14
14
  </div>
15
15
  <div class="row">
16
16
  <label>_(Plugin):</label>
@@ -29,9 +29,9 @@ module Spider; module Messenger
29
29
 
30
30
  def self.send_email(klass, template, scene, from, to, headers={}, attachments=[], params={})
31
31
  path_txt = klass.find_resource_path(:email, template+'.txt')
32
- path_txt = nil unless File.exist?(path_txt)
32
+ path_txt = nil unless path_txt && File.exist?(path_txt)
33
33
  path_html = klass.find_resource_path(:email, template+'.html')
34
- path_html = nil unless File.exist?(path_html)
34
+ path_html = nil unless path_html && File.exist?(path_html)
35
35
  scene_binding = scene.instance_eval{ binding }
36
36
  if (path_txt || path_html)
37
37
  text = ERB.new(IO.read(path_txt)).result(scene_binding) if path_txt
@@ -83,4 +83,4 @@ module Spider; module Messenger
83
83
 
84
84
  end
85
85
 
86
- end; end
86
+ end; end
@@ -0,0 +1 @@
1
+ gem "httpclient"
@@ -1,5 +1,9 @@
1
1
  module Spider
2
2
  module Servant
3
+ @short_name = 'servant'
3
4
  include Spider::App
5
+ @controller = :ServantController
4
6
  end
5
- end
7
+ end
8
+
9
+ require 'apps/servant/controllers/servant_controller'
data/apps/servant/cmd.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'cmdparse'
2
+ require 'apps/servant/lib/client'
2
3
 
3
4
  module Spider; module Servant
4
5
 
@@ -7,53 +8,21 @@ module Spider; module Servant
7
8
  def initialize
8
9
  super('servant', true)
9
10
 
10
- status = CmdParse::Command.new('status', false )
11
- status.short_desc = _("Check worker process status")
12
- status.set_execution_block do
13
- pid = Worker.running?
14
- if (pid)
15
- puts "Worker running (#{pid})"
16
- else
17
- puts "Worker not running"
11
+ ping = CmdParse::Command.new('ping', false )
12
+ ping.short_desc = _("Ping server")
13
+ ping.set_execution_block do |args|
14
+ require 'spiderfw/spider'
15
+ Spider.init_base
16
+ url = args.first || Spider.config.get('spider.master.url')
17
+ unless url
18
+ puts _("No url provided, exiting.")
19
+ exit
18
20
  end
21
+ servant = Spider::Servant::Client.new(url)
22
+ servant.ping_server
19
23
  end
20
- self.add_command(status)
21
-
22
- start = CmdParse::Command.new('start', false)
23
- start.short_desc = _("Start worker")
24
- start.options = CmdParse::OptionParserWrapper.new do |opt|
25
- opt.on("--daemonize", _("Daemonize worker"), "-d"){ |d|
26
- @daemonize = true
27
- }
28
- end
29
- start.set_execution_block do
30
- if (@daemonize)
31
- Worker.options[:fork] = true
32
- Worker.options[:detach] = true
33
- else
34
- Worker.options[:fork] = false
35
- Worker.options[:detach] = false
36
- end
37
- Worker.app_startup
38
- if (@daemonize)
39
- STDIN.reopen "/dev/null" # Free file descriptors and
40
- STDOUT.reopen "/dev/null", "a" # point them somewhere sensible
41
- STDERR.reopen STDOUT # STDOUT/STDERR should go to a logfile
42
- else
43
- # trap('TERM') { Worker.app_shutdown }
44
- # trap('INT') { Worker.app_shutdown }
45
- Worker.join
46
- end
47
- end
48
- self.add_command(start)
49
-
50
- stop = CmdParse::Command.new('stop', false)
51
- stop.short_desc = _("Stop worker")
52
- stop.set_execution_block do
53
- Worker.app_shutdown
54
- end
55
- self.add_command(stop)
56
-
24
+ self.add_command(ping)
25
+
57
26
 
58
27
  end
59
28
 
@@ -0,0 +1 @@
1
+ Spider.config_option 'spider.master.url', _('Url of spider master')
@@ -1,11 +1,17 @@
1
1
  module Spider; module Servant
2
2
 
3
3
 
4
- class ServantController
4
+ class ServantController < Spider::Controller
5
5
 
6
6
  def command
7
7
  end
8
8
 
9
+ __.action
10
+ def broken
11
+ a = 0
12
+ a / 0
13
+ end
14
+
9
15
  end
10
16
 
11
17
 
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'httpclient'
3
+
4
+ module Spider
5
+
6
+ module Servant
7
+
8
+ class Client
9
+
10
+ def initialize(url)
11
+ @url = url
12
+ end
13
+
14
+ def ping_server(url=@url)
15
+ clnt = HTTPClient.new
16
+ status = Servant.status
17
+ status[:apps] = status[:apps].to_json
18
+ last_check_file = File.join(Spider.paths[:var], 'memory', 'servant_last_check')
19
+ if File.exists?(last_check_file)
20
+ last_check = Time.parse(File.read(last_check_file))
21
+ status[:interval] = Time.now - last_check
22
+ end
23
+ status[:log] = Servant.gather_log.to_json
24
+ status[:configuration] = compress_string(Servant.gather_configuration)
25
+ res = clnt.post("#{url}/ping", Spider::HTTP.params_to_hash(status))
26
+ unless res.status == 200
27
+ puts _("The server responded with: %s - %s") % [res.status, res.reason]
28
+ exit
29
+ end
30
+ File.open(last_check_file, 'w'){ |f| f << Time.now.to_s }
31
+ res = JSON.parse(res.content)
32
+ if res[:commands]
33
+ res[:commands].each do |command|
34
+ command_result = execute_command(command[:name], command[:arguments])
35
+ clnt.post()
36
+ end
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def compress_string(str)
43
+ compr = ""
44
+ gz = Zlib::GzipWriter.new(StringIO.new(compr))
45
+ gz.write str
46
+ gz.close
47
+ compr
48
+ end
49
+
50
+
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -1,4 +1,4 @@
1
1
  name "Servant"
2
2
  version "0.1"
3
3
  author "Ivan Pirlik"
4
- gems "ohai >0.3", "httpclient"
4
+ gems "httpclient"
@@ -0,0 +1,90 @@
1
+ require 'uuidtools'
2
+
3
+ module Spider
4
+
5
+ module Servant
6
+
7
+ def self.install_id
8
+ uuid_file = File.join(Spider.paths[:var], 'install_id')
9
+ return File.read(uuid_file) if File.exists?(uuid_file)
10
+ uuid = UUIDTools::UUID.random_create.to_s
11
+ File.open(uuid_file, 'w'){ |f| f << uuid }
12
+ uuid
13
+ end
14
+
15
+ def self.status
16
+ Spider.init_base
17
+ apps = self.apps
18
+ status = {
19
+ :install_id => self.install_id,
20
+ :apps => apps
21
+ }
22
+ end
23
+
24
+ def self.apps
25
+ active = Spider.config.get('apps')
26
+ apps = Spider.home.apps
27
+ h = {}
28
+ apps.each do |k, v|
29
+ h[k] = {}
30
+ h[k][:version] = v[:spec].version
31
+ h[k][:active] = true if active.include?(k)
32
+ end
33
+ h
34
+ end
35
+
36
+ def self.gather_log(level=:WARN)
37
+ level = level.to_s
38
+ levels = ['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL']
39
+ lev = levels.index(level)
40
+
41
+ log_file = File.join(Spider.paths[:log], Spider.conf.get('log.file_name'))
42
+ return [] unless File.exists?(log_file)
43
+ log_prev_file = File.join(Spider.paths[:var], 'memory', 'servant_log_prev')
44
+ previous_position = 0
45
+ if File.exists?(log_prev_file)
46
+ previous_position = File.read(log_prev_file).to_i
47
+ end
48
+ current_position = open(log_file){ |fd| fd.stat.size }
49
+ if current_position < previous_position
50
+ previous_position = 0
51
+ end
52
+
53
+ log_line = /\w, \[(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6}) \#(\d+):(-?\d+)\] ([\s\w]{5}) -- : (.+)/
54
+ lines = []
55
+
56
+ File.open(log_file, 'rb') do |f|
57
+ # seek to the last position in the log file
58
+ f.seek(previous_position, IO::SEEK_SET)
59
+ cnt = 0
60
+ f.each_line do |line|
61
+ prev_cnt = cnt
62
+ cnt += line.length
63
+ parts = log_line.match(line)
64
+ next unless parts
65
+ m, time, pid, thread, severity, details = *parts
66
+ sev = levels.index(severity.strip)
67
+ next unless sev
68
+ next unless sev >= lev
69
+ lines << [time, severity.strip, details]
70
+ end
71
+
72
+ end # File.open
73
+ File.open(log_prev_file, 'w'){ |f| f << current_position}
74
+ lines
75
+ end
76
+
77
+ def self.gather_configuration
78
+ res = ""
79
+ first = true
80
+ Dir.glob(File.join(Spider.paths[:config], '*.yml')).each do |f|
81
+ res << "\n\n" unless first
82
+ res << File.read(f)
83
+ first = false
84
+ end
85
+ res
86
+ end
87
+
88
+ end
89
+
90
+ end
data/apps/worker/cmd.rb CHANGED
@@ -34,15 +34,20 @@ module Spider; module Worker
34
34
  Worker.options[:fork] = false
35
35
  Worker.options[:detach] = false
36
36
  end
37
- Worker.start
37
+ Spider.conf.set('worker.enable', true)
38
+ #Worker.start
39
+ Spider.main_process_startup
38
40
  if (@daemonize)
41
+ Worker.start
39
42
  STDIN.reopen "/dev/null" # Free file descriptors and
40
43
  STDOUT.reopen "/dev/null", "a" # point them somewhere sensible
41
44
  STDERR.reopen STDOUT # STDOUT/STDERR should go to a logfile
42
45
  else
43
- # trap('TERM') { Worker.app_shutdown }
44
- # trap('INT') { Worker.app_shutdown }
46
+ Spider.startup
45
47
  Worker.join
48
+ # trap('TERM') { Spider.shutdown; exit }
49
+ # trap('INT') { Spider.shutdown; exit }
50
+ # Worker.join
46
51
  end
47
52
  end
48
53
  self.add_command(start)
@@ -50,7 +55,7 @@ module Spider; module Worker
50
55
  stop = CmdParse::Command.new('stop', false)
51
56
  stop.short_desc = _("Stop worker")
52
57
  stop.set_execution_block do
53
- Worker.app_shutdown
58
+ Spider.shutdown
54
59
  end
55
60
  self.add_command(stop)
56
61
 
@@ -33,7 +33,7 @@ module Spider
33
33
  end
34
34
 
35
35
  def self.app_shutdown
36
- return unless Spider.conf.get('worker.enable')
36
+ return unless @runner || Spider.conf.get('worker.enable')
37
37
  @mutex.try_lock || return
38
38
  Spider::Logger.info("Shutting down worker in #{Process.pid}")
39
39
  if @runner
@@ -41,7 +41,7 @@ module Spider
41
41
  @runner.stop
42
42
  @runner = nil
43
43
  end
44
- elsif(File.exist?(@pid_file))
44
+ elsif File.exist?(@pid_file)
45
45
  begin
46
46
  pid = IO.read(@pid_file).to_i
47
47
  unless pid == Process.pid
@@ -99,14 +99,19 @@ module Spider
99
99
  end
100
100
  end
101
101
  if (options[:fork])
102
- forked = Spider.fork do
102
+ Spider.logger.debug("Forking worker in #{Process.pid}")
103
+ @forked = Spider.fork do
103
104
  $0 = 'spider-worker'
104
- trap('TERM') { app_shutdown }
105
- trap('INT') { app_shutdown }
105
+ $SPIDER_NO_RESPAWN = true if $SPIDER_SPAWNED
106
+ Spider.main_process_startup
107
+ Spider.on_main_process_shutdown do
108
+ Worker.app_shutdown
109
+ end
106
110
  start.call
111
+ Spider.logger.debug("Forked worker started")
107
112
  @runner.join if @runner
108
113
  end
109
- Process.detach(forked) if (options[:detach])
114
+ Process.detach(@forked) if (options[:detach])
110
115
  @runner = nil
111
116
  else
112
117
  start.call
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'spiderfw/env'
5
+ require 'spiderfw/cmd/cmd'
6
+ cmd = Spider::CommandLine::Cmd.new
7
+ cmd.parse()
@@ -1,6 +1,5 @@
1
1
  runmode: 'devel'
2
- session.store: 'file'
3
- client.text_editor: 'textmate'
2
+ apps: ['core']
4
3
 
5
4
  storages:
6
5
  default:
@@ -9,4 +8,4 @@ storages:
9
8
  set devel:
10
9
  template.cache.disable: true
11
10
  debugger.start: true
12
- debug.console.level: DEBUG
11
+ log.level: DEBUG
@@ -1,3 +1,3 @@
1
- Spider.load_apps 'core'
1
+ Spider.load_apps
2
2
 
3
3
  Spider.route_apps