From eee2baeeaf14d8e538cecf41c5ef949a4dc8bb54 Mon Sep 17 00:00:00 2001 From: YUKI Hiroshi Date: Wed, 24 Sep 2014 18:59:55 +0900 Subject: [PATCH] Make droonga-engine-configure available only for service installation --- bin/droonga-engine-configure | 44 ++++---------------------- lib/droonga/service_installation.rb | 49 ++++++++--------------------- 2 files changed, 19 insertions(+), 74 deletions(-) diff --git a/bin/droonga-engine-configure b/bin/droonga-engine-configure index da6da06a..575673b1 100755 --- a/bin/droonga-engine-configure +++ b/bin/droonga-engine-configure @@ -95,7 +95,7 @@ service_installation.ensure_using_service_base_directory running = false begin - if service_installation.running?(configuration.pid_file_path) + if service_installation.running? if !options[:quiet] puts("The droonga-engine service is now running.") puts("Before reconfiguration, the service is going to be stopped " + @@ -106,8 +106,8 @@ begin end running = true end -rescue Droonga::ServiceInstallation::MissingPidFilePath - puts("Couldn't detect running status of the service.") +rescue Droonga::NotInstalledAsService::MissingPidFilePath + puts("Not installed as a service yet.") end unless service_installation.have_write_permission? @@ -145,7 +145,7 @@ end if running unjoin(configuration) - service_installation.stop_service(configuration.pid_file_path) + service_installation.stop end if options[:clear] @@ -175,52 +175,20 @@ if options[:reset_config] or options[:reset_catalog] end if options[:reset_config] - if service_installation.user_exist? - daemon = true - elsif configuration.have_given_daemon? or options[:quiet] - daemon = configuration.daemon? - else - daemon = confirmed?("run as a daemon?") - end - - if service_installation.user_exist? - log_file = Droonga::Path.default_log_file - elsif configuration.have_given_log_file? - log_file = configuration.log_file - elsif options[:quiet] - log_file = Droonga::Path.default_log_file - else - log_file = input("path to the log file", Droonga::Path.default_log_file) - end - if configuration.have_given_log_level? or options[:quiet] log_level = configuration.log_level else log_level = input("log level", configuration.log_level) end - pid_file_path = nil - unless service_installation.installed_as_service? - if options[:quiet] or service_installation.user_exist? - pid_file_path = Droonga::Path.default_pid_file - elsif configuration.have_given_pid_file? - pid_file_path = configuration.pid_file_path - else - pid_file_path = input("path to the PID file", Droonga::Path.default_pid_file) - end - end - new_configuration = { "host" => host, "port" => port, "tag" => tag, - "daemon" => daemon, - "log_file" => path_from_base_dir(log_file), + "daemon" => true, + "log_file" => path_from_base_dir(Droonga::Path.default_log_file), "log_level" => log_level, } - unless pid_file_path.nil? - new_configuration["pid_file"] = path_from_base_dir(pid_file_path) - end Droonga::SafeFileWriter.write(Droonga::Path.config, YAML.dump(new_configuration)) end diff --git a/lib/droonga/service_installation.rb b/lib/droonga/service_installation.rb index eaa47b96..8fbb5aec 100644 --- a/lib/droonga/service_installation.rb +++ b/lib/droonga/service_installation.rb @@ -22,7 +22,7 @@ class ServiceInstallation class << self end - class MissingPidFilePath < ArgumentError + class NotInstalledAsService < StandardError end def user_name @@ -93,46 +93,23 @@ def ensure_correct_file_permission(file) end def running?(pid_file_path=nil) - if installed_as_service? - result = `env SYSTEMCTL_SKIP_REDIRECT=yes service droonga-engine status` - result.include?("running") - else - if pid_file_path.nil? - raise MissingPidFilePath.new - end - system("droonga-engine-status", - "--base-dir", Path.base.to_s, - "--pid-file", pid_file_path.to_s, - :out => "/dev/null", - :err => "/dev/null") - end + raise NotInstalledAsService.new unless installed_as_service? + result = `env SYSTEMCTL_SKIP_REDIRECT=yes service droonga-engine status` + result.include?("running") end def start - if installed_as_service? - system("service", "droonga-engine", "start", - :out => "/dev/null", - :err => "/dev/null") - else - false - end + raise NotInstalledAsService.new unless installed_as_service? + system("service", "droonga-engine", "start", + :out => "/dev/null", + :err => "/dev/null") end - def stop(pid_file_path=nil) - if installed_as_service? - system("service", "droonga-engine", "stop", - :out => "/dev/null", - :err => "/dev/null") - else - if pid_file_path.nil? - raise MissingPidFilePath.new - end - system("droonga-engine-stop", - "--base-dir", Path.base.to_s, - "--pid-file", pid_file_path.to_s, - :out => "/dev/null", - :err => "/dev/null") - end + def stop + raise NotInstalledAsService.new unless installed_as_service? + system("service", "droonga-engine", "stop", + :out => "/dev/null", + :err => "/dev/null") end end end