Top Level Namespace
Defined Under Namespace
Modules: MockWS Classes: ApplicationController
Instance Method Summary collapse
-
#daemonize(options) { ... } ⇒ Fixnum
Pid the pid of the forked processus.
-
#search_file_in_gem(gem, file) ⇒ String, False
facility to find a file in gem path.
Instance Method Details
#daemonize(options) { ... } ⇒ Fixnum
Returns pid the pid of the forked processus.
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/mockws.rb', line 155 def daemonize() { :sighup_handler => 'SIGHUP', :sigint_handler => 'SIGINT', :sigterm_handler => 'SIGTERM', }.each do |key,value| trap(value){ if [:sighup_handler].include? key then [:sighup_handler].call else exit! 0 end } end if [:foreground] Process.setproctitle [:description] if [:description] return yield end fork do File.open([:pid_file],"w"){|f| f.puts Process.pid } if [:pid_file] if [:daemon_user] and [:daemon_group] then uid = Etc.getpwnam([:daemon_user]).uid gid = Etc.getgrnam([:daemon_group]).gid Process::UID.change_privilege(uid) Process::GID.change_privilege(gid) end $stdout.reopen([:stdout_trace], "w") if [:stdout_trace] $stderr.reopen([:stderr_trace], "w") if [:stderr_trace] Process.setproctitle [:description] if [:description] yield end return 0 end |
#search_file_in_gem(gem, file) ⇒ String, False
facility to find a file in gem path
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mockws.rb', line 17 def search_file_in_gem(gem, file) if Gem::Specification.respond_to?(:find_by_name) begin spec = Gem::Specification.find_by_name(gem) rescue LoadError spec = nil end else spec = Gem.searcher.find(gem) end if spec res = if Gem::Specification.respond_to?(:find_by_name) spec.lib_dirs_glob.split('/') else Gem.searcher.lib_dirs_for(spec).split('/') end res.pop services_path = res.join('/').concat("/#{file}") return services_path if File.exist?(services_path) end false end |