Class: Droonga::ServiceInstallation

Inherits:
Object
  • Object
show all
Defined in:
lib/droonga/service_installation.rb

Defined Under Namespace

Classes: NotInstalledAsService

Instance Method Summary collapse

Instance Method Details

#base_directoryObject



36
37
38
# File 'lib/droonga/service_installation.rb', line 36

def base_directory
  @base_directory ||= Pathname("/home/#{user_name}/droonga")
end

#ensure_correct_file_permission(file) ⇒ Object



92
93
94
95
96
97
# File 'lib/droonga/service_installation.rb', line 92

def ensure_correct_file_permission(file)
  if user_exist?
    FileUtils.chown_R(user_name, group_name, file)
    FileUtils.chmod_R("go+r", file)
  end
end

#ensure_using_service_base_directoryObject



40
41
42
43
44
# File 'lib/droonga/service_installation.rb', line 40

def ensure_using_service_base_directory
  if user_exist?
    Path.base = base_directory.to_s
  end
end

#group_nameObject



32
33
34
# File 'lib/droonga/service_installation.rb', line 32

def group_name
  "droonga"
end

#have_read_permission?Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
54
# File 'lib/droonga/service_installation.rb', line 46

def have_read_permission?
  test_file = Path.config
  begin
    test_file.read
  rescue Errno::EACCES
    return false
  end
  true
end

#have_write_permission?Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/droonga/service_installation.rb', line 56

def have_write_permission?
  test_file = Path.base + "#{Time.now.to_i}.test"
  begin
    FileUtils.mkdir_p(Path.base)
    FileUtils.touch(test_file.to_s)
  rescue Errno::EACCES
  end
  unless test_file.exist?
    return false
  end
  FileUtils.rm_f(test_file.to_s)
  true
end

#installed_as_service?Boolean

Returns:

  • (Boolean)


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/droonga/service_installation.rb', line 76

def installed_as_service?
  return false unless user_exist?

  #TODO: we should support systemd also...
  succeeded = system("service", "droonga-engine", "status",
                     :out => "/dev/null",
                     :err => "/dev/null")
  return true if succeeded

  #TODO: we should support systemd also...
  result = `service droonga-engine status`
  result.include?("running") or \
    result.include?("droonga-engine is stopped") or \
    result.include?("droonga-engine dead")
end

#running?(pid_file_path = nil) ⇒ Boolean

Returns:

  • (Boolean)

Raises:



99
100
101
102
103
104
105
# File 'lib/droonga/service_installation.rb', line 99

def running?(pid_file_path=nil)
  raise NotInstalledAsService.new unless installed_as_service?
  #TODO: we should support systemd also...
  system("service", "droonga-engine", "status",
         :out => "/dev/null",
         :err => "/dev/null")
end

#startObject



107
108
109
110
111
112
113
# File 'lib/droonga/service_installation.rb', line 107

def start
  raise NotInstalledAsService.new unless installed_as_service?
  #TODO: we should support systemd also...
  system("service", "droonga-engine", "start",
         :out => "/dev/null",
         :err => "/dev/null")
end

#stopObject



115
116
117
118
119
120
121
# File 'lib/droonga/service_installation.rb', line 115

def stop
  raise NotInstalledAsService.new unless installed_as_service?
  #TODO: we should support systemd also...
  system("service", "droonga-engine", "stop",
         :out => "/dev/null",
         :err => "/dev/null")
end

#user_exist?Boolean

Returns:

  • (Boolean)


70
71
72
73
74
# File 'lib/droonga/service_installation.rb', line 70

def user_exist?
  system("id", user_name,
         :out => "/dev/null",
         :err => "/dev/null")
end

#user_nameObject



28
29
30
# File 'lib/droonga/service_installation.rb', line 28

def user_name
  "droonga-engine"
end