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