rsence 2.0.0.1.pre → 2.0.0.2.pre

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0.1.pre
1
+ 2.0.0.2.pre
data/lib/conf/argv.rb CHANGED
@@ -7,7 +7,7 @@
7
7
  # with this software package. If not, contact licensing@riassence.com
8
8
  ##
9
9
  #++
10
-
10
+ require 'daemon/sigcomm'
11
11
  module RSence
12
12
  def self.pid_support?
13
13
  # true for non-windows
@@ -27,8 +27,8 @@ end
27
27
  @@cmd_help = {}
28
28
 
29
29
  @@cmd_help[:head] = <<-EOF
30
- usage: rsence <command> [options] [args]
31
30
  RSence command-line tool, version #{@@version}
31
+
32
32
  EOF
33
33
 
34
34
  @@cmd_help[:unknown] = "Unknown command: "
@@ -36,6 +36,8 @@ EOF
36
36
  @@cmd_help[:help_help] = "Type 'rsence help' for usage."
37
37
 
38
38
  @@cmd_help[:help_main] = <<-EOF
39
+ usage: rsence <command> [options] [args]
40
+
39
41
  Type 'rsence help <command>' for help on a specific command.
40
42
 
41
43
  Available commands:
@@ -200,16 +202,31 @@ Available options:
200
202
 
201
203
  EOF
202
204
 
205
+ @@cmd_help[:save] = <<-EOF
206
+ usage: 'rsence save [options] [PATH]'
207
+
208
+ The 'save' command signals the RSence process to tell the plugins to save their
209
+ data and the session manager to save its session database.
210
+
211
+ Available options:
212
+
213
+ --conf <file.yaml> Use additional config file. You can give this option
214
+ several times. The <file.yaml> is the configuration
215
+ file to load.
216
+
217
+ --debug (-d) Debug mode. Shortcut for several options useful for
218
+ developers. Not the preferred mode for production.
219
+
220
+ --verbose (-v) More verbose output. Also enabled by --debug
221
+
222
+ #{@@cmd_help[:path]}
223
+
224
+ EOF
225
+
203
226
  @@cmd_help[:tail] = <<-EOF
204
227
  RSence is a self-contained rich internet application client-server framework.
205
228
  For further information, see http://rsence.org/
206
229
  EOF
207
-
208
- def initialize( argv )
209
- @argv = argv
210
- @startable = false
211
- parse_argv
212
- end
213
230
 
214
231
  def startable?; @startable; end
215
232
 
@@ -527,24 +544,16 @@ EOF
527
544
  end
528
545
  require 'conf/default'
529
546
  config = Configuration.new(@args).config
530
- # require 'daemon/daemon'
531
- # puts "status: #{HTTPDaemon.daemonize.inspect}"
532
547
  port = config[:http_server][:port]
533
548
  addr = config[:http_server][:bind_address]
534
549
  port_status = test_port( port, addr )
535
- # port_msg = port_status ? 'responds' : 'does not respond'
536
- # puts "TCP status: #{addr}:#{port} #{port_msg}" if @args[:verbose]
537
550
  if RSence.pid_support?
538
551
  pid_fn = config[:daemon][:pid_fn]
539
552
  if File.exists?( pid_fn )
540
553
  pid = File.read( pid_fn ).to_i
541
- begin
542
- pid_status = Process.kill('USR2',pid)
543
- rescue Errno::ESRCH
544
- pid_status = false
545
- end
546
- # pid_msg = pid_status == false ? 'not running' : 'responds'
547
- # puts "process id (#{pid}) #{pid_msg}" if @args[:verbose]
554
+ pid_status = RSence::SIGComm.wait_signal_response(
555
+ pid, pid_fn, 'USR2', 3
556
+ )
548
557
  else
549
558
  puts "no PID file, unable to check process status" if @args[:verbose]
550
559
  pid_status = nil
@@ -553,24 +562,109 @@ EOF
553
562
  puts "no PID support, unable to check process status" if @args[:verbose]
554
563
  pid_status = nil
555
564
  end
556
- if port_status
557
- puts "TCP response from #{addr} port #{port}"
558
- else
559
- puts "No TCP response from #{addr} port #{port}."
560
- end
561
565
  if RSence.pid_support?
562
566
  if pid_status == nil
563
567
  puts "No process id, unable to check process status."
564
568
  elsif pid_status == false
565
- puts "No process running."
569
+ puts "No process running#{port_status ? ' but something responds on ' : ' and nothing responds on ' }#{addr}:#{port}."
566
570
  else
567
- puts "Process id #{pid} responded with signal #{pid_status}."
571
+ puts "Process id #{pid} is running#{port_status ? ' and responds on ' : ', but does not respond on '}#{addr}:#{port}."
568
572
  end
569
573
  end
570
574
  end
571
575
 
572
576
  def parse_save_argv
573
- throw "parse_save_argv not implemented!"
577
+ init_args
578
+ expect_option = false
579
+ option_name = false
580
+ if @argv.length >= 2
581
+ @argv[1..-1].each_with_index do |arg,i|
582
+ if expect_option
583
+ if [:port,:latency].include?(option_name) and arg.to_i.to_s != arg
584
+ puts "invalid #{option_nam.to_s}, expected number: #{arg.inspect}"
585
+ puts "Type 'rsence help #{@cmd.to_s}' for usage."
586
+ exit
587
+ elsif option_name == :conf_files
588
+ if not File.exists?( arg ) or not File.file?( arg )
589
+ puts "no such configuration file: #{arg.inspect}"
590
+ puts "Type 'rsence help #{@cmd.to_s}' for usage."
591
+ exit
592
+ else
593
+ @args[:conf_files].push( arg )
594
+ end
595
+ else
596
+ @args[option_name] = arg
597
+ end
598
+ expect_option = false
599
+ else
600
+ if arg.start_with?('--')
601
+ if arg == '--debug'
602
+ set_debug
603
+ elsif arg == '--verbose'
604
+ set_verbose
605
+ elsif arg == '--conf' or arg == '--config'
606
+ expect_option = true
607
+ option_name = :conf_files
608
+ else
609
+ invalid_option(arg)
610
+ end
611
+ elsif arg.start_with?('-')
612
+ arg.split('')[1..-1].each do |chr|
613
+ if chr == 'd'
614
+ set_debug
615
+ elsif chr == 'v'
616
+ set_verbose
617
+ else
618
+ invalid_option(arg,chr)
619
+ end
620
+ end
621
+ elsif valid_env?(arg)
622
+ @args[:env_path] = File.expand_path(arg)
623
+ @args[:conf_files].push( File.expand_path( File.join( arg, 'conf', 'config.yaml' ) ) )
624
+ else
625
+ invalid_env( arg )
626
+ end
627
+ end
628
+ end
629
+ if expect_option
630
+ puts "no value for option #{option_name.to_s.inspect}"
631
+ puts "Type 'rsence help #{@cmd.to_s} for usage."
632
+ exit
633
+ end
634
+ end
635
+ if valid_env?(@args[:env_path])
636
+ conf_file = File.expand_path( File.join( @args[:env_path], 'conf', 'config.yaml' ) )
637
+ @args[:conf_files].push( conf_file ) unless @args[:conf_files].include?( conf_file )
638
+ else
639
+ puts "invalid environment."
640
+ exit
641
+ end
642
+ require 'conf/default'
643
+ config = Configuration.new(@args).config
644
+ if RSence.pid_support?
645
+ pid_fn = config[:daemon][:pid_fn]
646
+ if File.exists?( pid_fn )
647
+ pid = File.read( pid_fn ).to_i
648
+ pid_status = RSence::SIGComm.wait_signal_response(
649
+ pid, pid_fn, 'USR1', 30, 'Saving session data...', '.', 0.1, true
650
+ )
651
+ else
652
+ puts "no PID file, unable to signal the save command to the process" if @args[:verbose]
653
+ pid_status = nil
654
+ end
655
+ else
656
+ puts "no PID support, unable to signal the save command to the process" if @args[:verbose]
657
+ pid_status = nil
658
+ end
659
+ if RSence.pid_support?
660
+ if pid_status == nil
661
+ puts "No process id, unable to signal the save command to the process."
662
+ elsif pid_status == false
663
+ puts "No process running."
664
+ else
665
+ puts "Session data saved."
666
+ end
667
+ end
574
668
  end
575
669
 
576
670
  def parse_setup_argv
@@ -581,6 +675,29 @@ EOF
581
675
  throw "parse_initenv_argv not implemented!"
582
676
  end
583
677
 
678
+ def help( cmd )
679
+ cmd.to_sym! if cmd.class != Symbol
680
+ puts @@cmd_help[:head]
681
+ if @@cmd_help.has_key?(cmd)
682
+ puts @@cmd_help[cmd]
683
+ else
684
+ puts @@cmd_help[:help_main]
685
+ end
686
+ puts @@cmd_help[:tail]
687
+ end
688
+
689
+ def version
690
+ @@version
691
+ end
692
+
693
+ def cmd
694
+ @cmd
695
+ end
696
+
697
+ def args
698
+ @args
699
+ end
700
+
584
701
  def parse_argv
585
702
  if @argv.empty?
586
703
  puts @@cmd_help[:help_help]
@@ -614,37 +731,23 @@ EOF
614
731
  end
615
732
  end
616
733
 
617
- def help( cmd )
618
- cmd.to_sym! if cmd.class != Symbol
619
- puts @@cmd_help[:head]
620
- if @@cmd_help.has_key?(cmd)
621
- puts @@cmd_help[cmd]
622
- else
623
- puts @@cmd_help[:help_main]
624
- end
625
- puts @@cmd_help[:tail]
626
- end
627
-
628
- def version
629
- puts @@version
630
- end
631
-
632
- def cmd
633
- @cmd
734
+ def parse( argv )
735
+ @argv = argv
736
+ @startable = false
737
+ parse_argv
634
738
  end
635
739
 
636
- def args
637
- @args
740
+ def initialize
741
+ @startable = false
638
742
  end
639
743
 
640
744
  end
641
745
 
642
- @@argv_parser = ARGVParser.new( ARGV )
643
-
644
746
  def self.argv; @@argv_parser; end
645
747
  def self.cmd; @@argv_parser.cmd; end
646
748
  def self.args; @@argv_parser.args; end
647
749
  def self.startable?; @@argv_parser.startable?; end
750
+ def self.version; @@argv_parser.version; end
648
751
  def self.startup
649
752
  puts "Loading configuration..." if self.args[:verbose]
650
753
  # Use the default configuration:
@@ -659,6 +762,8 @@ def self.startup
659
762
  daemon = HTTPDaemon.new
660
763
  daemon.daemonize!
661
764
  end
765
+ @@argv_parser = ARGVParser.new
766
+ @@argv_parser.parse( ARGV )
662
767
 
663
768
  end
664
769
 
data/lib/daemon/daemon.rb CHANGED
@@ -34,9 +34,6 @@ RSence.config[:http_server][:rack_handler] = self.method({
34
34
  'rainbows' => :rack_rainbows_handler
35
35
  }[RSence.config[:http_server][:rack_require]]).call
36
36
 
37
- # Debug mode switch. The debug mode is intended for developers, not production.
38
- $DEBUG_MODE = RSence.config[:debug_mode]
39
-
40
37
  # Transporter is the top-level handler for calls coming from the javascript COMM.Transporter.
41
38
  require 'transporter/transporter'
42
39
 
@@ -92,53 +89,21 @@ module Daemon
92
89
  end
93
90
 
94
91
  def self.write_signal_response( daemon, signal )
95
- sig_fn = daemon.pid_fn+'.response.'+signal
96
- File.open(sig_fn,'w') do |file|
97
- file.write(Process.pid.to_s)
98
- end
92
+ pid = Process.pid.to_s
93
+ pid_fn = daemon.pid_fn
94
+ RSence::SIGComm.write_signal_response( pid, pid_fn, signal )
99
95
  end
100
96
 
101
97
  def self.delete_signal_response( daemon, signal )
102
- sig_fn = daemon.pid_fn+'.response.'+signal
103
- if File.file?( sig_fn )
104
- File.delete( sig_fn )
105
- end
98
+ pid_fn = daemon.pid_fn
99
+ RSence::SIGComm.delete_signal_response( pid_fn )
106
100
  end
107
101
 
108
102
  def self.wait_signal_response( daemon, signal, timeout = 10,
109
- debug_pre = '<', debug_suf = '>', sleep_secs = 0.2 )
110
- begin
111
- if RSence.args[:verbose]
112
- print debug_pre
113
- STDOUT.flush
114
- end
115
- pid = read_pid( daemon )
116
- sig_fn = daemon.pid_fn+'.response.'+signal
117
- File.delete( sig_fn ) if File.file?( sig_fn )
118
- status = Process.kill( signal, pid )
119
- time_out = Time.now + timeout
120
- until time_out > Time.now or File.file?( sig_fn )
121
- if RSence.args[:verbose]
122
- print "."
123
- STDOUT.flush
124
- end
125
- sleep sleep_secs
126
- end
127
- sleep sleep_secs
128
- if File.file?( sig_fn )
129
- sig_pid = File.read( sig_fn ).to_i
130
- if sig_pid != pid
131
- puts "Warning, signal PID mismatch. Expected #{pid}, got #{sig_pid}"
132
- end
133
- File.delete( sig_fn )
134
- else
135
- puts "Warning, signal response file disappeared! Expected #{sig_fn}"
136
- end
137
- puts debug_suf if RSence.args[:verbose]
138
- return true
139
- rescue Errno::ESRCH
140
- return false
141
- end
103
+ debug_pre = false, debug_suf = false, sleep_secs = 0.2 )
104
+ pid = read_pid( daemon )
105
+ pid_fn = daemon.pid_fn
106
+ return RSence::SIGComm.wait_signal_response( pid, pid_fn, signal, timeout, debug_pre, debug_suf, sleep_secs )
142
107
  end
143
108
 
144
109
  # Traps common kill signals
@@ -158,20 +123,30 @@ module Daemon
158
123
  puts "RSence killed with signal #{signal.inspect}" if RSence.args[:verbose]
159
124
  daemon.usr1
160
125
  daemon.stop
161
- # delete_signal_response( daemon, 'USR1' )
162
- # delete_signal_response( daemon, 'USR2' )
163
- File.delete( daemon.pid_fn ) if File.file?( daemon.pid_fn )
126
+ delete_stale_pids( daemon )
164
127
  write_signal_response( daemon, signal )
165
128
  puts "Shutdown complete."
166
129
  exit
167
130
  end
168
131
  end
169
- # Signal.trap('HUP') do
170
- # daemon.restart
171
- # end
132
+ Signal.trap('HUP') do
133
+ daemon.stop
134
+ daemon.start
135
+ end
136
+ end
137
+
138
+ def self.delete_stale_pids( daemon )
139
+ ( pid_fn_path, pid_fn_name ) = File.split( daemon.pid_fn )
140
+ Dir.entries( pid_fn_path ).each do | item_fn |
141
+ item_path = File.join( pid_fn_path, item_fn )
142
+ if item_fn.start_with?( pid_fn_name ) and File.file?( item_path )
143
+ puts "Stale pid file (#{item_fn}), removing.." if RSence.args[:verbose]
144
+ File.delete( item_path )
145
+ end
146
+ end
172
147
  end
173
148
 
174
- def self.handle_pid( daemon )
149
+ def self.init_pid( daemon )
175
150
  if RSence.pid_support?
176
151
  is_running = status( daemon )
177
152
  if is_running
@@ -181,9 +156,8 @@ module Daemon
181
156
  Process.kill( 'INT', RSence.launch_pid )
182
157
  end
183
158
  exit
184
- elsif not is_running and File.file?( daemon.pid_fn )
185
- puts "Stale pid file, removing.."
186
- File.delete( daemon.pid_fn )
159
+ elsif not is_running
160
+ delete_stale_pids( daemon )
187
161
  end
188
162
  trap_signals( daemon )
189
163
  pid = Process.pid
@@ -195,7 +169,7 @@ module Daemon
195
169
  end
196
170
 
197
171
  def self.run( daemon )
198
- handle_pid( daemon )
172
+ init_pid( daemon )
199
173
  daemon.run
200
174
  exit
201
175
  end
@@ -203,7 +177,7 @@ module Daemon
203
177
  def self.start( daemon )
204
178
  fork do
205
179
  exit if fork
206
- handle_pid( daemon )
180
+ init_pid( daemon )
207
181
  daemon.start
208
182
  end
209
183
  Signal.trap('INT') do
@@ -248,7 +222,7 @@ module Daemon
248
222
  puts "RSence might still be running, please ensure manually."
249
223
  end
250
224
  elsif status_ == false
251
- puts "Warning, no such process (#{pid}) running."
225
+ puts "Warning, no such process (#{read_pid(daemon)}) running."
252
226
  elsif status_ == nil
253
227
  puts "Warning, no pid file (process not running)."
254
228
  else
@@ -366,7 +340,7 @@ class HTTPDaemon
366
340
 
367
341
  # Called on USR2 signals ("Alive?")
368
342
  def usr2
369
- puts "Alive."
343
+ puts "#{Time.now.strftime('%Y-%m-%d %H:%M:%S')} -- RSence version #{RSence.version} is running."
370
344
  end
371
345
 
372
346
  # Main entry point, daemonizes itself using Controller.
@@ -0,0 +1,64 @@
1
+ #--
2
+ ## Riassence Framework
3
+ # Copyright 2010 Riassence Inc.
4
+ # http://riassence.com/
5
+ #
6
+ # You should have received a copy of the GNU General Public License along
7
+ # with this software package. If not, contact licensing@riassence.com
8
+ ##
9
+ #++
10
+
11
+ # RSence async signal communication handler, uses temporary files for communication.
12
+ # Utilized by ARGVParser and Daemon.
13
+
14
+ module RSence
15
+ module SIGComm
16
+ def self.delete_signal_response( pid_fn )
17
+ sig_fn = pid_fn+'.response.'+signal
18
+ if File.file?( sig_fn )
19
+ File.delete( sig_fn )
20
+ end
21
+ end
22
+ def self.write_signal_response( pid, pid_fn, signal )
23
+ sig_fn = pid_fn+'.response.'+signal
24
+ File.open(sig_fn,'w') do |file|
25
+ file.write( pid.to_s )
26
+ end
27
+ end
28
+ def self.wait_signal_response( pid, pid_fn, signal, timeout = 10,
29
+ debug_pre = false, debug_suf = false,
30
+ sleep_secs = 0.2, verbose=nil )
31
+ sig_fn = pid_fn+'.response.'+signal
32
+ verbose = RSence.args[:verbose] if verbose == nil
33
+ begin
34
+ if verbose and debug_pre
35
+ print debug_pre
36
+ end
37
+ File.delete( sig_fn ) if File.exists?( sig_fn )
38
+ status = Process.kill( signal, pid )
39
+ time_out = Time.now + timeout
40
+ until (time_out < Time.now) or File.exists?( sig_fn )
41
+ if verbose
42
+ print "."
43
+ STDOUT.flush
44
+ end
45
+ sleep sleep_secs
46
+ end
47
+ if File.file?( sig_fn )
48
+ sig_pid = File.read( sig_fn ).to_i
49
+ if sig_pid != pid
50
+ puts "Warning, signal PID mismatch. Expected #{pid}, got #{sig_pid}"
51
+ end
52
+ File.delete( sig_fn )
53
+ else
54
+ puts "Warning, signal response file disappeared! Expected #{sig_fn}"
55
+ end
56
+ puts debug_suf if verbose and debug_suf
57
+ return true
58
+ rescue Errno::ESRCH
59
+ return false
60
+ end
61
+ end
62
+ end
63
+ end
64
+
data/lib/http/broker.rb CHANGED
@@ -66,7 +66,7 @@ class Broker
66
66
  end
67
67
 
68
68
  def not_found
69
- puts "/404: #{@request.fullpath.inspect}" if $DEBUG_MODE
69
+ puts "/404: #{@request.fullpath.inspect}" if RSence.args[:verbose]
70
70
  @response.status = 404
71
71
  err404 = '<html><head><title>404 - Page Not Found</title></head><body>404 - Page Not Found</body></html>'
72
72
  @response['content-type'] = 'text/html; charset=UTF-8'
@@ -77,7 +77,7 @@ class Broker
77
77
  ## Post requests are always xhr requests
78
78
  def post
79
79
 
80
- puts "post: #{@request.fullpath}" if $DEBUG_MODE
80
+ puts "post: #{@request.fullpath}" if RSence.args[:verbose]
81
81
 
82
82
  sleep @@ping_sim if @@ping_sim
83
83
 
@@ -88,7 +88,7 @@ class Broker
88
88
  ## Get requests are different, depending on the uri requested
89
89
  def get
90
90
 
91
- puts "get: #{@request.fullpath}" if $DEBUG_MODE
91
+ puts "get: #{@request.fullpath}" if RSence.args[:verbose]
92
92
 
93
93
  sleep @@ping_sim if @@ping_sim
94
94
 
@@ -362,7 +362,7 @@ class SessionManager < SessionStorage
362
362
  end
363
363
 
364
364
  if domain == 'localhost'
365
- # warn "Warning: Cookies won't be set for 'localhost'. Use '127.0.0.1' instead." if $DEBUG_MODE
365
+ warn "Warning: Cookies won't be set for 'localhost'. Use '127.0.0.1' instead." if RSence.args[:debug]
366
366
  return
367
367
  end
368
368
 
@@ -101,7 +101,7 @@ class SessionStorage
101
101
  def create_session_table
102
102
  db_open
103
103
  unless @db.table_exists?(:rsence_session)
104
- puts "Creating session table..." if $DEBUG_MODE
104
+ puts "Creating session table..." if RSence.args[:verbose]
105
105
  @db.create_table :rsence_session do
106
106
  primary_key( :id )
107
107
  column( :cookie_key, String )
@@ -121,7 +121,7 @@ class SessionStorage
121
121
  def create_version_table
122
122
  db_open
123
123
  unless @db.table_exists?(:rsence_version)
124
- puts "Creating version info table..." if $DEBUG_MODE
124
+ puts "Creating version info table..." if RSence.args[:verbose]
125
125
  @db.create_table :rsence_version do
126
126
  Integer :version
127
127
  end
@@ -135,7 +135,7 @@ class SessionStorage
135
135
  def create_uploads_table
136
136
  db_open
137
137
  unless @db.table_exists?(:rsence_uploads)
138
- puts "Creating uploads table..." if $DEBUG_MODE
138
+ puts "Creating uploads table..." if RSence.args[:verbose]
139
139
  @db.create_table :rsence_uploads do
140
140
  primary_key( :id )
141
141
  foreign_key( :ses_id, :rsence_session )
@@ -189,7 +189,7 @@ class SessionStorage
189
189
 
190
190
  ## Restores all saved sessions from db to ram
191
191
  def restore_sessions
192
- puts "Restoring sessions..." if $DEBUG_MODE
192
+ puts "Restoring sessions..." if RSence.args[:verbose]
193
193
  db_open
194
194
  @db[:rsence_session].all do |ses_row|
195
195
  ses_id = ses_row[:id]
@@ -211,7 +211,7 @@ class SessionStorage
211
211
 
212
212
  ## Stores all sessions to db from ram
213
213
  def store_sessions
214
- puts "Storing sessions..." if $DEBUG_MODE
214
+ puts "Storing sessions..." if RSence.args[:verbose]
215
215
  db_open
216
216
  @sessions.each_key do |ses_id|
217
217
  ses_data = @sessions[ ses_id ]
@@ -233,9 +233,9 @@ class SessionStorage
233
233
  ## Shut-down signal, triggers store_sessions for now
234
234
  def shutdown
235
235
  @accept_requests = false
236
- puts "Session shutdown in progress..." if $DEBUG_MODE
236
+ puts "Session shutdown in progress..." if RSence.args[:verbose]
237
237
  store_sessions
238
- puts "Session shutdown complete." if $DEBUG_MODE
238
+ puts "Session shutdown complete." if RSence.args[:verbose]
239
239
  end
240
240
 
241
241
 
@@ -33,7 +33,7 @@ class Transporter
33
33
 
34
34
  @valuemanager = ValueManager.new
35
35
  @sessions = SessionManager.new( self )
36
- @plugins = PluginManager.new( ::RSence.config[:plugin_paths], self, $DEBUG_MODE )
36
+ @plugins = PluginManager.new( ::RSence.config[:plugin_paths], self, RSence.args[:autoreload] )
37
37
  if RSence.launch_pid != Process.pid
38
38
  Process.kill( 'TERM', RSence.launch_pid )
39
39
  end
@@ -42,25 +42,6 @@ class Transporter
42
42
  def servlet( request_type, request, response )
43
43
  broker_urls = ::RSence.config[:broker_urls]
44
44
  uri = request.fullpath
45
- # if $DEBUG_MODE and uri == $config[:index_html][:respond_address] and request_type == :get
46
- # unless ARGV.include?('-no-rescan') or ARGV.include?('--no-rescan')
47
- # puts "Reloading plugins."
48
- # if RSence.args[:say]
49
- # Thread.new do
50
- # Thread.pass
51
- # system('say "Reloading plugins."')
52
- # end
53
- # end
54
- # @plugins.rescan
55
- # puts "Plugins reloaded."
56
- # if RSence.args[:say]
57
- # Thread.new do
58
- # Thread.pass
59
- # system('say "Plugins reloaded."')
60
- # end
61
- # end
62
- # end
63
- # end
64
45
 
65
46
  if request_type == :post
66
47
  ## /x handles xhr without cookies
@@ -74,10 +55,6 @@ class Transporter
74
55
  else
75
56
  session = {}
76
57
  return @plugins.match_servlet( request_type, request, response, session )
77
- ## /SOAP handles SOAP Requests
78
- # elsif uri == broker_urls[:soap]
79
- # soap( request, response )
80
- # return true
81
58
  end
82
59
  else
83
60
  session = {}
@@ -85,11 +62,6 @@ class Transporter
85
62
  end
86
63
  end
87
64
 
88
- ## handles incoming SOAP requests
89
- # def soap(request, response)
90
- # PluginManager.soap( request, response )
91
- # end
92
-
93
65
  # wrapper for the session manager stop client functionality
94
66
  def xhr_error_handler(msg,err_name,err_extra_descr='')
95
67
  @sessions.stop_client_with_message( msg,
@@ -101,9 +73,9 @@ class Transporter
101
73
 
102
74
  # wrapper for tracebacks in xhr
103
75
  def xhr_traceback_handler(e,err_descr='Transporter::UnspecifiedError')
104
- puts "=="*40 if $DEBUG_MODE
76
+ puts "=="*40 if RSence.args[:debug]
105
77
  puts err_descr
106
- if $DEBUG_MODE
78
+ if RSence.args[:debug]
107
79
  puts "--"*40
108
80
  puts e.message
109
81
  puts " #{e.backtrace.join("\n ")}"
@@ -131,7 +103,7 @@ class Transporter
131
103
  if request.query.has_key?('err_msg')
132
104
  response_success = false
133
105
  client_error_msg = request.query['err_msg'].inspect
134
- puts "\nCLIENT ERROR:\n#{client_error_msg}\n" if $DEBUG_MODE
106
+ puts "\nCLIENT ERROR:\n#{client_error_msg}\n" if RSence.args[:debug]
135
107
  xhr_error_handler(msg,:client_error,client_error_msg)
136
108
  end
137
109
 
@@ -144,11 +116,11 @@ class Transporter
144
116
  msg.reply("COMM.Transporter.url=#{::RSence.config[:broker_urls][:x].to_json};")
145
117
  end
146
118
 
147
- # Appends a 'new session.' message for new sessions in $DEBUG_MODE:
148
- puts "new session." if msg.new_session and $DEBUG_MODE
149
- puts "restored session." if msg.restored_session and $DEBUG_MODE
150
- puts "clone source." if msg.cloned_targets and $DEBUG_MODE
151
- puts "clone target." if msg.cloned_source and $DEBUG_MODE
119
+ # Appends a 'new session.' message for new sessions in RSence.args[:verbose]:
120
+ puts "new session." if msg.new_session and RSence.args[:verbose]
121
+ puts "restored session." if msg.restored_session and RSence.args[:verbose]
122
+ puts "clone source." if msg.cloned_targets and RSence.args[:verbose]
123
+ puts "clone target." if msg.cloned_source and RSence.args[:verbose]
152
124
 
153
125
  ## Pass the client XML to the value manager
154
126
  if request.query.has_key?( 'values' )
@@ -99,7 +99,7 @@ class ClientPkg < Servlet
99
99
  end
100
100
 
101
101
  def open
102
- if not @thr and $DEBUG_MODE
102
+ if not @thr and RSence.args[:autoupdate]
103
103
  @thr = Thread.new do
104
104
  Thread.pass
105
105
  while true
@@ -320,8 +320,6 @@ class ClientPkgBuild
320
320
  minimize_data
321
321
  build_themes
322
322
 
323
- #save_file( File.join( @js_dst_dir, 'built' ), Time.now.to_i.to_s )
324
-
325
323
  end
326
324
 
327
325
  def setup_dirs
@@ -498,8 +496,8 @@ class ClientPkgBuild
498
496
  @no_obfuscation = config[:no_obfuscation]
499
497
  @no_whitespace_removal = config[:no_whitespace_removal]
500
498
  @js_inc = config[:js_inc]
501
- @debug = (not $DEBUG_MODE)
502
- @quiet = (not $DEBUG_MODE)
499
+ @debug = (not RSence.args[:debug])
500
+ @quiet = (not RSence.args[:verbose])
503
501
  end
504
502
 
505
503
  def find_newer( src_dir, newer_than )
@@ -529,19 +527,6 @@ class ClientPkgBuild
529
527
  return false
530
528
  end
531
529
 
532
- ##def autorun
533
- ## while true
534
- ## newest = read_file( File.join( @js_dst_dir, 'built' ) ).to_i
535
- ## @logger.log( "waiting for changes..." )
536
- ## until bundle_changes( newest )
537
- ## sleep 3
538
- ## end
539
- ## flush
540
- ## run
541
- ## `say "Autobuild complete!"` if RSence.args[:say]
542
- ## end
543
- ##end
544
-
545
530
  def print_stat( package_name, dst_size, jsc_size, gz_size )
546
531
  percent = 'n/a'
547
532
  if dst_size > 0
@@ -154,14 +154,14 @@ module ClientPkgServe
154
154
  if not has_theme
155
155
  response.status = 404
156
156
  response.body = '404 - Theme Not Found'
157
- puts "Theme #{theme_name} not found, avail: #{@client_cache.theme_cache.keys.join(', ')}" if $DEBUG_MODE
157
+ puts "Theme #{theme_name} not found, avail: #{@client_cache.theme_cache.keys.join(', ')}" if RSence.args[:verbose]
158
158
  elsif not has_theme_part
159
159
  response.status = 503
160
160
  response.body = '503 - Invalid Theme Part Request'
161
161
  elsif not has_theme_file
162
162
  response.status = 404
163
163
  response.body = '404 - Theme Resource Not Found'
164
- puts "File not found, avail: #{@client_cache.theme_cache[theme_name][theme_part].keys.join(', ')}" if $DEBUG_MODE
164
+ puts "File not found, avail: #{@client_cache.theme_cache[theme_name][theme_part].keys.join(', ')}" if RSence.args[:verbose]
165
165
  else
166
166
 
167
167
  response.status = 200
data/plugins/main/main.rb CHANGED
@@ -154,7 +154,7 @@ class Main < Plugin
154
154
  until time_taken > 0.2 or ses[:delayed_calls].size == 0 or call_count == 0
155
155
  # gets the next call
156
156
  delayed_call = ses[:delayed_calls].shift
157
- if $DEBUG_MODE
157
+ if RSence.args[:debug]
158
158
  puts "delayed_call: #{delayed_call.inspect}"
159
159
  end
160
160
  # strings are always javascript, used for segmenting client load
@@ -43,7 +43,7 @@ module Common
43
43
 
44
44
  # checks, that the format is a supported image type
45
45
  unless @content_types.keys.include?( format )
46
- puts "ImgServe.serve: invalid format (#{format.inspect})" if $DEBUG_MODE
46
+ puts "ImgServe.serve: invalid format (#{format.inspect})" if RSence.args[:verbose]
47
47
  return File.join(::RSence.config[:broker_urls][:i],'invalid.gif')
48
48
  end
49
49
 
@@ -150,18 +150,18 @@ module Common
150
150
  img_id = req.unparsed_uri.match(/^#{::RSence.config[:broker_urls][:i]}(.*)$/)[1]
151
151
 
152
152
  if img_id == nil
153
- puts "ImgServe.fetch_img: invalid uri#1 (#{req.unparsed_uri.inspect})" if $DEBUG_MODE
153
+ puts "ImgServe.fetch_img: invalid uri#1 (#{req.unparsed_uri.inspect})" if RSence.args[:verbose]
154
154
  img_id = 'invalid.gif'
155
155
  end
156
156
 
157
157
  img_id = img_id.split('.')[0]
158
158
 
159
159
  if img_id == nil
160
- puts "ImgServe.fetch_img: invalid uri#2 (#{req.unparsed_uri.inspect})" if $DEBUG_MODE
160
+ puts "ImgServe.fetch_img: invalid uri#2 (#{req.unparsed_uri.inspect})" if RSence.args[:verbose]
161
161
  img_id = 'invalid.gif'
162
162
 
163
163
  elsif img_id.size != 84
164
- puts "ImgServe.fetch_img: invalid img_id (#{img_id.inspect})" if $DEBUG_MODE
164
+ puts "ImgServe.fetch_img: invalid img_id (#{img_id.inspect})" if RSence.args[:verbose]
165
165
  img_id = 'invalid.gif'
166
166
  end
167
167
 
@@ -200,15 +200,15 @@ module Common
200
200
  elsif type == :file
201
201
  file_id = req.unparsed_uri.match(/^#{::RSence.config[:broker_urls][:f]}(.*)$/)[1]
202
202
  if file_id == nil
203
- puts "fileServe.fetch_file: invalid uri#1 (#{req.unparsed_uri.inspect})" if $DEBUG_MODE
203
+ puts "fileServe.fetch_file: invalid uri#1 (#{req.unparsed_uri.inspect})" if RSence.args[:verbose]
204
204
  file_id = 'invalid.gif'
205
205
  end
206
206
  file_id = file_id.split('.')[0]
207
207
  if file_id == nil
208
- puts "fileServe.fetch_file: invalid uri#2 (#{req.unparsed_uri.inspect})" if $DEBUG_MODE
208
+ puts "fileServe.fetch_file: invalid uri#2 (#{req.unparsed_uri.inspect})" if RSence.args[:verbose]
209
209
  file_id = 'invalid.gif'
210
210
  elsif file_id.size != 84
211
- puts "fileServe.fetch_file: invalid file_id (#{file_id.inspect})" if $DEBUG_MODE
211
+ puts "fileServe.fetch_file: invalid file_id (#{file_id.inspect})" if RSence.args[:verbose]
212
212
  file_id = 'invalid.gif'
213
213
  end
214
214
  if @raw_uris.include?(file_id)
@@ -231,14 +231,14 @@ module Common
231
231
  elsif type == :blobobj
232
232
  blobobj_id = req.unparsed_uri.match(/^#{::RSence.config[:broker_urls][:b]}(.*)$/)[1]
233
233
  if blobobj_id == nil
234
- puts "fileServe.fetch_blobobj: invalid uri#1 (#{req.unparsed_uri.inspect})" if $DEBUG_MODE
234
+ puts "fileServe.fetch_blobobj: invalid uri#1 (#{req.unparsed_uri.inspect})" if RSence.args[:verbose]
235
235
  blobobj_id = 'invalid.gif'
236
236
  end
237
237
  if blobobj_id == nil
238
- puts "fileServe.fetch_blobobj: invalid uri#2 (#{req.unparsed_uri.inspect})" if $DEBUG_MODE
238
+ puts "fileServe.fetch_blobobj: invalid uri#2 (#{req.unparsed_uri.inspect})" if RSence.args[:verbose]
239
239
  blobobj_id = 'invalid.gif'
240
240
  elsif blobobj_id.size != 84
241
- puts "fileServe.fetch_blobobj: invalid blobobj_id (#{blobobj_id.inspect})" if $DEBUG_MODE
241
+ puts "fileServe.fetch_blobobj: invalid blobobj_id (#{blobobj_id.inspect})" if RSence.args[:verbose]
242
242
  blobobj_id = 'invalid.gif'
243
243
  end
244
244
  if @raw_uris.include?(blobobj_id)
@@ -266,15 +266,15 @@ module Common
266
266
  elsif type == :rsrc
267
267
  rsrc_id = req.unparsed_uri.match(/^#{::RSence.config[:broker_urls][:d]}(.*)$/)[1]
268
268
  if rsrc_id == nil
269
- puts "rsrcServe.fetch_rsrc: invalid uri#1 (#{req.unparsed_uri.inspect})" if $DEBUG_MODE
269
+ puts "rsrcServe.fetch_rsrc: invalid uri#1 (#{req.unparsed_uri.inspect})" if RSence.args[:verbose]
270
270
  rsrc_id = 'invalid.gif'
271
271
  end
272
272
  rsrc_id = rsrc_id.split('.')[0]
273
273
  if rsrc_id == nil
274
- puts "rsrcServe.fetch_rsrc: invalid uri#2 (#{req.unparsed_uri.inspect})" if $DEBUG_MODE
274
+ puts "rsrcServe.fetch_rsrc: invalid uri#2 (#{req.unparsed_uri.inspect})" if RSence.args[:verbose]
275
275
  rsrc_id = 'invalid.gif'
276
276
  elsif rsrc_id.size != 84
277
- puts "rsrcServe.fetch_rsrc: invalid rsrc_id (#{rsrc_id.inspect})" if $DEBUG_MODE
277
+ puts "rsrcServe.fetch_rsrc: invalid rsrc_id (#{rsrc_id.inspect})" if RSence.args[:verbose]
278
278
  rsrc_id = 'invalid.gif'
279
279
  end
280
280
  if @raw_uris.include?(rsrc_id)
@@ -83,21 +83,21 @@ class TicketServe < Servlet
83
83
  def get( req, res, ses )
84
84
  uri = req.fullpath
85
85
  if uri.match( /^#{broker_urls[:i]}/ )
86
- # puts "/i: #{uri.inspect}" if $DEBUG_MODE
86
+ puts "/i: #{uri.inspect}" if RSence.args[:verbose]
87
87
  get_ticket( req, res, :img )
88
88
  elsif uri.match( /^#{broker_urls[:d]}/ )
89
- # puts "/d: #{uri.inspect}" if $DEBUG_MODE
89
+ puts "/d: #{uri.inspect}" if RSence.args[:verbose]
90
90
  get_ticket( req, res, :rsrc )
91
91
  elsif uri.match( /^#{broker_urls[:f]}/ )
92
- # puts "/f: #{uri.inspect}" if $DEBUG_MODE
92
+ puts "/f: #{uri.inspect}" if RSence.args[:verbose]
93
93
  get_ticket( req, res, :file )
94
94
  elsif uri.match( /^#{broker_urls[:b]}/ )
95
- # puts "/b: #{uri.inspect}" if $DEBUG_MODE
95
+ puts "/b: #{uri.inspect}" if RSence.args[:verbose]
96
96
  get_ticket( req, res, :blobobj )
97
97
  elsif uri == broker_urls[:favicon]
98
98
  favicon( req, res )
99
99
  elsif uri == broker_urls[:uploader_iframe]
100
- # puts "/U/iframe_html: #{uri.inspect}" if $DEBUG_MODE
100
+ puts "/U/iframe_html: #{uri.inspect}" if RSence.args[:verbose]
101
101
  res.status = 200
102
102
  http_body = '<html><head><title>Empty Iframe for Uploading</title></head><body></body></html>'
103
103
  res['content-type'] = 'text/html; charset=UTF-8'
@@ -109,7 +109,7 @@ class TicketServe < Servlet
109
109
  def post( req, res, ses )
110
110
  uri = req.fullpath
111
111
  if uri[0..2] == broker_urls[:u]
112
- puts "/U: #{uri.inspect}" if $DEBUG_MODE
112
+ puts "/U: #{uri.inspect}" if RSence.args[:verbose]
113
113
  upload( req, res )
114
114
  end
115
115
  end
metadata CHANGED
@@ -6,9 +6,9 @@ version: !ruby/object:Gem::Version
6
6
  - 2
7
7
  - 0
8
8
  - 0
9
- - 1
9
+ - 2
10
10
  - pre
11
- version: 2.0.0.1.pre
11
+ version: 2.0.0.2.pre
12
12
  platform: ruby
13
13
  authors:
14
14
  - Riassence Inc.
@@ -47,6 +47,7 @@ files:
47
47
  - lib/conf/default.rb
48
48
  - lib/conf/wizard.rb
49
49
  - lib/daemon/daemon.rb
50
+ - lib/daemon/sigcomm.rb
50
51
  - lib/http/broker.rb
51
52
  - lib/http/rackup.rb
52
53
  - lib/http/request.rb