-
Notifications
You must be signed in to change notification settings - Fork 301
/
Copy pathsystemd.rake
139 lines (120 loc) · 4.54 KB
/
systemd.rake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# frozen_string_literal: true
git_plugin = self
namespace :puma do
desc 'Install Puma systemd service'
task :install do
on roles(fetch(:puma_role)) do |role|
upload_compiled_template = lambda do |template_name, unit_filename|
git_plugin.template_puma template_name, "#{fetch(:tmp_dir)}/#{unit_filename}", role
systemd_path = fetch(:puma_systemd_conf_dir, git_plugin.fetch_systemd_unit_path)
if fetch(:puma_systemctl_user) == :system
sudo "mv #{fetch(:tmp_dir)}/#{unit_filename} #{systemd_path}"
else
execute :mkdir, "-p", systemd_path
execute :mv, "#{fetch(:tmp_dir)}/#{unit_filename}", "#{systemd_path}"
end
end
upload_compiled_template.call("puma.service", "#{fetch(:puma_service_unit_name)}.service")
if fetch(:puma_enable_socket_service)
upload_compiled_template.call("puma.socket", "#{fetch(:puma_service_unit_name)}.socket")
end
# Reload systemd
git_plugin.execute_systemd("daemon-reload")
invoke "puma:enable"
end
end
desc 'Uninstall Puma systemd service'
task :uninstall do
invoke 'puma:disable'
on roles(fetch(:puma_role)) do |role|
systemd_path = fetch(:puma_systemd_conf_dir, git_plugin.fetch_systemd_unit_path)
if fetch(:puma_systemctl_user) == :system
sudo "rm -f #{systemd_path}/#{fetch(:puma_service_unit_name)}*"
else
execute :rm, "-f", "#{systemd_path}/#{fetch(:puma_service_unit_name)}*"
end
git_plugin.execute_systemd("daemon-reload")
end
end
desc 'Enable Puma systemd service'
task :enable do
on roles(fetch(:puma_role)) do
git_plugin.execute_systemd("enable", fetch(:puma_service_unit_name))
git_plugin.execute_systemd("enable", fetch(:puma_service_unit_name) + ".socket") if fetch(:puma_enable_socket_service)
if fetch(:puma_systemctl_user) != :system && fetch(:puma_enable_lingering)
sudo "loginctl enable-linger #{fetch(:puma_lingering_user)}"
end
end
end
desc 'Disable Puma systemd service'
task :disable do
on roles(fetch(:puma_role)) do
git_plugin.execute_systemd("disable", fetch(:puma_service_unit_name))
git_plugin.execute_systemd("disable", fetch(:puma_service_unit_name) + ".socket") if fetch(:puma_enable_socket_service)
end
end
desc 'Start Puma service via systemd'
task :start do
on roles(fetch(:puma_role)) do
git_plugin.execute_systemd("start", fetch(:puma_service_unit_name))
end
end
desc 'Stop Puma service via systemd'
task :stop do
on roles(fetch(:puma_role)) do
git_plugin.execute_systemd("stop", fetch(:puma_service_unit_name))
end
end
desc 'Stop Puma socket via systemd'
task :stop_socket do
on roles(fetch(:puma_role)) do
git_plugin.execute_systemd("stop", fetch(:puma_service_unit_name) + ".socket")
end
end
desc 'Restarts or reloads Puma service via systemd'
task :smart_restart do
if fetch(:puma_phased_restart)
invoke 'puma:reload'
else
invoke 'puma:restart'
end
end
desc 'Restart Puma service via systemd'
task :restart do
on roles(fetch(:puma_role)) do
git_plugin.execute_systemd("restart", fetch(:puma_service_unit_name))
end
end
desc 'Restart Puma socket via systemd'
task :restart_socket do
on roles(fetch(:puma_role)) do
git_plugin.execute_systemd("restart", fetch(:puma_service_unit_name) + ".socket")
end
end
desc 'Reload Puma service via systemd'
task :reload do
on roles(fetch(:puma_role)) do
service_ok = if fetch(:puma_systemctl_user) == :system
execute("#{fetch(:puma_systemctl_bin)} status #{fetch(:puma_service_unit_name)} > /dev/null", raise_on_non_zero_exit: false)
else
execute("#{fetch(:puma_systemctl_bin)} --user status #{fetch(:puma_service_unit_name)} > /dev/null", raise_on_non_zero_exit: false)
end
cmd = 'reload'
unless service_ok
cmd = 'restart'
end
if fetch(:puma_systemctl_user) == :system
sudo "#{fetch(:puma_systemctl_bin)} #{cmd} #{fetch(:puma_service_unit_name)}"
else
execute "#{fetch(:puma_systemctl_bin)}", "--user", cmd, fetch(:puma_service_unit_name)
end
end
end
desc 'Get Puma service status via systemd'
task :status do
on roles(fetch(:puma_role)) do
git_plugin.execute_systemd("status", fetch(:puma_service_unit_name))
git_plugin.execute_systemd("status", fetch(:puma_service_unit_name) + ".socket") if fetch(:puma_enable_socket_service)
end
end
end