Class: Cmdserver::CLI::Daemonizer

Inherits:
Object
  • Object
show all
Defined in:
lib/cmdserver/cli.rb

Direct Known Subclasses

ServerDaemonizer

Instance Method Summary collapse

Constructor Details

#initializeDaemonizer

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_sighupObject



39
40
41
# File 'lib/cmdserver/cli.rb', line 39

def _handle_sighup()
    # Placeholder
end

#_handle_sigtermObject



43
44
45
# File 'lib/cmdserver/cli.rb', line 43

def _handle_sigterm()
    # Placeholder
end

#daemon_preparationObject



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

#daemonizeObject



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