Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/tbot/config/systemd/systemd.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Group={{ .Group }}
Restart=always
RestartSec=5
Environment="TELEPORT_ANONYMOUS_TELEMETRY={{ if .AnonymousTelemetry }}1{{ else }}0{{ end }}"
ExecStart={{ .TBotPath }} start -c {{ .ConfigPath }}{{ with .DiagSocketForUpdater }} --diag-socket-for-updater={{ . }}{{ end }} --pid-file=/run/{{ .UnitName }}.pid
ExecStart={{ .TBotPath }} start -c {{ .ConfigPath }}{{ with .DiagSocketForUpdater }} --diag-socket-for-updater={{ . }}{{ end }} --pid-file={{ if .PIDFile }}{{ .PIDFile }}{{ else }}/run/{{ .UnitName }}.pid{{ end }}
ExecReload=/bin/kill -HUP $MAINPID
PIDFile=/run/{{ .UnitName }}.pid
PIDFile={{ if .PIDFile }}{{ .PIDFile }}{{ else }}/run/{{ .UnitName }}.pid{{ end }}
LimitNOFILE=524288

[Install]
Expand Down
2 changes: 2 additions & 0 deletions lib/tbot/config/systemd/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ type TemplateParams struct {
TBotPath string
// DiagSocketForUpdater is the path to the diag socket for the updater.
DiagSocketForUpdater string
// PIDFile is the path to the PID file.
PIDFile string
}
4 changes: 4 additions & 0 deletions tool/tbot/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func setupInstallSystemdCmd(rootCmd *kingpin.Application) (
write := installSystemdCmd.Flag("write", "Write the systemd unit file. If not specified, this command runs in a dry-run mode that outputs the generated content to stdout.").Bool()
systemdDirectory := installSystemdCmd.Flag("systemd-directory", "Path to the directory that the systemd unit file should be written. Defaults to '/etc/systemd/system'.").Default("/etc/systemd/system").String()
anonymousTelemetry := installSystemdCmd.Flag("anonymous-telemetry", "Enable anonymous telemetry.").Bool()
pidFile := installSystemdCmd.Flag("pid-file", "Overrides the PID file path that should be set in the systemd unit files.").String()

f := onInstallSystemdCmdFunc(func(
ctx context.Context,
Expand All @@ -76,6 +77,7 @@ func setupInstallSystemdCmd(rootCmd *kingpin.Application) (
configPath,
getExecutablePath,
stdout,
*pidFile,
)
})

Expand All @@ -95,6 +97,7 @@ func onInstallSystemdCmd(
configPath string,
getExecutablePath func() (string, error),
stdout io.Writer,
pidFile string,
) error {
switch {
case configPath == "":
Expand Down Expand Up @@ -123,6 +126,7 @@ func onInstallSystemdCmd(
AnonymousTelemetry: anonymousTelemetry,
ConfigPath: configPath,
TBotPath: tbotPath,
PIDFile: pidFile,
})
if err != nil {
return trace.Wrap(err)
Expand Down
16 changes: 16 additions & 0 deletions tool/tbot/systemd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ func TestInstallSystemdCmd(t *testing.T) {
},
wantUnitName: "my-farm-bot",
},
{
name: "success - override only pid file",
params: []string{
"--write",
"--pid-file", "/tmp/tbot-fake.pid",
},
},
{
name: "success - override pid and unit name",
params: []string{
"--write",
"--pid-file", "/tmp/tbot-fake.pid",
"--name", "my-special-bot",
},
wantUnitName: "my-special-bot",
},
{
name: "fails prexisting",
params: []string{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by `tbot`
[Unit]
Description=tbot - Teleport Machine & Workload Identity Service
After=network.target

[Service]
Type=simple
User=teleport
Group=teleport
Restart=always
RestartSec=5
Environment="TELEPORT_ANONYMOUS_TELEMETRY=0"
ExecStart=/usr/local/bin/tbot start -c /etc/tbot.yaml --pid-file=/tmp/tbot-fake.pid
ExecReload=/bin/kill -HUP $MAINPID
PIDFile=/tmp/tbot-fake.pid
LimitNOFILE=524288

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by `tbot`
[Unit]
Description=my-special-bot - Teleport Machine & Workload Identity Service
After=network.target

[Service]
Type=simple
User=teleport
Group=teleport
Restart=always
RestartSec=5
Environment="TELEPORT_ANONYMOUS_TELEMETRY=0"
ExecStart=/usr/local/bin/tbot start -c /etc/tbot.yaml --pid-file=/tmp/tbot-fake.pid
ExecReload=/bin/kill -HUP $MAINPID
PIDFile=/tmp/tbot-fake.pid
LimitNOFILE=524288

[Install]
WantedBy=multi-user.target
Loading