@@ -18,8 +18,6 @@ package install
18
18
19
19
import (
20
20
"fmt"
21
- "os"
22
- "strings"
23
21
24
22
"github.com/kardianos/service"
25
23
"github.com/sirupsen/logrus"
@@ -87,11 +85,6 @@ func EnsureService(args []string, envVars []string, force bool) error {
87
85
// fetch service type
88
86
svcType := s .Platform ()
89
87
switch svcType {
90
- case "darwin-launchd" :
91
- svcConfig .Option = map [string ]interface {}{
92
- "EnvironmentMap" : prepareEnvVars (envVars ),
93
- "LaunchdConfig" : launchdConfig ,
94
- }
95
88
case "linux-openrc" :
96
89
deps = []string {"need cgroups" , "need net" , "use dns" , "after firewall" }
97
90
svcConfig .Option = map [string ]interface {}{
@@ -103,7 +96,7 @@ func EnsureService(args []string, envVars []string, force bool) error {
103
96
}
104
97
case "unix-systemv" :
105
98
svcConfig .Option = map [string ]interface {}{
106
- "SystemdScript " : sysvScript ,
99
+ "SysVScript " : sysvScript ,
107
100
}
108
101
case "linux-systemd" :
109
102
deps = []string {"After=network-online.target" , "Wants=network-online.target" }
@@ -151,37 +144,6 @@ func UninstallService(role string) error {
151
144
return s .Uninstall ()
152
145
}
153
146
154
- // GetSysInit returns the sys init platform name, and the stub file path for a system
155
- func GetSysInit (role string ) (sysInitPlatform string , stubFile string , err error ) {
156
- if role == "controller+worker" {
157
- role = "controller"
158
- }
159
- if sysInitPlatform , err = getSysInitPlatform (); err != nil {
160
- return sysInitPlatform , stubFile , err
161
- }
162
- if sysInitPlatform == "linux-systemd" {
163
- stubFile = fmt .Sprintf ("/etc/systemd/system/k0s%s.service" , role )
164
- if _ , err := os .Stat (stubFile ); err != nil {
165
- stubFile = ""
166
- }
167
- } else if sysInitPlatform == "linux-openrc" {
168
- stubFile = fmt .Sprintf ("/etc/init.d/k0s%s" , role )
169
- if _ , err := os .Stat (stubFile ); err != nil {
170
- stubFile = ""
171
- }
172
- }
173
- return sysInitPlatform , stubFile , err
174
- }
175
-
176
- func getSysInitPlatform () (string , error ) {
177
- prg := & Program {}
178
- s , err := service .New (prg , & service.Config {Name : "132" })
179
- if err != nil {
180
- return "" , err
181
- }
182
- return s .Platform (), nil
183
- }
184
-
185
147
func GetServiceConfig (role string ) * service.Config {
186
148
var k0sDisplayName string
187
149
@@ -195,58 +157,3 @@ func GetServiceConfig(role string) *service.Config {
195
157
Description : k0sDescription ,
196
158
}
197
159
}
198
-
199
- func prepareEnvVars (envVars []string ) map [string ]string {
200
- result := make (map [string ]string )
201
- for _ , envVar := range envVars {
202
- parts := strings .SplitN (envVar , "=" , 1 )
203
- if len (parts ) != 2 {
204
- continue
205
- }
206
-
207
- result [parts [0 ]] = parts [1 ]
208
- }
209
- return result
210
- }
211
-
212
- // Upstream kardianos/service does not support all the options we want to set to the systemd unit, hence we override the template
213
- // Currently mostly for KillMode=process so we get systemd to only send the sigterm to the main process
214
- const systemdScript = `[Unit]
215
- Description={{.Description}}
216
- Documentation=https://docs.k0sproject.io
217
- ConditionFileIsExecutable={{.Path|cmdEscape}}
218
- {{range $i, $dep := .Dependencies}}
219
- {{$dep}} {{end}}
220
-
221
- [Service]
222
- StartLimitInterval=5
223
- StartLimitBurst=10
224
- ExecStart={{.Path|cmdEscape}}{{range .Arguments}} {{.|cmdEscape}}{{end}}
225
- {{- if .Option.Environment}}{{range .Option.Environment}}
226
- Environment="{{.}}"{{end}}{{- end}}
227
-
228
- RestartSec=10
229
- Delegate=yes
230
- KillMode=process
231
- LimitCORE=infinity
232
- TasksMax=infinity
233
- TimeoutStartSec=0
234
-
235
- {{- if .ChRoot}}RootDirectory={{.ChRoot|cmd}}{{- end}}
236
-
237
- {{- if .WorkingDirectory}}WorkingDirectory={{.WorkingDirectory|cmdEscape}}{{- end}}
238
- {{- if .UserName}}User={{.UserName}}{{end}}
239
- {{- if .ReloadSignal}}ExecReload=/bin/kill -{{.ReloadSignal}} "$MAINPID"{{- end}}
240
- {{- if .PIDFile}}PIDFile={{.PIDFile|cmd}}{{- end}}
241
- {{- if and .LogOutput .HasOutputFileSupport -}}
242
- StandardOutput=file:/var/log/{{.Name}}.out
243
- StandardError=file:/var/log/{{.Name}}.err
244
- {{- end}}
245
-
246
- {{- if .SuccessExitStatus}}SuccessExitStatus={{.SuccessExitStatus}}{{- end}}
247
- {{ if gt .LimitNOFILE -1 }}LimitNOFILE={{.LimitNOFILE}}{{- end}}
248
- {{ if .Restart}}Restart={{.Restart}}{{- end}}
249
-
250
- [Install]
251
- WantedBy=multi-user.target
252
- `
0 commit comments