1
0
mirror of https://github.com/rancher/os.git synced 2025-07-12 22:27:59 +00:00

Keep the sshd config file when using the previous console version

This commit is contained in:
niusmallnan 2019-04-30 11:03:17 +08:00 committed by niusmallnan
parent 19cf9b28bc
commit 4546fac3c2

View File

@ -31,6 +31,8 @@ const (
rancherHome = "/home/rancher" rancherHome = "/home/rancher"
startScript = "/opt/rancher/bin/start.sh" startScript = "/opt/rancher/bin/start.sh"
runLockDir = "/run/lock" runLockDir = "/run/lock"
sshdFile = "/etc/ssh/sshd_config"
sshdTplFile = "/etc/ssh/sshd_config.tpl"
) )
type symlink struct { type symlink struct {
@ -322,12 +324,14 @@ func writeRespawn(user string, sshd, recovery bool) error {
} }
func modifySshdConfig(cfg *config.CloudConfig) error { func modifySshdConfig(cfg *config.CloudConfig) error {
os.Remove("/etc/ssh/sshd_config") _, err := os.Stat(sshdTplFile)
sshdTpl, err := template.ParseFiles("/etc/ssh/sshd_config.tpl") if err == nil {
os.Remove(sshdFile)
sshdTpl, err := template.ParseFiles(sshdTplFile)
if err != nil { if err != nil {
return err return err
} }
f, err := os.OpenFile("/etc/ssh/sshd_config", os.O_WRONLY|os.O_CREATE, 0644) f, err := os.OpenFile(sshdFile, os.O_WRONLY|os.O_CREATE, 0644)
if err != nil { if err != nil {
return err return err
} }
@ -342,6 +346,11 @@ func modifySshdConfig(cfg *config.CloudConfig) error {
} }
return sshdTpl.Execute(f, config) return sshdTpl.Execute(f, config)
} else if os.IsNotExist(err) {
return nil
}
return err
} }
func setupSSH(cfg *config.CloudConfig) error { func setupSSH(cfg *config.CloudConfig) error {