Skip to content

Commit

Permalink
Extra arguments from K0S_EXTRA_ARGS
Browse files Browse the repository at this point in the history
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
  • Loading branch information
kke committed Jan 9, 2024
1 parent a8bf7be commit 4b5e977
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 45 deletions.
5 changes: 4 additions & 1 deletion pkg/install/linux_openrc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ limitations under the License.
package install

const openRCScript = `#!/sbin/openrc-run
if [ -f "/etc/conf.d/{{.Name}}" ]; then
. /etc/conf.d/{{.Name}}
fi
{{- if .Option.Environment}}{{range .Option.Environment}}
export {{.}}{{end}}{{- end}}
supervisor=supervise-daemon
name="{{.DisplayName}}"
description="{{.Description}}"
command={{.Path|cmdEscape}}
{{- if .Arguments }}
command_args="{{range .Arguments}}'{{.}}' {{end}}"
command_args="{{range .Arguments}}'{{.}}' {{end}} ${K0S_EXTRA_ARGS}"
{{- end }}
name=$(basename $(readlink -f $command))
supervise_daemon_args="--stdout /var/log/${name}.log --stderr /var/log/${name}.err"
Expand Down
60 changes: 60 additions & 0 deletions pkg/install/linux_systemd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
Copyright 2024 k0s authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package install

// Upstream kardianos/service does not support all the options we want to set to the systemd unit, hence we override the template
// Currently mostly for KillMode=process so we get systemd to only send the sigterm to the main process
const systemdScript = `[Unit]
Description={{.Description}}
Documentation=https://docs.k0sproject.io
ConditionFileIsExecutable={{.Path|cmdEscape}}
{{range $i, $dep := .Dependencies}}
{{$dep}} {{end}}
[Service]
StartLimitInterval=5
StartLimitBurst=10
ExecStart={{.Path|cmdEscape}}{{range .Arguments}} {{.|cmdEscape}}{{end}} $K0S_EXTRA_ARGS
EnvironmentFile=-/etc/systemd/system/{{.Name}}.env
{{- if .Option.Environment}}{{range .Option.Environment}}
Environment="{{.}}"{{end}}{{- end}}
RestartSec=120
Delegate=yes
KillMode=process
LimitCORE=infinity
TasksMax=infinity
TimeoutStartSec=0
{{- if .ChRoot}}RootDirectory={{.ChRoot|cmd}}{{- end}}
{{- if .WorkingDirectory}}WorkingDirectory={{.WorkingDirectory|cmdEscape}}{{- end}}
{{- if .UserName}}User={{.UserName}}{{end}}
{{- if .ReloadSignal}}ExecReload=/bin/kill -{{.ReloadSignal}} "$MAINPID"{{- end}}
{{- if .PIDFile}}PIDFile={{.PIDFile|cmd}}{{- end}}
{{- if and .LogOutput .HasOutputFileSupport -}}
StandardOutput=file:/var/log/{{.Name}}.out
StandardError=file:/var/log/{{.Name}}.err
{{- end}}
{{- if .SuccessExitStatus}}SuccessExitStatus={{.SuccessExitStatus}}{{- end}}
{{ if gt .LimitNOFILE -1 }}LimitNOFILE={{.LimitNOFILE}}{{- end}}
{{ if .Restart}}Restart={{.Restart}}{{- end}}
[Install]
WantedBy=multi-user.target
`
6 changes: 5 additions & 1 deletion pkg/install/linux_sysv.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@ const sysvScript = `#!/bin/sh
# Description: {{.Description}}
### END INIT INFO
if [ -f "/etc/default/{{.Name}}" ]; then
. /etc/default/{{.Name}}
fi
{{- if .Option.Environment}}{{range .Option.Environment}}
export {{.}}{{end}}{{- end}}
cmd="{{.Path}}{{range .Arguments}} {{.|cmd}}{{end}}"
cmd="{{.Path}}{{range .Arguments}} {{.|cmd}}{{end}} ${K0S_EXTRA_ARGS}"
name=$(basename $(readlink -f $0))
pid_file="/var/run/$name.pid"
Expand Down
2 changes: 1 addition & 1 deletion pkg/install/linux_upstart.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ script
set +a
fi
exec {{if and .UserName (not .HasSetUIDStanza)}}sudo -E -u {{.UserName}} {{end}}{{.Path}}{{range .Arguments}} {{.|cmd}}{{end}}{{if .LogOutput}} >> $stdout_log 2>> $stderr_log{{end}}
exec {{if and .UserName (not .HasSetUIDStanza)}}sudo -E -u {{.UserName}} {{end}}{{.Path}}{{range .Arguments}} {{.|cmd}}{{end}} ${K0S_EXTRA_ARGS} {{if .LogOutput}} >> $stdout_log 2>> $stderr_log{{end}}
end script
`
42 changes: 0 additions & 42 deletions pkg/install/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,45 +208,3 @@ func prepareEnvVars(envVars []string) map[string]string {
}
return result
}

// Upstream kardianos/service does not support all the options we want to set to the systemd unit, hence we override the template
// Currently mostly for KillMode=process so we get systemd to only send the sigterm to the main process
const systemdScript = `[Unit]
Description={{.Description}}
Documentation=https://docs.k0sproject.io
ConditionFileIsExecutable={{.Path|cmdEscape}}
{{range $i, $dep := .Dependencies}}
{{$dep}} {{end}}
[Service]
StartLimitInterval=5
StartLimitBurst=10
ExecStart={{.Path|cmdEscape}}{{range .Arguments}} {{.|cmdEscape}}{{end}}
{{- if .Option.Environment}}{{range .Option.Environment}}
Environment="{{.}}"{{end}}{{- end}}
RestartSec=120
Delegate=yes
KillMode=process
LimitCORE=infinity
TasksMax=infinity
TimeoutStartSec=0
{{- if .ChRoot}}RootDirectory={{.ChRoot|cmd}}{{- end}}
{{- if .WorkingDirectory}}WorkingDirectory={{.WorkingDirectory|cmdEscape}}{{- end}}
{{- if .UserName}}User={{.UserName}}{{end}}
{{- if .ReloadSignal}}ExecReload=/bin/kill -{{.ReloadSignal}} "$MAINPID"{{- end}}
{{- if .PIDFile}}PIDFile={{.PIDFile|cmd}}{{- end}}
{{- if and .LogOutput .HasOutputFileSupport -}}
StandardOutput=file:/var/log/{{.Name}}.out
StandardError=file:/var/log/{{.Name}}.err
{{- end}}
{{- if .SuccessExitStatus}}SuccessExitStatus={{.SuccessExitStatus}}{{- end}}
{{ if gt .LimitNOFILE -1 }}LimitNOFILE={{.LimitNOFILE}}{{- end}}
{{ if .Restart}}Restart={{.Restart}}{{- end}}
[Install]
WantedBy=multi-user.target
`

0 comments on commit 4b5e977

Please sign in to comment.