mirror of
https://github.com/tailscale/tailscale.git
synced 2025-03-14 01:11:01 +00:00
ipn: temporary support for loading legacy relaynode configs.
Signed-off-by: David Anderson <dave@natulte.net>
This commit is contained in:
parent
4ebc0fa70f
commit
0c55777fed
@ -80,6 +80,7 @@ func main() {
|
||||
SocketPath: *socketpath,
|
||||
StatePath: *statepath,
|
||||
AutostartStateKey: globalStateKey,
|
||||
LegacyConfigPath: "/var/lib/tailscale/relay.conf",
|
||||
SurviveDisconnects: true,
|
||||
}
|
||||
err = ipnserver.Run(context.Background(), logf, pol.PublicID.String(), opts, e)
|
||||
|
@ -82,6 +82,14 @@ type Options struct {
|
||||
// an initial overwrite of backend state with Prefs.
|
||||
StateKey StateKey
|
||||
Prefs *Prefs
|
||||
// LegacyConfigPath optionally specifies the old-style relaynode
|
||||
// relay.conf location. If both LegacyConfigPath and StateKey are
|
||||
// specified and the requested state doesn't exist in the backend
|
||||
// store, the backend migrates the config from LegacyConfigPath.
|
||||
//
|
||||
// TODO(danderson): remove some time after the transition to
|
||||
// tailscaled is done.
|
||||
LegacyConfigPath string
|
||||
// Notify is called when backend events happen.
|
||||
Notify func(Notify) `json:"-"`
|
||||
}
|
||||
|
@ -43,6 +43,15 @@ type Options struct {
|
||||
// using the given StateKey. If empty, the agent stays idle and
|
||||
// waits for a frontend to start it.
|
||||
AutostartStateKey ipn.StateKey
|
||||
// LegacyConfigPath optionally specifies the old-style relaynode
|
||||
// relay.conf location. If both LegacyConfigPath and
|
||||
// AutostartStateKey are specified and the requested state doesn't
|
||||
// exist in the backend store, the backend migrates the config
|
||||
// from LegacyConfigPath.
|
||||
//
|
||||
// TODO(danderson): remove some time after the transition to
|
||||
// tailscaled is done.
|
||||
LegacyConfigPath string
|
||||
// SurviveDisconnects specifies how the server reacts to its
|
||||
// frontend disconnecting. If true, the server keeps running on
|
||||
// its existing state, and accepts new frontend connections. If
|
||||
@ -114,7 +123,8 @@ func Run(rctx context.Context, logf logger.Logf, logid string, opts Options, e w
|
||||
Version: version.LONG,
|
||||
Start: &ipn.StartArgs{
|
||||
Opts: ipn.Options{
|
||||
StateKey: opts.AutostartStateKey,
|
||||
StateKey: opts.AutostartStateKey,
|
||||
LegacyConfigPath: opts.LegacyConfigPath,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
13
ipn/local.go
13
ipn/local.go
@ -150,7 +150,7 @@ func (b *LocalBackend) Start(opts Options) error {
|
||||
b.hiCache = hi
|
||||
b.state = NoState
|
||||
|
||||
if err := b.loadStateWithLock(opts.StateKey, opts.Prefs); err != nil {
|
||||
if err := b.loadStateWithLock(opts.StateKey, opts.Prefs, opts.LegacyConfigPath); err != nil {
|
||||
b.mu.Unlock()
|
||||
return fmt.Errorf("loading requested state: %v", err)
|
||||
}
|
||||
@ -360,7 +360,7 @@ func (b *LocalBackend) popBrowserAuthNow() {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *LocalBackend) loadStateWithLock(key StateKey, prefs *Prefs) error {
|
||||
func (b *LocalBackend) loadStateWithLock(key StateKey, prefs *Prefs, legacyPath string) error {
|
||||
if prefs == nil && key == "" {
|
||||
panic("state key and prefs are both unset")
|
||||
}
|
||||
@ -386,9 +386,14 @@ func (b *LocalBackend) loadStateWithLock(key StateKey, prefs *Prefs) error {
|
||||
bs, err := b.store.ReadState(key)
|
||||
if err != nil {
|
||||
if err == ErrStateNotExist {
|
||||
b.prefs = NewPrefs()
|
||||
if legacyPath != "" {
|
||||
b.prefs = *LoadPrefs(legacyPath, true)
|
||||
b.logf("Imported state from relaynode for %q", key)
|
||||
} else {
|
||||
b.prefs = NewPrefs()
|
||||
b.logf("Created empty state for %q", key)
|
||||
}
|
||||
b.stateKey = key
|
||||
b.logf("Created empty state for %q", key)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("store.ReadState(%q): %v", key, err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user