bin/oversip in oversip-1.0.2 vs bin/oversip in oversip-1.0.3
- old
+ new
@@ -1,18 +1,16 @@
-#!/usr/bin/ruby1.9
+#!/usr/bin/ruby
# -*- encoding: binary -*-
unless RUBY_VERSION >= "1.9.2"
raise LoadError, "OverSIP requires Ruby version >= 1.9.2 (current version is #{RUBY_VERSION})"
end
-
# First of all, trap some signals in order to ignore them if they arrive while
# loading server libraries.
[:HUP, :INT, :USR1, :USR2].each {|signal| trap(signal) {} }
-
require "optparse"
require "etc"
require "oversip"
@@ -26,40 +24,49 @@
::OverSIP::Logger.load_methods
extend ::OverSIP::Logger
# Options by default.
options = {
- :colorize => true
+ :num_instances => 1,
+ :colorize => true
}
- OptionParser.new("", 24, " ") do |opts|
+ OptionParser.new("", 28, " ") do |opts|
opts.banner = "#{::OverSIP::DESCRIPTION}" \
"\n\nUsage: #{File.basename(__FILE__)} " \
"[#{::OverSIP::PROGRAM_NAME} options] [Ruby options]"
opts.separator "\n#{::OverSIP::PROGRAM_NAME} options:"
opts.on("-P", "--pid FILE", "Create a PID file (required)") do |value|
options[:pid_file] = value
end
- opts.on("-p", "--process_name NAME", "Change the running process name, also affects to syslogger process and Posix Message Queue name (default 'oversip')") do |value|
+ opts.on("-p", "--process-name NAME", "Change the running process name, also affects to syslogger process and Posix Message Queue name (default 'oversip')") do |value|
options[:process_name] = value
end
- opts.on("-c", "--dir_config DIR", "Absolute path to the directory with user configuration files (default '/etc/oversip/')") do |value|
- options[:dir_config] = value
+ opts.on("--config-dir DIR", "Absolute path to the directory with user configuration files (default '/etc/oversip/')") do |value|
+ options[:config_dir] = value
end
+ opts.on("--config-file FILE", "Name of the configuration file within the configuration directory (default 'oversip.conf')") do |value|
+ options[:config_file] = value
+ end
+
opts.on("-u", "--user USER", "System user to run with") do |value|
options[:user] = value
end
opts.on("-g", "--group GROUP", "System group to run with") do |value|
options[:group] = value
end
+ opts.on("-n", "--num-instances NUM", "Number of OverSIP instances that will run together in this host (this parameter is just for some resources allocation, it does not run NUM instances!) (default 1)") do |value|
+ options[:num_instances] = value.to_i
+ end
+
opts.on("--no-color", "Don't colorize text printed in stdout") do |value|
options[:colorize] = false
end
opts.on("--remove-mqueue MQUEUE", "Destroy the Posix Message Queue with the given name and exit") do |value|
@@ -154,22 +161,27 @@
fatal "group '#{options[:group]}' does not exist in the system"
end
end
end
+ # Check the --num-instances parameter.
+ if options[:num_instances] < 1
+ fatal "num_instances #{n} is not a valid value (must be greater than 0)"
+ end
+
# Set the command name (as it appears in "ps" output) to given --process_name option (-p)
# or to the script filename otherwise.
$0 = options[:process_name] || File.basename(__FILE__)
OverSIP.master_name = $0
log_system_info "master process name: #{OverSIP.master_name}"
- OverSIP::Config.load options[:dir_config]
+ OverSIP::Config.load options[:config_dir], options[:config_file]
log_system_info "applied configuration:"
OverSIP::Config.print options[:colorize]
log_system_info "creating Posix Message Queue for communicating master and syslogger processes"
- OverSIP::Logger.init_logger_mq options[:group]
+ OverSIP::Logger.init_logger_mq options[:num_instances], options[:group]
OverSIP::Logger.load_methods
OverSIP::Launcher.daemonize!(options)
OverSIP::Launcher.run(options)