Module: Dorsal::Privates
- Included in:
- Controller, ImplementationServer
- Defined in:
- lib/dorsal/privates.rb
Overview
module mixin for privates methods for both Controller and ImplementationServer
Instance Method Summary collapse
-
#daemonize(_options) { ... } ⇒ Fixnum
method for daemonize blocks.
-
#start(_options = {}) { ... } ⇒ Fixnum
daemonize wrapper to prevent processus cloning.
-
#status(_options = {}) ⇒ TrueClass, FalseClass
give the status of a processus.
-
#stop(_options = {}) ⇒ TrueClass, FalseClass
stop a running processus.
Instance Method Details
#daemonize(_options) { ... } ⇒ Fixnum
method for daemonize blocks
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/dorsal/privates.rb', line 58 def daemonize() = Methodic::() .specify_presences_of :description, :pid_file .validate return yield if [:debug] pid = fork do trap("SIGINT"){ exit! 0 } trap("SIGTERM"){ exit! 0 } trap("SIGHUP"){ exit! 0 } Process.daemon $0 = [:description] yield end File.open([:pid_file],"w"){|f| f.puts pid } if [:pid_file] return pid end |
#start(_options = {}) { ... } ⇒ Fixnum
daemonize wrapper to prevent processus cloning
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/dorsal/privates.rb', line 118 def start( = {}) = Methodic::() .specify_presences_of :description, :pid_file .validate raise Dorsal::RingServerError::new('already running, pid file exist') if File::exist?([:pid_file]) raise Dorsal::RingServerError::new('already running') unless `ps aux|grep ruby|grep -v grep |grep '#{[:description]}'`.empty? return daemonize() do yield end end |
#status(_options = {}) ⇒ TrueClass, FalseClass
give the status of a processus
170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/dorsal/privates.rb', line 170 def status( = {}) = Methodic::() .specify_presences_of :description, :pid_file .validate pid = `COLUMNS=160 ps aux|grep ruby|grep -v grep |grep '#{[:description]}'|awk '{ print $2}'` if pid.empty? then return false else File.open([:pid_file],"w"){|f| f.puts pid } unless File::exist?([:pid_file]) return true end end |
#stop(_options = {}) ⇒ TrueClass, FalseClass
stop a running processus
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/dorsal/privates.rb', line 141 def stop( = {}) = Methodic::() .specify_presences_of :description, :pid_file .validate File::unlink([:pid_file]) if File::exist?([:pid_file]) pid = `COLUMNS=160 ps aux|grep ruby|grep -v grep |grep '#{[:description]}'|awk '{ print $2}'` if pid.empty? then return false else if [:name] == 'ringserver' then raise Dorsal::ServerError::new('Stopping failed') unless system("kill -TERM #{pid} > /dev/null") else return false unless system("kill -TERM #{pid} > /dev/null") end return true end end |