lib/process/daemon/controller.rb in process-daemon-0.6.1 vs lib/process/daemon/controller.rb in process-daemon-1.0.0

- old
+ new

@@ -40,22 +40,22 @@ # This function is called from the daemon executable. It processes ARGV and checks whether the user is asking for `start`, `stop`, `restart`, `status`. def daemonize(argv = ARGV) case (argv.shift || :default).to_sym when :start start - status + show_status when :stop stop - status + show_status ProcessFile.cleanup(@daemon) when :restart stop ProcessFile.cleanup(@daemon) start - status + show_status when :status - status + show_status else @output.puts Rainbow("Invalid command. Please specify start, restart, stop or status.").red end end @@ -71,12 +71,12 @@ ProcessFile.store(@daemon, Process.pid) File.umask 0000 Dir.chdir @daemon.working_directory - $stdin.reopen "/dev/null" - $stdout.reopen @daemon.log_file_path, "a" + $stdin.reopen '/dev/null' + $stdout.reopen @daemon.log_file_path, 'a' $stdout.sync = true $stderr.reopen $stdout $stderr.sync = true @@ -97,11 +97,11 @@ # This function starts the daemon process in the background. def start @output.puts Rainbow("Starting #{@daemon.name} daemon...").blue - case ProcessFile.status(@daemon) + case self.status when :running @output.puts Rainbow("Daemon already running!").blue return when :stopped # We are good to go... @@ -130,13 +130,15 @@ end end # Prints out the status of the daemon def status - daemon_state = ProcessFile.status(@daemon) - - case daemon_state + ProcessFile.status(@daemon) + end + + def show_status + case self.status when :running @output.puts Rainbow("Daemon status: running pid=#{ProcessFile.recall(@daemon)}").green when :unknown if @daemon.crashed? @output.puts Rainbow("Daemon status: crashed").red @@ -148,11 +150,9 @@ @output.puts Rainbow("Daemon status: unknown").red end when :stopped @output.puts Rainbow("Daemon status: stopped").blue end - - return daemon_state end # The pid of the daemon if it is available. The pid may be invalid if the daemon has crashed. def pid ProcessFile.recall(@daemon)