rsence 2.0.0.5.pre → 2.0.0.6.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -2
- data/VERSION +1 -1
- data/bin/rsence +4 -1
- data/conf/default_conf.yaml +1 -1
- data/conf/rsence_command_strings.yaml +444 -0
- data/js/comm/comm/autosync/autosync.js +1 -1
- data/js/comm/comm/comm.js +1 -1
- data/js/comm/comm/queue/queue.js +1 -1
- data/js/comm/comm/session/session.js +1 -1
- data/js/comm/comm/sessionwatcher/sessionwatcher.js +1 -1
- data/js/comm/comm/transporter/transporter.js +1 -1
- data/js/comm/comm/urlresponder/urlresponder.js +1 -1
- data/js/comm/comm/values/values.js +1 -1
- data/js/comm/jsloader/jsloader.js +1 -1
- data/js/comm/reloadapp/reloadapp.js +1 -1
- data/js/comm/sha/sha.js +1 -1
- data/js/comm/values/value/value.js +1 -1
- data/js/comm/values/valuematrix/valuematrix.js +1 -1
- data/js/controls/button/button.js +1 -1
- data/js/controls/checkbox/checkbox.js +1 -1
- data/js/controls/datetime/calendar/calendar.js +1 -1
- data/js/controls/datetime/datetimevalue/datetimevalue.js +1 -1
- data/js/controls/datetime/timesheet/timesheet.js +1 -1
- data/js/controls/datetime/timesheet_item/timesheet_item.js +1 -1
- data/js/controls/datetime/timesheet_item_edit/timesheet_item_edit.js +1 -1
- data/js/controls/dialogs/alert_sheet/alert_sheet.js +1 -1
- data/js/controls/dialogs/confirm_sheet/confirm_sheet.js +1 -1
- data/js/controls/dialogs/sheet/sheet.js +1 -1
- data/js/controls/imageview/imageview.js +1 -1
- data/js/controls/lists/checkboxlist/checkboxlist.js +1 -1
- data/js/controls/lists/listitems/listitems.js +1 -1
- data/js/controls/lists/radiobuttonlist/radiobuttonlist.js +1 -1
- data/js/controls/passwordcontrol/passwordcontrol.js +1 -1
- data/js/controls/progress/progressbar/progressbar.js +1 -1
- data/js/controls/progress/progressindicator/progressindicator.js +1 -1
- data/js/controls/radiobutton/radiobutton.js +1 -1
- data/js/controls/sliders/slider/slider.js +1 -1
- data/js/controls/sliders/vslider/vslider.js +1 -1
- data/js/controls/stepper/stepper.js +1 -1
- data/js/controls/stringview/stringview.js +1 -1
- data/js/controls/tab/tab.js +1 -1
- data/js/controls/textarea/textarea.js +1 -1
- data/js/controls/textcontrol/textcontrol.js +1 -1
- data/js/controls/uploader/uploader.js +1 -1
- data/js/controls/validatorview/validatorview.js +6 -2
- data/js/controls/window/window.js +1 -1
- data/js/core/class/class.js +1 -1
- data/js/core/elem/elem.js +1 -1
- data/js/core/event/event.js +1 -1
- data/js/core/iefix/iefix.js +1 -1
- data/js/foundation/application/application.js +1 -1
- data/js/foundation/control/control.js +1 -1
- data/js/foundation/control/controldefaults/controldefaults.js +1 -1
- data/js/foundation/control/dummyvalue/dummyvalue.js +1 -1
- data/js/foundation/control/dyncontrol/dyncontrol.js +1 -1
- data/js/foundation/control/eventresponder/eventresponder.js +1 -1
- data/js/foundation/control/valueresponder/valueresponder.js +1 -1
- data/js/foundation/geom/point/point.js +1 -1
- data/js/foundation/geom/rect/rect.js +1 -1
- data/js/foundation/json_renderer/json_renderer.js +1 -1
- data/js/foundation/system/system.js +1 -1
- data/js/foundation/thememanager/thememanager.js +1 -1
- data/js/foundation/view/markupview/markupview.js +1 -1
- data/js/foundation/view/morphanimation/morphanimation.js +1 -1
- data/js/foundation/view/view.js +1 -1
- data/js/foundation/view/viewdefaults/viewdefaults.js +1 -1
- data/js/views/centerview/centerview.js +1 -1
- data/js/views/inlineview/inlineview.js +1 -1
- data/js/views/scrollview/scrollview.js +1 -1
- data/lib/conf/argv.rb +719 -1006
- data/lib/conf/default.rb +14 -3
- data/lib/daemon/daemon.rb +1 -1
- data/lib/daemon/sigcomm.rb +1 -1
- data/lib/http/broker.rb +5 -1
- data/lib/http/rackup.rb +1 -1
- data/lib/http/request.rb +1 -1
- data/lib/http/response.rb +2 -2
- data/lib/plugins/dependencies.rb +36 -0
- data/lib/plugins/gui_plugin.rb +83 -80
- data/lib/plugins/guiparser.rb +7 -3
- data/lib/plugins/plugin.rb +308 -307
- data/lib/plugins/plugin_plugins.rb +5 -1
- data/lib/plugins/plugin_sqlite_db.rb +5 -1
- data/lib/plugins/plugin_util.rb +22 -0
- data/lib/plugins/pluginmanager.rb +95 -95
- data/lib/plugins/plugins.rb +117 -0
- data/lib/plugins/servlet.rb +47 -57
- data/lib/session/msg.rb +1 -1
- data/lib/session/sessionmanager.rb +1 -1
- data/lib/session/sessionstorage.rb +2 -2
- data/lib/transporter/transporter.rb +1 -2
- data/lib/values/hvalue.rb +7 -3
- data/lib/values/valuemanager.rb +7 -1
- data/plugins/client_pkg/client_pkg.rb +15 -48
- data/plugins/client_pkg/info.yaml +1 -1
- data/plugins/client_pkg/lib/client_pkg_build.rb +1 -1
- data/plugins/client_pkg/lib/client_pkg_cache.rb +1 -1
- data/plugins/index_html/index_html.rb +5 -6
- data/plugins/index_html/info.yaml +21 -0
- data/plugins/index_html/tmpl/index.html +1 -1
- data/plugins/index_html/tmpl/startup_index.html +1 -1
- data/plugins/main/info.yaml +21 -0
- data/plugins/main/main.rb +1 -5
- data/plugins/{ticketservices → ticket}/lib/common.rb +92 -2
- data/plugins/{ticketservices → ticket}/lib/favicon.rb +1 -1
- data/plugins/{ticketservices → ticket}/lib/file.rb +1 -1
- data/plugins/{ticketservices → ticket}/lib/img.rb +1 -1
- data/plugins/{ticketservices → ticket}/lib/objblob.rb +1 -1
- data/plugins/{ticketservices → ticket}/lib/rsrc.rb +1 -1
- data/plugins/{ticketservices → ticket}/lib/upload.rb +60 -31
- data/plugins/{ticketservices/ticketservices.rb → ticket/ticket.rb} +50 -118
- data/{plugins → setup}/legacy/info.yaml +0 -0
- data/{plugins → setup}/legacy/legacy.rb +2 -0
- data/setup/welcome/welcome.rb +1 -1
- metadata +27 -21
- data/conf/config.yaml +0 -4
- data/conf/local_conf.yaml.devel +0 -14
- data/lib/conf/wizard.rb +0 -303
- data/plugins/client_pkg/log/build_log +0 -0
- data/plugins/legacy/disabled +0 -0
- data/plugins/legacy/disabled- +0 -0
data/lib/conf/argv.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
##
|
2
|
+
## RSence
|
3
3
|
# Copyright 2010 Riassence Inc.
|
4
4
|
# http://riassence.com/
|
5
5
|
#
|
@@ -7,1117 +7,830 @@
|
|
7
7
|
# with this software package. If not, contact licensing@riassence.com
|
8
8
|
##
|
9
9
|
#++
|
10
|
-
require 'daemon/sigcomm'
|
11
|
-
module RSence
|
12
|
-
def self.pid_support?
|
13
|
-
# true for non-windows
|
14
|
-
return (not ['i386-mingw32','x86-mingw32'].include?(RUBY_PLATFORM))
|
15
|
-
end
|
16
|
-
class ARGVParser
|
17
|
-
|
18
|
-
@@version = File.read( File.join( SERVER_PATH, 'VERSION' ) ).strip
|
19
|
-
|
20
|
-
if RSence.pid_support?
|
21
|
-
@@cmds = [ :run, :status, :start, :stop, :restart, :save,
|
22
|
-
:initenv, :version, :help ]
|
23
|
-
else
|
24
|
-
@@cmds = [ :run, :initenv, :version, :help ]
|
25
|
-
end
|
26
|
-
|
27
|
-
@@cmd_help = {}
|
28
|
-
|
29
|
-
@@cmd_help[:head] = <<-EOF
|
30
|
-
RSence command-line tool, version #{@@version}
|
31
|
-
|
32
|
-
EOF
|
33
|
-
|
34
|
-
@@cmd_help[:unknown] = "Unknown command: "
|
35
|
-
|
36
|
-
@@cmd_help[:help_help] = "Type 'rsence help' for usage."
|
37
|
-
|
38
|
-
@@cmd_help[:help_main] = <<-EOF
|
39
|
-
usage: rsence <command> [options] [args]
|
40
|
-
|
41
|
-
Type 'rsence help <command>' for help on a specific command.
|
42
|
-
|
43
|
-
Available commands:
|
44
|
-
#{@@cmds.map{|cmd|cmd.to_s}.join("\n ")}
|
45
|
-
|
46
|
-
EOF
|
47
|
-
|
48
|
-
@@cmd_help[:path] = <<-EOF
|
49
|
-
The [PATH] is the RSence environment to use.
|
50
|
-
The [PATH] defaults to the current working directory.
|
51
|
-
|
52
|
-
EOF
|
53
|
-
|
54
|
-
@@cmd_help[:options] = <<-EOF
|
55
|
-
Available options:
|
56
|
-
|
57
|
-
--conf <file.yaml> Use additional config file. You can give this option
|
58
|
-
several times. The <file.yaml> is the configuration
|
59
|
-
file to load.
|
60
|
-
|
61
|
-
--debug (-d) Debug mode. Shortcut for several options useful for
|
62
|
-
developers. Not the preferred mode for production.
|
63
|
-
|
64
|
-
--verbose (-v) More verbose output. Also enabled by --debug
|
65
|
-
|
66
|
-
--log-fg (-f) Directs the output of the log messages to stdout
|
67
|
-
instead of the log files. Useful for development.
|
68
|
-
|
69
|
-
--trace-js Logs all js/json going through the msg object.
|
70
|
-
|
71
|
-
--trace-delegate Logs all plugin delegate calls.
|
72
|
-
|
73
|
-
--port <number> The port number the http server listens to.
|
74
|
-
|
75
|
-
--addr <ip address> The IP address or netmask the http server listens to.
|
76
|
-
'0.0.0.0' matches all interfaces.
|
77
|
-
'127.0.0.1' matches the local loopback interface.
|
78
|
-
|
79
|
-
--server <handler> The Rack handler to use. Defaults to mongrel
|
80
|
-
|
81
|
-
--reset-sessions (-r) Resets all active sessions.
|
82
|
-
|
83
|
-
--auto-update (-a) Automatically checks for changes in installed plugin
|
84
|
-
and component bundles. Rebuilds changed component
|
85
|
-
bundles and reload changed plugin bundles.
|
86
|
-
Useful for development purposes.
|
87
|
-
Also enabled by --debug
|
88
|
-
|
89
|
-
--latency <number> Sleeps <number> amount of milliseconds on every
|
90
|
-
request. Useful for testing slow connections.
|
91
|
-
|
92
|
-
--say (-S) Uses speech synthesis via the 'say' command to
|
93
|
-
provide audible feedback, when --auto-update is
|
94
|
-
enabled. Says 'Autobuild complete.',
|
95
|
-
'Loaded [plugin name].', 'Unloaded [plugin name].',
|
96
|
-
'Reloaded [plugin name].', 'Reloading plugins.' and
|
97
|
-
'Plugins reloaded.'
|
98
|
-
Only available on Mac OS X and other systems with a
|
99
|
-
'say' command installed.
|
100
|
-
|
101
|
-
EOF
|
102
|
-
|
103
|
-
@@cmd_help[:initenv] = <<-EOF
|
104
|
-
usage: 'rsence initenv [options] [PATH]'
|
105
|
-
|
106
|
-
The 'initenv' command creates a new RSence environment.
|
107
|
-
|
108
|
-
The expected structure of a project environment (where 'project_directory'
|
109
|
-
is the directory of your project) is:
|
110
|
-
|
111
|
-
[d] project_name : The name of your project.
|
112
|
-
[d] conf : The directory of config files.
|
113
|
-
[f] config.yaml : The config file to load by defult.
|
114
|
-
[d] db : Directory containing database files.
|
115
|
-
[d] log : Directory containing log files.
|
116
|
-
[d] plugins : Directory containing installed plugins.
|
117
|
-
[d] run : Directory containing runtime pid files.
|
118
|
-
[f] README : Description of the environment directory.
|
119
|
-
[f] VERSION : RSence version the environment was created with
|
120
|
-
|
121
|
-
The 'config.yaml' file contains patches specific to your project.
|
122
|
-
|
123
|
-
The configuration files are loaded and applied in this order:
|
124
|
-
1: [rsence_install_path]/conf/default_conf.yaml
|
125
|
-
2: [rsence_install_path]/conf/local_conf.yaml
|
126
|
-
3: /etc/rsence/config.yaml
|
127
|
-
4: ~/.rsence/config.yaml
|
128
|
-
5: [project_directory]/conf/config.yaml
|
129
|
-
6: Any files given using --conf parameters, in order of occurrence.
|
130
|
-
|
131
|
-
The plugins directory contains the plugins that are run in the project.
|
132
|
-
|
133
|
-
|
134
|
-
Available options:
|
135
|
-
|
136
|
-
--port <number> The port number the http server listens to.
|
137
|
-
|
138
|
-
--addr <ip address> The IP address or netmask the http server listens to.
|
139
|
-
'0.0.0.0' matches all interfaces.
|
140
|
-
'127.0.0.1' matches the local loopback interface.
|
141
|
-
Defaults to 0.0.0.0
|
142
|
-
|
143
|
-
--server <handler> The Rack handler to use. Defaults to mongrel
|
144
|
-
|
145
|
-
--title <title> The title of the index page.
|
146
|
-
|
147
|
-
--database <conn_str> Use the Sequel connection string to configure the
|
148
|
-
default session database.
|
149
|
-
|
150
|
-
--uri-prefix <path> Configure RSence to use this http "directory" as
|
151
|
-
the prefix. It defaults to the root directory: /
|
152
|
-
|
153
|
-
--blank Doesn't install the Welcome -plugin.
|
154
|
-
|
155
|
-
--non-interactive (-q) Doesn't ask anything, just creates the environment
|
156
|
-
with the options supplied.
|
157
|
-
|
158
|
-
For further configuration, edit the config.yaml file.
|
159
10
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
The 'run' command starts RSence in foreground (no daemon). Exit with CTRL-C.
|
166
|
-
|
167
|
-
#{@@cmd_help[:path]}
|
168
|
-
#{@@cmd_help[:options]}
|
169
|
-
EOF
|
170
|
-
|
171
|
-
@@cmd_help[:start] = <<-EOF
|
172
|
-
usage: 'rsence start [options] [PATH]'
|
173
|
-
|
174
|
-
The 'start' command starts RSence in the background (as a daemon).
|
175
|
-
|
176
|
-
Use the 'stop' command to stop RSence.
|
177
|
-
|
178
|
-
Use the 'restart' command to restart RSence in the background.
|
179
|
-
|
180
|
-
Use the 'status' command to see if RSence is running.
|
181
|
-
|
182
|
-
#{@@cmd_help[:path]}
|
183
|
-
#{@@cmd_help[:options]}
|
184
|
-
EOF
|
185
|
-
|
186
|
-
@@cmd_help[:stop] = <<-EOF
|
187
|
-
usage: 'rsence stop [options] [PATH]'
|
188
|
-
|
189
|
-
The 'stop' command stops RSence running in the background (as a daemon).
|
190
|
-
|
191
|
-
Use the 'status' command to see if RSence is running.
|
192
|
-
|
193
|
-
#{@@cmd_help[:path]}
|
194
|
-
#{@@cmd_help[:options]}
|
195
|
-
EOF
|
196
|
-
|
197
|
-
@@cmd_help[:restart] = <<-EOF
|
198
|
-
usage: 'rsence restart [options] [PATH]'
|
199
|
-
|
200
|
-
The 'restart' command restarts RSence in the background (as a daemon).
|
201
|
-
If RSence wasn't running before the 'restart' command was issued, the
|
202
|
-
effect is the same as 'start'.
|
203
|
-
|
204
|
-
Use the 'stop' command to stop RSence.
|
205
|
-
|
206
|
-
Use the 'status' command to see if RSence is running.
|
207
|
-
|
208
|
-
#{@@cmd_help[:path]}
|
209
|
-
#{@@cmd_help[:options]}
|
210
|
-
EOF
|
211
|
-
|
212
|
-
@@cmd_help[:status] = <<-EOF
|
213
|
-
usage: 'rsence status [options] [PATH]'
|
214
|
-
|
215
|
-
The 'status' command checks if RSence is running.
|
216
|
-
If started with the 'start', 'run' or 'restart' command, a PID file is written.
|
217
|
-
Status checks if the PID file exists, if the RSence process responds and if
|
218
|
-
the configured TCP port responds in the configured IP address.
|
219
|
-
|
220
|
-
Available options:
|
221
|
-
|
222
|
-
--conf <file.yaml> Use additional config file. You can give this option
|
223
|
-
several times. The <file.yaml> is the configuration
|
224
|
-
file to load.
|
225
|
-
|
226
|
-
--debug (-d) Debug mode. Shortcut for several options useful for
|
227
|
-
developers. Not the preferred mode for production.
|
228
|
-
|
229
|
-
--verbose (-v) More verbose output. Also enabled by --debug
|
230
|
-
|
231
|
-
--port <number> The port number the http server listens to.
|
232
|
-
|
233
|
-
--addr <ip address> The IP address or netmask the http server listens to.
|
234
|
-
|
235
|
-
#{@@cmd_help[:path]}
|
236
|
-
|
237
|
-
EOF
|
238
|
-
|
239
|
-
@@cmd_help[:save] = <<-EOF
|
240
|
-
usage: 'rsence save [options] [PATH]'
|
241
|
-
|
242
|
-
The 'save' command signals the RSence process to tell the plugins to save their
|
243
|
-
data and the session manager to save its session database.
|
244
|
-
|
245
|
-
Available options:
|
246
|
-
|
247
|
-
--conf <file.yaml> Use additional config file. You can give this option
|
248
|
-
several times. The <file.yaml> is the configuration
|
249
|
-
file to load.
|
250
|
-
|
251
|
-
--debug (-d) Debug mode. Shortcut for several options useful for
|
252
|
-
developers. Not the preferred mode for production.
|
253
|
-
|
254
|
-
--verbose (-v) More verbose output. Also enabled by --debug
|
255
|
-
|
256
|
-
#{@@cmd_help[:path]}
|
257
|
-
|
258
|
-
EOF
|
259
|
-
|
260
|
-
@@cmd_help[:version] = <<-EOF
|
261
|
-
usage: 'rsence version'
|
262
|
-
|
263
|
-
The 'version' command simply outputs the version number of RSence.
|
264
|
-
|
265
|
-
RSence follows the standard four-numbered sequence-based version identification
|
266
|
-
scheme. The scheme is defined like: major.minor[.maintenance[.package]][.pre]
|
267
|
-
|
268
|
-
The major number designates major changes in functionality, sometimes limiting
|
269
|
-
backwards compatibility with software written for previous versions.
|
270
|
-
|
271
|
-
The minor number designates minor changes in functionality, like minor or
|
272
|
-
moderate changes in functinality that usually don't impact backwards
|
273
|
-
compatibilty of software written for a previous release with the same major
|
274
|
-
version.
|
275
|
-
|
276
|
-
The maintenance number designates bug fixes and other minimal changes to
|
277
|
-
the release. In a maintenance number change, no new features are introduced.
|
278
|
-
|
279
|
-
The package number is a sequence used for the package release. Rubygems
|
280
|
-
requires an unique version for each gem released, so pre-releases usually
|
281
|
-
occupy the first package numbers of any release.
|
282
|
-
|
283
|
-
The '.pre' suffix signifies a pre-release, like "Alpha" or "Beta". To
|
284
|
-
install a prerelease version, gem requires the '--pre' command line argument.
|
285
|
-
Release versions never have the '.pre' suffix. There are usually several
|
286
|
-
package number increments of a new release.
|
287
|
-
|
288
|
-
Version number conventions in written text should include both major and
|
289
|
-
minor version numbers prefixed with 'RSence'. The maintennance number
|
290
|
-
is usally not mentioned unless an issue is fix or such is discussed.
|
291
|
-
|
292
|
-
For instance: "RSence 2.0 has undergone some major refactoring since 1.2.1"
|
293
|
-
|
294
|
-
EOF
|
11
|
+
# --
|
12
|
+
# Includes the Signal Communication utility.
|
13
|
+
# Used to respond via special PID files in the run directory of the environment
|
14
|
+
# ++
|
15
|
+
require 'daemon/sigcomm'
|
295
16
|
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
17
|
+
# --
|
18
|
+
# Creates the RSence module. RSence classes are defined within.
|
19
|
+
# ++
|
20
|
+
module RSence
|
300
21
|
|
301
|
-
|
22
|
+
# Returns true, if platform fully supports POSIX standard signals.
|
23
|
+
def self.pid_support?
|
24
|
+
# true for non-windows
|
25
|
+
return (not ['i386-mingw32','x86-mingw32'].include?(RUBY_PLATFORM))
|
26
|
+
end
|
302
27
|
|
303
|
-
|
304
|
-
|
305
|
-
|
28
|
+
# ARGVParser is the "user interface" as a command-line argument parser.
|
29
|
+
# Handles every action of the 'rsence' command-line tool.
|
30
|
+
class ARGVParser
|
31
|
+
|
32
|
+
# The RSence version string, read from the VERSION file in
|
33
|
+
# the root directory of RSence.
|
34
|
+
@@version = File.read( File.join( SERVER_PATH, 'VERSION' ) ).strip
|
35
|
+
|
36
|
+
# --
|
37
|
+
# Makes various commands available depending on the platform.
|
38
|
+
# The status/start/stop/restart/save -commands depend on an operating
|
39
|
+
# system that fully implements POSIX standard signals.
|
40
|
+
# These are necessary to send signals to the background process.
|
41
|
+
# ++
|
42
|
+
if RSence.pid_support?
|
43
|
+
@@cmds = [ :run, :status, :start, :stop, :restart, :save,
|
44
|
+
:initenv, :version, :help ]
|
306
45
|
else
|
307
|
-
|
46
|
+
@@cmds = [ :run, :initenv, :version, :help ]
|
308
47
|
end
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
48
|
+
|
49
|
+
help_avail_cmds = @@cmds.map{|cmd|cmd.to_s}.join("\n ")
|
50
|
+
|
51
|
+
# Load the strings from the strings file.
|
52
|
+
strs_path = File.join( SERVER_PATH, 'conf',
|
53
|
+
'rsence_command_strings.yaml' )
|
54
|
+
strs_data = File.read( strs_path )
|
55
|
+
require 'erb'
|
56
|
+
|
57
|
+
strs_data = ERB.new( strs_data ).result( binding )
|
58
|
+
|
59
|
+
require 'yaml'
|
60
|
+
@@strs = YAML.load( strs_data )
|
61
|
+
|
62
|
+
@@strs[:help][:run] += @@strs[:help][:path]+@@strs[:help][:options]
|
63
|
+
@@strs[:help][:start] += @@strs[:help][:path]+@@strs[:help][:options]
|
64
|
+
@@strs[:help][:stop] += @@strs[:help][:path]+@@strs[:help][:options]
|
65
|
+
@@strs[:help][:restart] += @@strs[:help][:path]+@@strs[:help][:options]
|
66
|
+
@@strs[:help][:status] += @@strs[:help][:path]
|
67
|
+
@@strs[:help][:save] += @@strs[:help][:path]
|
68
|
+
|
69
|
+
|
70
|
+
# Returns true if one of the 'start' -type commands were supplied
|
71
|
+
# and the environment seems valid.
|
72
|
+
def startable?; @startable; end
|
73
|
+
|
74
|
+
# Parses an argument of the 'help' command
|
75
|
+
def parse_help_argv
|
76
|
+
if @argv.length >= 2
|
77
|
+
help_cmd = @argv[1].to_sym
|
78
|
+
else
|
79
|
+
help_cmd = :help_main
|
80
|
+
end
|
81
|
+
help( help_cmd )
|
82
|
+
exit
|
83
|
+
end
|
84
|
+
|
85
|
+
# Creates the default and initial @args hash.
|
86
|
+
def init_args
|
87
|
+
@args = {
|
88
|
+
:env_path => Dir.pwd,
|
89
|
+
:conf_files => [ ], # --conf
|
90
|
+
:debug => false, # -d --debug
|
91
|
+
:verbose => false, # -v --verbose
|
92
|
+
:log_fg => false, # -f --log-fg
|
93
|
+
:trace_js => false, # --trace-js
|
94
|
+
:trace_delegate => false, # --trace-delegate
|
95
|
+
:port => nil, # --port
|
96
|
+
:addr => nil, # --addr --bind
|
97
|
+
:server => nil, # --server
|
98
|
+
:reset_ses => false, # -r --reset-sessions
|
99
|
+
:autoupdate => false, # -a --auto-update
|
100
|
+
:latency => 0, # --latency
|
101
|
+
:say => false, # -S --say
|
329
102
|
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
103
|
+
# client_pkg (not supported yet)
|
104
|
+
:client_pkg_no_gzip => false, # --build-no-gzip
|
105
|
+
:client_pkg_no_obfuscation => false, # --build-no-obfuscation
|
106
|
+
:client_pkg_no_whitespace_removal => false, # --build-keep-whitespace
|
107
|
+
:client_pkg_quiet => true, # --build-verbose
|
335
108
|
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
@argv
|
345
|
-
|
346
|
-
if
|
347
|
-
|
348
|
-
|
349
|
-
exit
|
350
|
-
elsif option_name == :conf_files
|
351
|
-
if not File.exists?( arg ) or not File.file?( arg )
|
352
|
-
puts "no such configuration file: #{arg.inspect}"
|
353
|
-
puts "Type 'rsence help #{@cmd.to_s}' for usage."
|
109
|
+
}
|
110
|
+
end
|
111
|
+
|
112
|
+
# Main argument parser for all 'start' -type commands.
|
113
|
+
def parse_startup_argv
|
114
|
+
init_args
|
115
|
+
expect_option = false
|
116
|
+
option_name = false
|
117
|
+
if @argv.length >= 2
|
118
|
+
@argv[1..-1].each_with_index do |arg,i|
|
119
|
+
if expect_option
|
120
|
+
if [:port,:latency].include?(option_name) and arg.to_i.to_s != arg
|
121
|
+
puts ERB.new( @@strs[:messages][:invalid_option_expected_number] ).result( binding )
|
354
122
|
exit
|
123
|
+
elsif option_name == :conf_files
|
124
|
+
if not File.exists?( arg ) or not File.file?( arg )
|
125
|
+
puts ERB.new( @@strs[:messages][:no_such_configuration_file] ).result( binding )
|
126
|
+
exit
|
127
|
+
else
|
128
|
+
@args[:conf_files].push( arg )
|
129
|
+
end
|
355
130
|
else
|
356
|
-
@args[
|
131
|
+
@args[option_name] = arg
|
357
132
|
end
|
133
|
+
expect_option = false
|
358
134
|
else
|
359
|
-
|
360
|
-
|
361
|
-
expect_option = false
|
362
|
-
else
|
363
|
-
if arg.start_with?('--')
|
364
|
-
if arg == '--debug'
|
365
|
-
set_debug
|
366
|
-
elsif arg == '--verbose'
|
367
|
-
set_verbose
|
368
|
-
elsif arg == '--log-fg'
|
369
|
-
set_log_fg
|
370
|
-
elsif arg == '--trace-js'
|
371
|
-
@args[:trace_js] = true
|
372
|
-
elsif arg == '--trace-delegate'
|
373
|
-
@args[:trace_delegate] = true
|
374
|
-
elsif arg == '--port'
|
375
|
-
expect_option = true
|
376
|
-
option_name = :port
|
377
|
-
elsif arg == '--addr'
|
378
|
-
expect_option = true
|
379
|
-
option_name = :addr
|
380
|
-
elsif arg == '--server'
|
381
|
-
expect_option = true
|
382
|
-
option_name = :server
|
383
|
-
elsif arg == '--conf' or arg == '--config'
|
384
|
-
expect_option = true
|
385
|
-
option_name = :conf_files
|
386
|
-
elsif arg == '--reset-sessions'
|
387
|
-
set_reset_ses
|
388
|
-
elsif arg == '--auto-update'
|
389
|
-
set_autoupdate
|
390
|
-
elsif arg == '--latency'
|
391
|
-
expect_option = true
|
392
|
-
option_name = :latency
|
393
|
-
elsif arg == '--say'
|
394
|
-
set_say
|
395
|
-
else
|
396
|
-
invalid_option(arg)
|
397
|
-
end
|
398
|
-
elsif arg.start_with?('-')
|
399
|
-
arg.split('')[1..-1].each do |chr|
|
400
|
-
if chr == 'd'
|
135
|
+
if arg.start_with?('--')
|
136
|
+
if arg == '--debug'
|
401
137
|
set_debug
|
402
|
-
elsif
|
138
|
+
elsif arg == '--verbose'
|
403
139
|
set_verbose
|
404
|
-
elsif
|
140
|
+
elsif arg == '--log-fg'
|
405
141
|
set_log_fg
|
406
|
-
elsif
|
142
|
+
elsif arg == '--trace-js'
|
143
|
+
@args[:trace_js] = true
|
144
|
+
elsif arg == '--trace-delegate'
|
145
|
+
@args[:trace_delegate] = true
|
146
|
+
elsif arg == '--port'
|
147
|
+
expect_option = true
|
148
|
+
option_name = :port
|
149
|
+
elsif arg == '--addr'
|
150
|
+
expect_option = true
|
151
|
+
option_name = :addr
|
152
|
+
elsif arg == '--server'
|
153
|
+
expect_option = true
|
154
|
+
option_name = :server
|
155
|
+
elsif arg == '--conf' or arg == '--config'
|
156
|
+
expect_option = true
|
157
|
+
option_name = :conf_files
|
158
|
+
elsif arg == '--reset-sessions'
|
407
159
|
set_reset_ses
|
408
|
-
elsif
|
160
|
+
elsif arg == '--auto-update'
|
409
161
|
set_autoupdate
|
410
|
-
elsif
|
162
|
+
elsif arg == '--latency'
|
163
|
+
expect_option = true
|
164
|
+
option_name = :latency
|
165
|
+
elsif arg == '--say'
|
411
166
|
set_say
|
412
167
|
else
|
413
|
-
invalid_option(arg
|
168
|
+
invalid_option(arg)
|
414
169
|
end
|
170
|
+
elsif arg.start_with?('-')
|
171
|
+
arg.split('')[1..-1].each do |chr|
|
172
|
+
if chr == 'd'
|
173
|
+
set_debug
|
174
|
+
elsif chr == 'v'
|
175
|
+
set_verbose
|
176
|
+
elsif chr == 'f'
|
177
|
+
set_log_fg
|
178
|
+
elsif chr == 'r'
|
179
|
+
set_reset_ses
|
180
|
+
elsif chr == 'a'
|
181
|
+
set_autoupdate
|
182
|
+
elsif chr == 'S'
|
183
|
+
set_say
|
184
|
+
else
|
185
|
+
invalid_option(arg,chr)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
elsif valid_env?(arg)
|
189
|
+
@args[:env_path] = File.expand_path(arg)
|
190
|
+
@args[:conf_files].push( File.expand_path( File.join( arg, 'conf', 'config.yaml' ) ) )
|
191
|
+
else
|
192
|
+
invalid_env( arg )
|
415
193
|
end
|
416
|
-
elsif valid_env?(arg)
|
417
|
-
@args[:env_path] = File.expand_path(arg)
|
418
|
-
@args[:conf_files].push( File.expand_path( File.join( arg, 'conf', 'config.yaml' ) ) )
|
419
|
-
else
|
420
|
-
invalid_env( arg )
|
421
194
|
end
|
422
195
|
end
|
196
|
+
if expect_option
|
197
|
+
puts ERB.new( @@strs[:messages][:no_value_for_option] ).result( binding )
|
198
|
+
exit
|
199
|
+
end
|
423
200
|
end
|
424
|
-
if
|
425
|
-
|
426
|
-
|
427
|
-
|
201
|
+
if valid_env?(@args[:env_path])
|
202
|
+
conf_file = File.expand_path( File.join( @args[:env_path], 'conf', 'config.yaml' ) )
|
203
|
+
@args[:conf_files].push( conf_file ) unless @args[:conf_files].include?( conf_file )
|
204
|
+
else
|
205
|
+
invalid_env
|
428
206
|
end
|
207
|
+
@startable = true
|
429
208
|
end
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
209
|
+
|
210
|
+
# Sets various debug-related options on.
|
211
|
+
def set_debug
|
212
|
+
@args[:debug] = true
|
213
|
+
@args[:verbose] = true
|
214
|
+
@args[:autoupdate] = true
|
215
|
+
@args[:client_pkg_no_obfuscation] = true
|
216
|
+
@args[:client_pkg_no_whitespace_removal] = true
|
217
|
+
@args[:client_pkg_quiet] = false
|
436
218
|
end
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
@args[:debug] = true
|
442
|
-
@args[:verbose] = true
|
443
|
-
@args[:autoupdate] = true
|
444
|
-
@args[:client_pkg_quiet] = false
|
445
|
-
end
|
446
|
-
def set_verbose
|
447
|
-
@args[:verbose] = true
|
448
|
-
end
|
449
|
-
def set_log_fg
|
450
|
-
@args[:log_fg] = true
|
451
|
-
end
|
452
|
-
def set_reset_ses
|
453
|
-
@args[:reset_ses] = true
|
454
|
-
end
|
455
|
-
def set_autoupdate
|
456
|
-
@args[:autoupdate] = true
|
457
|
-
end
|
458
|
-
def set_say
|
459
|
-
@args[:say] = true
|
460
|
-
end
|
461
|
-
|
462
|
-
def valid_env?( arg, quiet=false )
|
463
|
-
path = File.expand_path( arg )
|
464
|
-
if not File.exists?( path )
|
465
|
-
puts "no such directory: #{path.inspect}" unless quiet
|
466
|
-
return false
|
467
|
-
elsif not File.directory?( path )
|
468
|
-
puts "not a directory: #{path.inspect}" unless quiet
|
469
|
-
return false
|
219
|
+
|
220
|
+
# Set the verbose argument on
|
221
|
+
def set_verbose
|
222
|
+
@args[:verbose] = true
|
470
223
|
end
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
elsif not File.directory?( conf_path )
|
476
|
-
puts "not a conf directory, expected: #{conf_path.inspect}" unless quiet
|
477
|
-
return false
|
224
|
+
|
225
|
+
# Set the foreground logging argument on
|
226
|
+
def set_log_fg
|
227
|
+
@args[:log_fg] = true
|
478
228
|
end
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
elsif not File.file?( conf_file )
|
484
|
-
puts "conf file not a file, expected: #{conf_file.inspect}" unless quiet
|
485
|
-
return false
|
229
|
+
|
230
|
+
# Sets the session reset argument on
|
231
|
+
def set_reset_ses
|
232
|
+
@args[:reset_ses] = true
|
486
233
|
end
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
puts "plugin directory not a directory, expected: #{plugin_path.inspect}" unless quiet
|
492
|
-
return false
|
234
|
+
|
235
|
+
# Sets the auto-update argument on
|
236
|
+
def set_autoupdate
|
237
|
+
@args[:autoupdate] = true
|
493
238
|
end
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
239
|
+
|
240
|
+
# Sets the speech synthesis argument on
|
241
|
+
def set_say
|
242
|
+
@args[:say] = true
|
498
243
|
end
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
244
|
+
|
245
|
+
# Tests for a valid environment
|
246
|
+
def valid_env?( arg, quiet=false )
|
247
|
+
|
248
|
+
# Checks, if the top-level path exists and is a directory
|
249
|
+
path = File.expand_path( arg )
|
250
|
+
if not File.exists?( path )
|
251
|
+
puts ERB.new( @@strs[:messages][:no_such_directory] ).result( binding ) unless quiet
|
252
|
+
return false
|
253
|
+
elsif not File.directory?( path )
|
254
|
+
puts ERB.new( @@strs[:messages][:not_a_directory] ).result( binding ) unless quiet
|
255
|
+
return false
|
256
|
+
end
|
257
|
+
|
258
|
+
# Checks, if the conf path exists and is a directory
|
259
|
+
conf_path = File.join( path, 'conf' )
|
260
|
+
if not File.exists?( conf_path )
|
261
|
+
puts ERB.new( @@strs[:messages][:missing_conf_directory] ).result( binding ) unless quiet
|
262
|
+
return false
|
263
|
+
elsif not File.directory?( conf_path )
|
264
|
+
puts ERB.new( @@strs[:messages][:invalid_conf_directory] ).result( binding ) unless quiet
|
265
|
+
return false
|
266
|
+
end
|
267
|
+
|
268
|
+
# Checks, if the conf/config.yaml file exists and is a directory
|
269
|
+
conf_file = File.join( path, 'conf', 'config.yaml' )
|
270
|
+
if not File.exists?(conf_file)
|
271
|
+
puts ERB.new( @@strs[:messages][:missing_conf_file] ).result( binding ) unless quiet
|
272
|
+
return false
|
273
|
+
elsif not File.file?( conf_file )
|
274
|
+
puts ERB.new( @@strs[:messages][:invalid_conf_file_not_file] ).result( binding ) unless quiet
|
275
|
+
return false
|
276
|
+
end
|
277
|
+
|
278
|
+
# Checks, if the plugins path exists and is a directory
|
279
|
+
plugin_path = File.join( path, 'plugins' )
|
280
|
+
if not File.exists?( plugin_path )
|
281
|
+
warn ERB.new( @@strs[:messages][:warn_no_plugin_directory_in_project] ).result( binding ) if @args[:verbose]
|
282
|
+
elsif not File.directory?( plugin_path )
|
283
|
+
puts ERB.new( @@strs[:messages][:plugin_directory_not_a_directory] ).result( binding ) unless quiet
|
284
|
+
return false
|
285
|
+
end
|
286
|
+
|
287
|
+
# Checks (and automatically creates if missing) the run, db and log directories
|
288
|
+
['run','log','db'].each do |dir_name|
|
289
|
+
dir_path = File.join( path, dir_name )
|
290
|
+
unless File.exists?( dir_path )
|
291
|
+
warn ERB.new( @@strs[:messages][:warn_no_directory_creating] ).result( binding ) if @args[:verbose]
|
292
|
+
Dir.mkdir( dir_path )
|
293
|
+
end
|
294
|
+
end
|
295
|
+
return true
|
503
296
|
end
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
297
|
+
|
298
|
+
# Error message when an invalid environment is encountered, exits.
|
299
|
+
def invalid_env( env_path=false )
|
300
|
+
env_path = @args[:env_path] unless env_path
|
301
|
+
puts ERB.new( @@strs[:messages][:invalid_environment] ).result( binding )
|
302
|
+
exit
|
508
303
|
end
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
def invalid_option(arg,chr=false)
|
520
|
-
if not chr
|
521
|
-
puts "invalid option: #{arg.inspect}"
|
522
|
-
else
|
523
|
-
puts "invalid option character #{chr.inspect} in option character block #{arg.inspect}"
|
304
|
+
|
305
|
+
# Error message when an invalid option is encountered, exits.
|
306
|
+
def invalid_option(arg,chr=false)
|
307
|
+
if chr
|
308
|
+
puts ERB.new( @@strs[:messages][:invalid_option_chr] ).result( binding )
|
309
|
+
else
|
310
|
+
puts ERB.new( @@strs[:messages][:invalid_option] ).result( binding )
|
311
|
+
end
|
312
|
+
exit
|
524
313
|
end
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
314
|
+
|
315
|
+
# Tests, if the port on addr responds or refuses the connection.
|
316
|
+
# Automatically replaces '0.0.0.0' with '127.0.0.1'
|
317
|
+
def test_port( port, addr='127.0.0.1' )
|
318
|
+
require 'socket'
|
319
|
+
begin
|
320
|
+
addr = '127.0.0.1' if addr == '0.0.0.0'
|
321
|
+
if RUBY_VERSION.to_f >= 1.9
|
322
|
+
sock = TCPSocket.open( addr, port )
|
323
|
+
else
|
324
|
+
sock = TCPsocket.open( addr, port )
|
325
|
+
end
|
326
|
+
sock.close
|
327
|
+
return true
|
328
|
+
rescue Errno::ECONNREFUSED
|
329
|
+
return false
|
330
|
+
rescue => e
|
331
|
+
warn e.inspect
|
332
|
+
return false
|
333
|
+
end
|
541
334
|
end
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
@argv
|
550
|
-
|
551
|
-
if
|
552
|
-
|
553
|
-
|
554
|
-
exit
|
555
|
-
elsif option_name == :conf_files
|
556
|
-
if not File.exists?( arg ) or not File.file?( arg )
|
557
|
-
puts "no such configuration file: #{arg.inspect}"
|
558
|
-
puts "Type 'rsence help #{@cmd.to_s}' for usage."
|
335
|
+
|
336
|
+
# Main argument parser for the status command, sends the USR2 POSIX signal to the process, if running.
|
337
|
+
# Checks if the process responds on the port and address it's configured for.
|
338
|
+
def parse_status_argv
|
339
|
+
init_args
|
340
|
+
expect_option = false
|
341
|
+
option_name = false
|
342
|
+
if @argv.length >= 2
|
343
|
+
@argv[1..-1].each_with_index do |arg,i|
|
344
|
+
if expect_option
|
345
|
+
if [:port].include?(option_name) and arg.to_i.to_s != arg
|
346
|
+
puts ERB.new( @@strs[:messages][:invalid_option_expected_number] ).result( binding )
|
559
347
|
exit
|
348
|
+
elsif option_name == :conf_files
|
349
|
+
if not File.exists?( arg ) or not File.file?( arg )
|
350
|
+
puts ERB.new( @@strs[:messages][:no_such_configuration_file] ).result( binding )
|
351
|
+
exit
|
352
|
+
else
|
353
|
+
@args[:conf_files].push( arg )
|
354
|
+
end
|
560
355
|
else
|
561
|
-
@args[
|
356
|
+
@args[option_name] = arg
|
562
357
|
end
|
358
|
+
expect_option = false
|
563
359
|
else
|
564
|
-
|
565
|
-
|
566
|
-
expect_option = false
|
567
|
-
else
|
568
|
-
if arg.start_with?('--')
|
569
|
-
if arg == '--debug'
|
570
|
-
set_debug
|
571
|
-
elsif arg == '--verbose'
|
572
|
-
set_verbose
|
573
|
-
elsif arg == '--port'
|
574
|
-
expect_option = true
|
575
|
-
option_name = :port
|
576
|
-
elsif arg == '--addr'
|
577
|
-
expect_option = true
|
578
|
-
option_name = :addr
|
579
|
-
elsif arg == '--conf' or arg == '--config'
|
580
|
-
expect_option = true
|
581
|
-
option_name = :conf_files
|
582
|
-
else
|
583
|
-
invalid_option(arg)
|
584
|
-
end
|
585
|
-
elsif arg.start_with?('-')
|
586
|
-
arg.split('')[1..-1].each do |chr|
|
587
|
-
if chr == 'd'
|
360
|
+
if arg.start_with?('--')
|
361
|
+
if arg == '--debug'
|
588
362
|
set_debug
|
589
|
-
elsif
|
363
|
+
elsif arg == '--verbose'
|
590
364
|
set_verbose
|
365
|
+
elsif arg == '--port'
|
366
|
+
expect_option = true
|
367
|
+
option_name = :port
|
368
|
+
elsif arg == '--addr'
|
369
|
+
expect_option = true
|
370
|
+
option_name = :addr
|
371
|
+
elsif arg == '--conf' or arg == '--config'
|
372
|
+
expect_option = true
|
373
|
+
option_name = :conf_files
|
591
374
|
else
|
592
|
-
invalid_option(arg
|
375
|
+
invalid_option(arg)
|
376
|
+
end
|
377
|
+
elsif arg.start_with?('-')
|
378
|
+
arg.split('')[1..-1].each do |chr|
|
379
|
+
if chr == 'd'
|
380
|
+
set_debug
|
381
|
+
elsif chr == 'v'
|
382
|
+
set_verbose
|
383
|
+
else
|
384
|
+
invalid_option(arg,chr)
|
385
|
+
end
|
593
386
|
end
|
387
|
+
elsif valid_env?(arg)
|
388
|
+
@args[:env_path] = File.expand_path(arg)
|
389
|
+
@args[:conf_files].push( File.expand_path( File.join( arg, 'conf', 'config.yaml' ) ) )
|
390
|
+
else
|
391
|
+
invalid_env( arg )
|
594
392
|
end
|
595
|
-
elsif valid_env?(arg)
|
596
|
-
@args[:env_path] = File.expand_path(arg)
|
597
|
-
@args[:conf_files].push( File.expand_path( File.join( arg, 'conf', 'config.yaml' ) ) )
|
598
|
-
else
|
599
|
-
invalid_env( arg )
|
600
393
|
end
|
601
394
|
end
|
395
|
+
if expect_option
|
396
|
+
puts ERB.new( @@strs[:messages][:no_value_for_option] ).result( binding )
|
397
|
+
exit
|
398
|
+
end
|
602
399
|
end
|
603
|
-
if
|
604
|
-
|
605
|
-
|
606
|
-
exit
|
607
|
-
end
|
608
|
-
end
|
609
|
-
if valid_env?(@args[:env_path])
|
610
|
-
conf_file = File.expand_path( File.join( @args[:env_path], 'conf', 'config.yaml' ) )
|
611
|
-
@args[:conf_files].push( conf_file ) unless @args[:conf_files].include?( conf_file )
|
612
|
-
else
|
613
|
-
puts "invalid environment."
|
614
|
-
exit
|
615
|
-
end
|
616
|
-
require 'conf/default'
|
617
|
-
config = Configuration.new(@args).config
|
618
|
-
port = config[:http_server][:port]
|
619
|
-
addr = config[:http_server][:bind_address]
|
620
|
-
port_status = test_port( port, addr )
|
621
|
-
if RSence.pid_support?
|
622
|
-
pid_fn = config[:daemon][:pid_fn]
|
623
|
-
if File.exists?( pid_fn )
|
624
|
-
pid = File.read( pid_fn ).to_i
|
625
|
-
pid_status = RSence::SIGComm.wait_signal_response(
|
626
|
-
pid, pid_fn, 'USR2', 3
|
627
|
-
)
|
400
|
+
if valid_env?(@args[:env_path])
|
401
|
+
conf_file = File.expand_path( File.join( @args[:env_path], 'conf', 'config.yaml' ) )
|
402
|
+
@args[:conf_files].push( conf_file ) unless @args[:conf_files].include?( conf_file )
|
628
403
|
else
|
629
|
-
|
630
|
-
pid_status = nil
|
404
|
+
invalid_env
|
631
405
|
end
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
if
|
638
|
-
|
639
|
-
|
640
|
-
|
406
|
+
require 'conf/default'
|
407
|
+
config = Configuration.new(@args).config
|
408
|
+
port = config[:http_server][:port]
|
409
|
+
addr = config[:http_server][:bind_address]
|
410
|
+
port_status = test_port( port, addr )
|
411
|
+
if RSence.pid_support?
|
412
|
+
pid_fn = config[:daemon][:pid_fn]
|
413
|
+
if File.exists?( pid_fn )
|
414
|
+
pid = File.read( pid_fn ).to_i
|
415
|
+
pid_status = RSence::SIGComm.wait_signal_response(
|
416
|
+
pid, pid_fn, 'USR2', 3
|
417
|
+
)
|
418
|
+
else
|
419
|
+
warn @@strs[:messages][:no_pid_file] if @args[:verbose]
|
420
|
+
pid_status = nil
|
421
|
+
end
|
641
422
|
else
|
642
|
-
|
423
|
+
warn @@strs[:messages][:no_pid_support] if @args[:verbose]
|
424
|
+
pid_status = nil
|
643
425
|
end
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
option_name = false
|
651
|
-
if @argv.length >= 2
|
652
|
-
@argv[1..-1].each_with_index do |arg,i|
|
653
|
-
if expect_option
|
654
|
-
if option_name == :conf_files
|
655
|
-
if not File.exists?( arg ) or not File.file?( arg )
|
656
|
-
puts "no such configuration file: #{arg.inspect}"
|
657
|
-
puts "Type 'rsence help #{@cmd.to_s}' for usage."
|
658
|
-
exit
|
659
|
-
else
|
660
|
-
@args[:conf_files].push( arg )
|
661
|
-
end
|
426
|
+
if RSence.pid_support?
|
427
|
+
if pid_status == nil
|
428
|
+
puts @@strs[:messages][:no_pid]
|
429
|
+
elsif pid_status == false
|
430
|
+
if port_status
|
431
|
+
puts ERB.new( @@strs[:messages][:no_process_running_but_something_responds] ).result( binding )
|
662
432
|
else
|
663
|
-
|
433
|
+
puts ERB.new( @@strs[:messages][:no_process_running_and_nothing_responds] ).result( binding )
|
664
434
|
end
|
665
|
-
expect_option = false
|
666
435
|
else
|
667
|
-
if
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
436
|
+
if port_status
|
437
|
+
puts ERB.new( @@strs[:messages][:process_running_and_responds] ).result( binding )
|
438
|
+
else
|
439
|
+
puts ERB.new( @@strs[:messages][:process_running_but_nothing_responds] ).result( binding )
|
440
|
+
end
|
441
|
+
end
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
# Main argument parser for the save command. Sends the USR1 POSIX signal to the process, if running.
|
446
|
+
def parse_save_argv
|
447
|
+
init_args
|
448
|
+
expect_option = false
|
449
|
+
option_name = false
|
450
|
+
if @argv.length >= 2
|
451
|
+
@argv[1..-1].each_with_index do |arg,i|
|
452
|
+
if expect_option
|
453
|
+
if option_name == :conf_files
|
454
|
+
if not File.exists?( arg ) or not File.file?( arg )
|
455
|
+
puts ERB.new( @@strs[:messages][:no_such_configuration_file] ).result( binding )
|
456
|
+
exit
|
457
|
+
else
|
458
|
+
@args[:conf_files].push( arg )
|
459
|
+
end
|
675
460
|
else
|
676
|
-
|
461
|
+
@args[option_name] = arg
|
677
462
|
end
|
678
|
-
|
679
|
-
|
680
|
-
|
463
|
+
expect_option = false
|
464
|
+
else
|
465
|
+
if arg.start_with?('--')
|
466
|
+
if arg == '--debug'
|
681
467
|
set_debug
|
682
|
-
elsif
|
468
|
+
elsif arg == '--verbose'
|
683
469
|
set_verbose
|
470
|
+
elsif arg == '--conf' or arg == '--config'
|
471
|
+
expect_option = true
|
472
|
+
option_name = :conf_files
|
684
473
|
else
|
685
|
-
invalid_option(arg
|
474
|
+
invalid_option(arg)
|
475
|
+
end
|
476
|
+
elsif arg.start_with?('-')
|
477
|
+
arg.split('')[1..-1].each do |chr|
|
478
|
+
if chr == 'd'
|
479
|
+
set_debug
|
480
|
+
elsif chr == 'v'
|
481
|
+
set_verbose
|
482
|
+
else
|
483
|
+
invalid_option(arg,chr)
|
484
|
+
end
|
686
485
|
end
|
486
|
+
elsif valid_env?(arg)
|
487
|
+
@args[:env_path] = File.expand_path(arg)
|
488
|
+
@args[:conf_files].push( File.expand_path( File.join( arg, 'conf', 'config.yaml' ) ) )
|
489
|
+
else
|
490
|
+
invalid_env( arg )
|
687
491
|
end
|
688
|
-
elsif valid_env?(arg)
|
689
|
-
@args[:env_path] = File.expand_path(arg)
|
690
|
-
@args[:conf_files].push( File.expand_path( File.join( arg, 'conf', 'config.yaml' ) ) )
|
691
|
-
else
|
692
|
-
invalid_env( arg )
|
693
492
|
end
|
694
493
|
end
|
494
|
+
if expect_option
|
495
|
+
puts ERB.new( @@strs[:messages][:no_value_for_option] ).result( binding )
|
496
|
+
exit
|
497
|
+
end
|
695
498
|
end
|
696
|
-
if
|
697
|
-
|
698
|
-
|
699
|
-
|
499
|
+
if valid_env?(@args[:env_path])
|
500
|
+
conf_file = File.expand_path( File.join( @args[:env_path], 'conf', 'config.yaml' ) )
|
501
|
+
@args[:conf_files].push( conf_file ) unless @args[:conf_files].include?( conf_file )
|
502
|
+
else
|
503
|
+
invalid_env
|
700
504
|
end
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
pid_status = RSence::SIGComm.wait_signal_response(
|
716
|
-
pid, pid_fn, 'USR1', 30, 'Saving session data...', '.', 0.1, true
|
717
|
-
)
|
505
|
+
require 'conf/default'
|
506
|
+
config = Configuration.new(@args).config
|
507
|
+
if RSence.pid_support?
|
508
|
+
pid_fn = config[:daemon][:pid_fn]
|
509
|
+
if File.exists?( pid_fn )
|
510
|
+
pid = File.read( pid_fn ).to_i
|
511
|
+
saving_message = @@strs[:messages][:saving_message]
|
512
|
+
pid_status = RSence::SIGComm.wait_signal_response(
|
513
|
+
pid, pid_fn, 'USR1', 30, saving_message, '.', 0.1, true
|
514
|
+
)
|
515
|
+
else
|
516
|
+
warn @@strs[:messages][:no_pid_file] if @args[:verbose]
|
517
|
+
pid_status = nil
|
518
|
+
end
|
718
519
|
else
|
719
|
-
|
520
|
+
warn @@strs[:messages][:no_pid_support] if @args[:verbose]
|
720
521
|
pid_status = nil
|
721
522
|
end
|
722
|
-
|
723
|
-
|
724
|
-
|
523
|
+
if RSence.pid_support?
|
524
|
+
if pid_status == nil
|
525
|
+
puts @@strs[:messages][:no_pid_unable_to_save]
|
526
|
+
elsif pid_status == false
|
527
|
+
puts @@strs[:messages][:no_process_running]
|
528
|
+
else
|
529
|
+
puts @@strs[:messages][:session_data_saved]
|
530
|
+
end
|
531
|
+
end
|
725
532
|
end
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
533
|
+
|
534
|
+
# asks y/n and returns boleans,
|
535
|
+
# the default tells if which one is for just enter
|
536
|
+
def yesno(default=false)
|
537
|
+
if default
|
538
|
+
question = "Y/n? "
|
731
539
|
else
|
732
|
-
|
540
|
+
question = "y/N? "
|
541
|
+
end
|
542
|
+
print question
|
543
|
+
answer = $stdin.gets.strip.downcase[0]
|
544
|
+
answer = answer.chr if answer
|
545
|
+
if answer == 'n'
|
546
|
+
return false
|
547
|
+
elsif answer == 'y'
|
548
|
+
return true
|
549
|
+
elsif answer == nil
|
550
|
+
return default
|
551
|
+
else
|
552
|
+
return nil
|
733
553
|
end
|
734
554
|
end
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
elsif answer == 'y'
|
751
|
-
return true
|
752
|
-
elsif answer == nil
|
753
|
-
return default
|
754
|
-
else
|
755
|
-
return nil
|
756
|
-
end
|
757
|
-
end
|
758
|
-
|
759
|
-
def parse_initenv_argv
|
760
|
-
init_args
|
761
|
-
expect_option = false
|
762
|
-
option_name = false
|
763
|
-
valid_env = false
|
764
|
-
interactive = true
|
765
|
-
create_blank = false
|
766
|
-
if @argv.length >= 2
|
767
|
-
@argv[1..-1].each_with_index do |arg,i|
|
768
|
-
if expect_option
|
769
|
-
if [:port].include?(option_name) and arg.to_i.to_s != arg
|
770
|
-
puts "invalid #{option_name.to_s}, expected number: #{arg.inspect}"
|
771
|
-
puts "Type 'rsence help #{@cmd.to_s}' for usage."
|
772
|
-
exit
|
773
|
-
else
|
774
|
-
@args[option_name] = arg
|
775
|
-
end
|
776
|
-
expect_option = false
|
777
|
-
else
|
778
|
-
if arg.start_with?('--')
|
779
|
-
if arg == '--port'
|
780
|
-
expect_option = true
|
781
|
-
option_name = :port
|
782
|
-
elsif arg == '--addr'
|
783
|
-
expect_option = true
|
784
|
-
option_name = :addr
|
785
|
-
elsif arg == '--server'
|
786
|
-
expect_option = true
|
787
|
-
option_name = :server
|
788
|
-
elsif arg == '--title'
|
789
|
-
expect_option = true
|
790
|
-
option_name = :title
|
791
|
-
elsif arg == '--database'
|
792
|
-
expect_option = true
|
793
|
-
option_name = :db
|
794
|
-
elsif arg == '--uri-prefix'
|
795
|
-
expect_option = true
|
796
|
-
option_name = :base_url
|
797
|
-
elsif arg == '--blank'
|
798
|
-
create_blank = true
|
799
|
-
elsif arg == '--non-interactive'
|
800
|
-
interactive = false
|
555
|
+
|
556
|
+
# The initenv command and its parser. Asks questions about the environment before doing anything else.
|
557
|
+
def parse_initenv_argv
|
558
|
+
init_args
|
559
|
+
expect_option = false
|
560
|
+
option_name = false
|
561
|
+
valid_env = false
|
562
|
+
interactive = true
|
563
|
+
create_blank = false
|
564
|
+
if @argv.length >= 2
|
565
|
+
@argv[1..-1].each_with_index do |arg,i|
|
566
|
+
if expect_option
|
567
|
+
if [:port].include?(option_name) and arg.to_i.to_s != arg
|
568
|
+
puts ERB.new( @@strs[:messages][:invalid_option_expected_number] ).result( binding )
|
569
|
+
exit
|
801
570
|
else
|
802
|
-
|
571
|
+
@args[option_name] = arg
|
803
572
|
end
|
804
|
-
|
805
|
-
|
806
|
-
|
573
|
+
expect_option = false
|
574
|
+
else
|
575
|
+
if arg.start_with?('--')
|
576
|
+
if arg == '--port'
|
577
|
+
expect_option = true
|
578
|
+
option_name = :port
|
579
|
+
elsif arg == '--addr'
|
580
|
+
expect_option = true
|
581
|
+
option_name = :addr
|
582
|
+
elsif arg == '--server'
|
583
|
+
expect_option = true
|
584
|
+
option_name = :server
|
585
|
+
elsif arg == '--title'
|
586
|
+
expect_option = true
|
587
|
+
option_name = :title
|
588
|
+
elsif arg == '--database'
|
589
|
+
expect_option = true
|
590
|
+
option_name = :db
|
591
|
+
elsif arg == '--uri-prefix'
|
592
|
+
expect_option = true
|
593
|
+
option_name = :base_url
|
594
|
+
elsif arg == '--blank'
|
595
|
+
create_blank = true
|
596
|
+
elsif arg == '--non-interactive'
|
807
597
|
interactive = false
|
598
|
+
else
|
599
|
+
invalid_option(arg)
|
808
600
|
end
|
601
|
+
elsif arg.start_with?('-')
|
602
|
+
arg.split('')[1..-1].each do |chr|
|
603
|
+
if chr == 'q'
|
604
|
+
interactive = false
|
605
|
+
end
|
606
|
+
end
|
607
|
+
else
|
608
|
+
@args[:env_path] = File.expand_path(arg)
|
809
609
|
end
|
810
|
-
else
|
811
|
-
@args[:env_path] = File.expand_path(arg)
|
812
610
|
end
|
813
611
|
end
|
612
|
+
if expect_option
|
613
|
+
puts ERB.new( @@strs[:messages][:no_value_for_option] ).result( binding )
|
614
|
+
exit
|
615
|
+
end
|
814
616
|
end
|
815
|
-
if
|
816
|
-
puts
|
817
|
-
puts "Type 'rsence help #{@cmd.to_s} for usage."
|
617
|
+
if valid_env?(@args[:env_path],true)
|
618
|
+
puts @@strs[:initenv][:env_already_initialized]
|
818
619
|
exit
|
819
620
|
end
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
if File.exists?(@args[:env_path])
|
827
|
-
if Dir.entries(@args[:env_path]).length > 2 # [ '.', '..' ]
|
828
|
-
puts "Environment directory #{@args[:env_path]} is not empty."
|
829
|
-
exit
|
621
|
+
conf_file = File.expand_path( File.join( @args[:env_path], 'conf', 'config.yaml' ) )
|
622
|
+
if File.exists?(@args[:env_path])
|
623
|
+
if Dir.entries(@args[:env_path]).length > 2 # [ '.', '..' ]
|
624
|
+
puts ERB.new( @@strs[:initenv][:env_not_empty] ).result( binding )
|
625
|
+
exit
|
626
|
+
end
|
830
627
|
end
|
831
|
-
end
|
832
628
|
|
833
|
-
|
834
|
-
|
629
|
+
require 'conf/default'
|
630
|
+
default_config = Configuration.new(@args,true).config
|
835
631
|
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
632
|
+
config = {
|
633
|
+
:base_url => (@args[:base_url] or default_config[:base_url]),
|
634
|
+
:http_server => {
|
635
|
+
:port => (@args[:port] or default_config[:http_server][:port]),
|
636
|
+
:bind_address => (@args[:addr] or default_config[:http_server][:bind_address]),
|
637
|
+
:rack_require => (@args[:server] or default_config[:http_server][:rack_require])
|
638
|
+
},
|
639
|
+
:index_html => {
|
640
|
+
:title => (@args[:title] or default_config[:index_html][:title])
|
641
|
+
},
|
642
|
+
:database => {
|
643
|
+
:ses_db => (@args[:db] or default_config[:database][:ses_db])
|
644
|
+
}
|
848
645
|
}
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
puts <<-END
|
859
|
-
|
860
|
-
Creating a new RSence environment at #{@args[:env_path]}
|
861
|
-
|
862
|
-
RSence will first ask a few questions about your environment
|
863
|
-
in order to initialize and prepare the project configuration.
|
864
|
-
|
865
|
-
You may abort this command at any time by pressing CTRL-C
|
866
|
-
Nothing will be written until you have answered all the questions.
|
867
|
-
|
868
|
-
Pressing the ENTER (or RETURN) key at each prompt will choose the
|
869
|
-
default option shown.
|
870
|
-
If you are not sure about how to answer a question, press
|
871
|
-
the ENTER (or RETURN) key to continue.
|
872
|
-
|
873
|
-
END
|
646
|
+
Signal.trap 'INT' do
|
647
|
+
puts
|
648
|
+
puts "Configuration aborted."
|
649
|
+
exit
|
650
|
+
end
|
651
|
+
if interactive
|
652
|
+
answers_ok = false
|
653
|
+
until answers_ok
|
654
|
+
puts ERB.new( @@strs[:initenv][:creating_env] ).result( binding )
|
874
655
|
|
875
|
-
|
656
|
+
require 'highline/import'
|
876
657
|
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
END
|
883
|
-
config[:index_html][:title] = ask("Project Title") do |q|
|
884
|
-
q.default = config[:index_html][:title]
|
885
|
-
end
|
886
|
-
|
887
|
-
say <<-END
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
Please specify the connection string for the session database to use.
|
892
|
-
By default, a local SQLite database is created in the 'db' subdirectory
|
893
|
-
of the environment directory. Any database supported by Sequel is supported
|
894
|
-
by RSence.
|
895
|
-
|
896
|
-
For further information about database connection strings, read the Sequel
|
897
|
-
documentation at:
|
898
|
-
http://sequel.rubyforge.org/rdoc/files/doc/opening_databases_rdoc.html
|
899
|
-
|
900
|
-
You will also need the appropriate ruby driver for the database selected. If
|
901
|
-
none is installed, RSence will not be able to store persistent session data
|
902
|
-
between server restarts.
|
903
|
-
|
904
|
-
END
|
905
|
-
config[:database][:ses_db] = ask("Session database connection string") do |q|
|
906
|
-
q.default = config[:database][:ses_db]
|
907
|
-
end
|
908
|
-
say <<-END
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
Please enter a HTTP port for the server to listen to. This port must not be a
|
913
|
-
TCP port already in use.
|
914
|
-
|
915
|
-
END
|
916
|
-
config[:http_server][:port] = ask("HTTP Port:") do |q|
|
917
|
-
q.default = config[:http_server][:port]
|
918
|
-
end
|
919
|
-
say <<-END
|
920
|
-
|
921
|
-
|
922
|
-
Please enter a TCP/IP address for the HTTP server to listen to. This address
|
923
|
-
must be an address configured by a network interface of this computer.
|
924
|
-
|
925
|
-
The address 0.0.0.0 matches any interfaces.
|
926
|
-
The address 127.0.0.1 matches only the localhost address, this address is
|
927
|
-
not accessible from any other computer.
|
928
|
-
|
929
|
-
END
|
930
|
-
config[:http_server][:bind_address] = ask("Interface TCP/IP address:") do |q|
|
931
|
-
q.default = config[:http_server][:bind_address]
|
932
|
-
end
|
658
|
+
say @@strs[:initenv][:enter_title]
|
659
|
+
str_project_title = @@strs[:initenv][:project_title]
|
660
|
+
config[:index_html][:title] = ask( str_project_title ) do |q|
|
661
|
+
q.default = config[:index_html][:title]
|
662
|
+
end
|
933
663
|
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
664
|
+
say @@strs[:initenv][:enter_db_url]
|
665
|
+
str_db_url = @@strs[:initenv][:db_url]
|
666
|
+
config[:database][:ses_db] = ask(str_db_url) do |q|
|
667
|
+
q.default = config[:database][:ses_db]
|
668
|
+
end
|
669
|
+
|
670
|
+
say @@strs[:initenv][:enter_http_port]
|
671
|
+
str_http_port = @@strs[:initenv][:http_port]
|
672
|
+
config[:http_server][:port] = ask(str_http_port) do |q|
|
673
|
+
q.default = config[:http_server][:port]
|
674
|
+
end
|
675
|
+
|
676
|
+
say @@strs[:initenv][:enter_tcp_ip]
|
677
|
+
str_tcp_ip = @@strs[:initenv][:tcp_ip]
|
678
|
+
config[:http_server][:bind_address] = ask(str_tcp_ip) do |q|
|
679
|
+
q.default = config[:http_server][:bind_address]
|
680
|
+
end
|
681
|
+
|
682
|
+
say @@strs[:initenv][:enter_root_dir]
|
683
|
+
str_root_dir = @@strs[:initenv][:root_dir]
|
684
|
+
config[:base_url] = ask(str_root_dir) do |q|
|
685
|
+
q.default = config[:base_url]
|
686
|
+
end
|
687
|
+
|
688
|
+
test_url = "http://#{config[:http_server][:bind_address]}:#{config[:http_server][:port]}#{config[:base_url]}"
|
689
|
+
say ERB.new( @@strs[:initenv][:config_summary] ).result( binding )
|
690
|
+
print @@strs[:initenv][:confirm_config]
|
691
|
+
answers_ok = yesno(true)
|
943
692
|
end
|
693
|
+
else
|
944
694
|
test_url = "http://#{config[:http_server][:bind_address]}:#{config[:http_server][:port]}#{config[:base_url]}"
|
945
|
-
say <<-END
|
946
|
-
|
947
|
-
Configuration Summary
|
948
|
-
|
949
|
-
Please verify that the configuration is correct.
|
950
|
-
This configuration will be written into the configuration file:
|
951
|
-
#{conf_file}
|
952
|
-
|
953
|
-
Title: #{config[:index_html][:title]}
|
954
|
-
|
955
|
-
Database: #{config[:database][:ses_db]}
|
956
|
-
|
957
|
-
HTTP Server:
|
958
|
-
Address: #{config[:http_server][:bind_address]}
|
959
|
-
Port: #{config[:http_server][:port]}
|
960
|
-
URI Prefix: #{config[:base_url]}
|
961
|
-
|
962
|
-
This means the URL will be #{test_url}
|
963
|
-
|
964
|
-
END
|
965
|
-
print "Is the configuration correct, "
|
966
|
-
answers_ok = yesno(true)
|
967
695
|
end
|
968
|
-
|
969
|
-
|
696
|
+
|
697
|
+
puts @@strs[:initenv][:creating_dirs]
|
698
|
+
env_dir = @args[:env_path]
|
699
|
+
require 'fileutils'
|
700
|
+
FileUtils.mkdir_p( env_dir ) unless File.exists?( env_dir )
|
701
|
+
conf_dir = File.expand_path( 'conf', env_dir )
|
702
|
+
Dir.mkdir( conf_dir )
|
703
|
+
db_dir = File.expand_path( 'db', env_dir )
|
704
|
+
Dir.mkdir( db_dir )
|
705
|
+
log_dir = File.expand_path( 'log', env_dir )
|
706
|
+
Dir.mkdir( log_dir )
|
707
|
+
plugins_dir = File.expand_path( 'plugins', env_dir )
|
708
|
+
Dir.mkdir( plugins_dir )
|
709
|
+
run_dir = File.expand_path( 'run', env_dir )
|
710
|
+
Dir.mkdir( run_dir )
|
711
|
+
unless create_blank
|
712
|
+
welcome_plugin_dir = File.join( SERVER_PATH, 'setup', 'welcome' )
|
713
|
+
welcome_plugin_dst = File.join( plugins_dir, 'welcome' )
|
714
|
+
puts ERB.new( @@strs[:initenv][:installing_welcome_plugin] ).result( binding )
|
715
|
+
FileUtils.cp_r( welcome_plugin_dir, welcome_plugin_dst )
|
716
|
+
end
|
717
|
+
puts @@strs[:initenv][:creating_files]
|
718
|
+
conf_file = File.join( conf_dir, 'config.yaml' )
|
719
|
+
File.open( conf_file, 'w' ) {|f| f.write( YAML.dump( config ) ) }
|
720
|
+
readme_file = File.join( env_dir, 'README' )
|
721
|
+
File.open( readme_file, 'w' ) {|f| f.write( ERB.new( @@strs[:initenv][:readme] ).result( binding ) ) }
|
722
|
+
version_file = File.join( env_dir, 'VERSION' )
|
723
|
+
File.open( version_file, 'w' ) {|f| f.write( "RSence Environment Version #{version.to_f}" ) }
|
724
|
+
puts ERB.new( @@strs[:initenv][:congratulations] ).result( binding )
|
725
|
+
exit
|
970
726
|
end
|
971
727
|
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
plugins_dir = File.expand_path( 'plugins', env_dir )
|
983
|
-
Dir.mkdir( plugins_dir )
|
984
|
-
run_dir = File.expand_path( 'run', env_dir )
|
985
|
-
Dir.mkdir( run_dir )
|
986
|
-
unless create_blank
|
987
|
-
welcome_plugin_dir = File.join( SERVER_PATH, 'setup', 'welcome' )
|
988
|
-
welcome_plugin_dst = File.join( plugins_dir, 'welcome' )
|
989
|
-
puts "Installing the welcome plugin. To remove it, just delete this folder:"
|
990
|
-
puts " #{welcome_plugin_dst}"
|
991
|
-
FileUtils.cp_r( welcome_plugin_dir, welcome_plugin_dst )
|
728
|
+
# Main parser for the help command
|
729
|
+
def help( cmd )
|
730
|
+
cmd.to_sym! if cmd.class != Symbol
|
731
|
+
puts @@strs[:help][:head]
|
732
|
+
if @@strs[:help].has_key?(cmd)
|
733
|
+
puts @@strs[:help][cmd]
|
734
|
+
else
|
735
|
+
puts @@strs[:help][:help_main]
|
736
|
+
end
|
737
|
+
puts @@strs[:help][:tail]
|
992
738
|
end
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
File.open( readme_file, 'w' ) {|f| f.write( <<-END
|
998
|
-
This directory contains a RSence environment titled '#{config[:index_html][:title]}'.
|
999
|
-
Visit http://rsence.org/ for further information.
|
1000
|
-
END
|
1001
|
-
) }
|
1002
|
-
version_file = File.join( env_dir, 'VERSION' )
|
1003
|
-
File.open( version_file, 'w' ) {|f| f.write( "RSence Environment Version #{version.to_f}" ) }
|
1004
|
-
puts <<-END
|
1005
|
-
|
1006
|
-
#{'-='*39}-
|
1007
|
-
|
1008
|
-
RSence project environment for '#{config[:index_html][:title]}' created.
|
1009
|
-
|
1010
|
-
You may configure the environment by editing the file:
|
1011
|
-
|
1012
|
-
#{conf_file}
|
1013
|
-
|
1014
|
-
If you would like to test this environment now, start the RSence server:
|
1015
|
-
|
1016
|
-
rsence run #{env_dir}
|
1017
|
-
|
1018
|
-
Then point your browser to:
|
1019
|
-
|
1020
|
-
#{test_url}
|
1021
|
-
|
1022
|
-
The latest documentation and further information is available at the
|
1023
|
-
RSence website:
|
1024
|
-
|
1025
|
-
http://rsence.org/
|
1026
|
-
|
1027
|
-
|
1028
|
-
Congratulations!
|
1029
|
-
|
1030
|
-
END
|
1031
|
-
exit
|
1032
|
-
end
|
1033
|
-
|
1034
|
-
def help( cmd )
|
1035
|
-
cmd.to_sym! if cmd.class != Symbol
|
1036
|
-
puts @@cmd_help[:head]
|
1037
|
-
if @@cmd_help.has_key?(cmd)
|
1038
|
-
puts @@cmd_help[cmd]
|
1039
|
-
else
|
1040
|
-
puts @@cmd_help[:help_main]
|
739
|
+
|
740
|
+
# Returns the version of RSence
|
741
|
+
def version
|
742
|
+
@@version
|
1041
743
|
end
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
end
|
1052
|
-
|
1053
|
-
def args
|
1054
|
-
@args
|
1055
|
-
end
|
1056
|
-
|
1057
|
-
def parse_argv
|
1058
|
-
if @argv.empty?
|
1059
|
-
puts @@cmd_help[:help_help]
|
1060
|
-
exit
|
1061
|
-
else
|
1062
|
-
cmd = @argv[0].to_sym
|
1063
|
-
cmd = :help if [:h, :'-h', :'--help', :'-help'].include? cmd
|
744
|
+
|
745
|
+
# Returns the command the process was started with.
|
746
|
+
def cmd
|
747
|
+
@cmd
|
748
|
+
end
|
749
|
+
|
750
|
+
# Returns the parsed optional arguments
|
751
|
+
def args
|
752
|
+
@args
|
1064
753
|
end
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
754
|
+
|
755
|
+
# Top-level argument parser, checks for command and calls sub-parser, if valid command.
|
756
|
+
def parse_argv
|
757
|
+
if @argv.empty?
|
758
|
+
puts @@strs[:help][:help_help]
|
759
|
+
exit
|
760
|
+
else
|
761
|
+
cmd = @argv[0].to_sym
|
762
|
+
cmd = :help if [:h, :'-h', :'--help', :'-help'].include? cmd
|
763
|
+
end
|
764
|
+
if @@cmds.include?(cmd)
|
765
|
+
@cmd = cmd
|
766
|
+
if cmd == :help
|
767
|
+
parse_help_argv
|
768
|
+
elsif cmd == :version
|
769
|
+
puts version
|
770
|
+
exit
|
771
|
+
elsif [:run,:start,:stop,:restart].include? cmd
|
772
|
+
parse_startup_argv
|
773
|
+
elsif cmd == :status
|
774
|
+
parse_status_argv
|
775
|
+
elsif cmd == :save
|
776
|
+
parse_save_argv
|
777
|
+
elsif cmd == :initenv
|
778
|
+
parse_initenv_argv
|
779
|
+
end
|
780
|
+
else
|
781
|
+
puts @@strs[:help][:unknown] + cmd.to_s.inspect
|
782
|
+
puts @@strs[:help][:help_help]
|
1071
783
|
exit
|
1072
|
-
elsif [:run,:start,:stop,:restart].include? cmd
|
1073
|
-
parse_startup_argv
|
1074
|
-
elsif cmd == :status
|
1075
|
-
parse_status_argv
|
1076
|
-
elsif cmd == :save
|
1077
|
-
parse_save_argv
|
1078
|
-
elsif cmd == :initenv
|
1079
|
-
parse_initenv_argv
|
1080
784
|
end
|
1081
|
-
else
|
1082
|
-
puts @@cmd_help[:unknown] + cmd.to_s.inspect
|
1083
|
-
puts @@cmd_help[:help_help]
|
1084
|
-
exit
|
1085
785
|
end
|
1086
|
-
|
786
|
+
|
787
|
+
# Entry point for ARGV parsing
|
788
|
+
def parse( argv )
|
789
|
+
@argv = argv
|
790
|
+
@startable = false
|
791
|
+
parse_argv
|
792
|
+
end
|
793
|
+
|
794
|
+
# The constructor sets the @startable flag as false. Use the #parse method with ARGV as the argument to start parsing the ARGV.
|
795
|
+
def initialize
|
796
|
+
@startable = false
|
797
|
+
end
|
1087
798
|
|
1088
|
-
def parse( argv )
|
1089
|
-
@argv = argv
|
1090
|
-
@startable = false
|
1091
|
-
parse_argv
|
1092
799
|
end
|
1093
800
|
|
1094
|
-
|
1095
|
-
|
1096
|
-
end
|
801
|
+
# This accessor enables RSence.argv method, which returns the ARGVParser instance
|
802
|
+
def self.argv; @@argv_parser; end
|
1097
803
|
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
def self.args; @@argv_parser.args; end
|
1103
|
-
|
1104
|
-
|
1105
|
-
def self.
|
1106
|
-
|
1107
|
-
#
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
804
|
+
# This accessor enables RSence.cmd method, which returns the command the process was started with.
|
805
|
+
def self.cmd; @@argv_parser.cmd; end
|
806
|
+
|
807
|
+
# This accessor enables RSence.args method, which returns the parsed command-line arguments.
|
808
|
+
def self.args; @@argv_parser.args; end
|
809
|
+
|
810
|
+
# This accessor enables RSence.startable? method, which returns true if a start-type command was given.
|
811
|
+
def self.startable?; @@argv_parser.startable?; end
|
812
|
+
|
813
|
+
# This accessor enables RSence.version method, which returns the RSence version number.
|
814
|
+
def self.version; @@argv_parser.version; end
|
815
|
+
|
816
|
+
# This accessor enables RSence.startup method, which starts RSence.
|
817
|
+
def self.startup
|
818
|
+
puts "Loading configuration..." if self.args[:verbose]
|
819
|
+
# Use the default configuration:
|
820
|
+
require 'conf/default'
|
821
|
+
@@config = Configuration.new(self.args).config
|
822
|
+
def self.config
|
823
|
+
@@config
|
824
|
+
end
|
825
|
+
## Riassence Daemon controls
|
826
|
+
require 'daemon/daemon'
|
827
|
+
puts "Starting RSence..." if self.args[:verbose]
|
828
|
+
daemon = HTTPDaemon.new
|
829
|
+
daemon.daemonize!
|
1112
830
|
end
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
daemon = HTTPDaemon.new
|
1117
|
-
daemon.daemonize!
|
1118
|
-
end
|
1119
|
-
@@argv_parser = ARGVParser.new
|
1120
|
-
@@argv_parser.parse( ARGV )
|
831
|
+
|
832
|
+
@@argv_parser = ARGVParser.new
|
833
|
+
@@argv_parser.parse( ARGV )
|
1121
834
|
|
1122
835
|
end
|
1123
836
|
|