Class: Cmdserver::CLI::Daemonizer
- Inherits:
-
Object
- Object
- Cmdserver::CLI::Daemonizer
- Defined in:
- lib/cmdserver/cli.rb
Direct Known Subclasses
Instance Method Summary collapse
- #_handle_sighup ⇒ Object
- #_handle_sigterm ⇒ Object
- #daemon_preparation ⇒ Object
- #daemonize ⇒ Object
-
#initialize ⇒ Daemonizer
constructor
A new instance of Daemonizer.
Constructor Details
#initialize ⇒ Daemonizer
Returns a new instance of Daemonizer.
7 8 9 10 11 12 |
# File 'lib/cmdserver/cli.rb', line 7 def initialize() @dprocess = nil @daemon_pid_file = nil @daemon_pid = nil @daemon_running = false end |
Instance Method Details
#_handle_sighup ⇒ Object
39 40 41 |
# File 'lib/cmdserver/cli.rb', line 39 def _handle_sighup() # Placeholder end |
#_handle_sigterm ⇒ Object
43 44 45 |
# File 'lib/cmdserver/cli.rb', line 43 def _handle_sigterm() # Placeholder end |
#daemon_preparation ⇒ Object
32 33 34 35 36 37 |
# File 'lib/cmdserver/cli.rb', line 32 def daemon_preparation $0 = DAEMON_NAME Process.setsid Signal.trap("HUP", proc { _handle_sighup } ) Signal.trap("TERM", proc { _handle_sigterm } ) end |
#daemonize ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cmdserver/cli.rb', line 14 def daemonize() puts "Forking server to the background..." if @dprocess.nil? puts "FATAL ERROR: No daemon process specified!" exit -1 end pid = fork if not pid #child daemon_preparation() @dprocess.call() puts "Server started." end return pid end |