From 9d7106f7d671ad11e089751871c5e800242ec13f Mon Sep 17 00:00:00 2001 From: Gus Luxton Date: Mon, 14 Aug 2023 16:09:11 -0300 Subject: [PATCH] systemd: Specify default config file path in unit file (#30442) * systemd: Specify default config file path in unit file Fixes #30306 * Also update 'teleport install systemd' * Format file with gci --- examples/systemd/fips/teleport.service | 4 ++-- examples/systemd/teleport.service | 2 +- lib/config/systemd.go | 8 +++++++- lib/config/testdata/TestWriteSystemdUnitFile.golden | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/examples/systemd/fips/teleport.service b/examples/systemd/fips/teleport.service index c366a249ed4d1..ad30a0a4d424e 100644 --- a/examples/systemd/fips/teleport.service +++ b/examples/systemd/fips/teleport.service @@ -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 diff --git a/examples/systemd/teleport.service b/examples/systemd/teleport.service index b969f818b5c5a..3a84fa0329119 100644 --- a/examples/systemd/teleport.service +++ b/examples/systemd/teleport.service @@ -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 diff --git a/lib/config/systemd.go b/lib/config/systemd.go index 7fc15080e9f69..b0f3c5b12d091 100644 --- a/lib/config/systemd.go +++ b/lib/config/systemd.go @@ -20,6 +20,8 @@ import ( "text/template" "github.com/gravitational/trace" + + "github.com/gravitational/teleport/lib/defaults" ) const ( @@ -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 }} @@ -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. @@ -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 } diff --git a/lib/config/testdata/TestWriteSystemdUnitFile.golden b/lib/config/testdata/TestWriteSystemdUnitFile.golden index 7158564712cdc..bfd0987b65225 100644 --- a/lib/config/testdata/TestWriteSystemdUnitFile.golden +++ b/lib/config/testdata/TestWriteSystemdUnitFile.golden @@ -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