Skip to content

Commit

Permalink
systemd: Specify default config file path in unit file (gravitational…
Browse files Browse the repository at this point in the history
…#30442)

* systemd: Specify default config file path in unit file

Fixes gravitational#30306

* Also update 'teleport install systemd'

* Format file with gci
  • Loading branch information
webvictim authored Aug 14, 2023
1 parent e572328 commit 9d7106f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions examples/systemd/fips/teleport.service
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[Unit]
Description=Teleport Service FIPS
Description=Teleport Service FIPS
After=network.target

[Service]
Type=simple
Restart=on-failure
EnvironmentFile=-/etc/default/teleport
ExecStart=/usr/local/bin/teleport start --fips --pid-file=/run/teleport.pid
ExecStart=/usr/local/bin/teleport start --config /etc/teleport.yaml --fips --pid-file=/run/teleport.pid
ExecReload=/bin/kill -HUP $MAINPID
PIDFile=/run/teleport.pid
LimitNOFILE=524288
Expand Down
2 changes: 1 addition & 1 deletion examples/systemd/teleport.service
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ After=network.target
Type=simple
Restart=on-failure
EnvironmentFile=-/etc/default/teleport
ExecStart=/usr/local/bin/teleport start --pid-file=/run/teleport.pid
ExecStart=/usr/local/bin/teleport start --config /etc/teleport.yaml --pid-file=/run/teleport.pid
ExecReload=/bin/kill -HUP $MAINPID
PIDFile=/run/teleport.pid
LimitNOFILE=524288
Expand Down
8 changes: 7 additions & 1 deletion lib/config/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"text/template"

"github.com/gravitational/trace"

"github.com/gravitational/teleport/lib/defaults"
)

const (
Expand All @@ -40,7 +42,7 @@ After=network.target
Type=simple
Restart=on-failure
EnvironmentFile=-{{ .EnvironmentFile }}
ExecStart={{ .TeleportInstallationFile }} start --pid-file={{ .PIDFile }}
ExecStart={{ .TeleportInstallationFile }} start --config {{ .TeleportConfigPath }} --pid-file={{ .PIDFile }}
ExecReload=/bin/kill -HUP $MAINPID
PIDFile={{ .PIDFile }}
LimitNOFILE={{ .FileDescriptorLimit }}
Expand All @@ -58,6 +60,8 @@ type SystemdFlags struct {
FileDescriptorLimit int
// TeleportInstallationFile is the teleport installation path provided by the user.
TeleportInstallationFile string
// TeleportConfigPath is the path to the teleport config file (as set by Teleport defaults)
TeleportConfigPath string
}

// CheckAndSetDefaults checks and sets default values for the flags.
Expand All @@ -69,6 +73,8 @@ func (f *SystemdFlags) CheckAndSetDefaults() error {
}
f.TeleportInstallationFile = teleportPath
}
// set Teleport config path to the default
f.TeleportConfigPath = defaults.ConfigFilePath

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion lib/config/testdata/TestWriteSystemdUnitFile.golden
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ After=network.target
Type=simple
Restart=on-failure
EnvironmentFile=-/custom/env/dir/teleport
ExecStart=/custom/install/dir/teleport start --pid-file=/custom/pid/dir/teleport.pid
ExecStart=/custom/install/dir/teleport start --config /etc/teleport.yaml --pid-file=/custom/pid/dir/teleport.pid
ExecReload=/bin/kill -HUP $MAINPID
PIDFile=/custom/pid/dir/teleport.pid
LimitNOFILE=16384
Expand Down

0 comments on commit 9d7106f

Please sign in to comment.