Class: Droonga::ServiceInstallation
- Inherits:
-
Object
- Object
- Droonga::ServiceInstallation
show all
- Defined in:
- lib/droonga/service_installation.rb
Defined Under Namespace
Classes: NotInstalledAsService
Instance Method Summary
collapse
Instance Method Details
#base_directory ⇒ Object
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_directory ⇒ Object
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_name ⇒ Object
32
33
34
|
# File 'lib/droonga/service_installation.rb', line 32
def group_name
"droonga"
end
|
#have_read_permission? ⇒ 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
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
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?
succeeded = system("service", "droonga-engine", "status",
:out => "/dev/null",
:err => "/dev/null")
return true if succeeded
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
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?
system("service", "droonga-engine", "status",
:out => "/dev/null",
:err => "/dev/null")
end
|
#start ⇒ Object
107
108
109
110
111
112
113
|
# File 'lib/droonga/service_installation.rb', line 107
def start
raise NotInstalledAsService.new unless installed_as_service?
system("service", "droonga-engine", "start",
:out => "/dev/null",
:err => "/dev/null")
end
|
#stop ⇒ Object
115
116
117
118
119
120
121
|
# File 'lib/droonga/service_installation.rb', line 115
def stop
raise NotInstalledAsService.new unless installed_as_service?
system("service", "droonga-engine", "stop",
:out => "/dev/null",
:err => "/dev/null")
end
|
#user_exist? ⇒ 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_name ⇒ Object
28
29
30
|
# File 'lib/droonga/service_installation.rb', line 28
def user_name
"droonga-engine"
end
|