mirror of
https://github.com/tailscale/tailscale.git
synced 2025-06-18 14:18:41 +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,
|
SocketPath: *socketpath,
|
||||||
StatePath: *statepath,
|
StatePath: *statepath,
|
||||||
AutostartStateKey: globalStateKey,
|
AutostartStateKey: globalStateKey,
|
||||||
|
LegacyConfigPath: "/var/lib/tailscale/relay.conf",
|
||||||
SurviveDisconnects: true,
|
SurviveDisconnects: true,
|
||||||
}
|
}
|
||||||
err = ipnserver.Run(context.Background(), logf, pol.PublicID.String(), opts, e)
|
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.
|
// an initial overwrite of backend state with Prefs.
|
||||||
StateKey StateKey
|
StateKey StateKey
|
||||||
Prefs *Prefs
|
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 is called when backend events happen.
|
||||||
Notify func(Notify) `json:"-"`
|
Notify func(Notify) `json:"-"`
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,15 @@ type Options struct {
|
|||||||
// using the given StateKey. If empty, the agent stays idle and
|
// using the given StateKey. If empty, the agent stays idle and
|
||||||
// waits for a frontend to start it.
|
// waits for a frontend to start it.
|
||||||
AutostartStateKey ipn.StateKey
|
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
|
// SurviveDisconnects specifies how the server reacts to its
|
||||||
// frontend disconnecting. If true, the server keeps running on
|
// frontend disconnecting. If true, the server keeps running on
|
||||||
// its existing state, and accepts new frontend connections. If
|
// its existing state, and accepts new frontend connections. If
|
||||||
@ -115,6 +124,7 @@ func Run(rctx context.Context, logf logger.Logf, logid string, opts Options, e w
|
|||||||
Start: &ipn.StartArgs{
|
Start: &ipn.StartArgs{
|
||||||
Opts: ipn.Options{
|
Opts: ipn.Options{
|
||||||
StateKey: opts.AutostartStateKey,
|
StateKey: opts.AutostartStateKey,
|
||||||
|
LegacyConfigPath: opts.LegacyConfigPath,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
11
ipn/local.go
11
ipn/local.go
@ -150,7 +150,7 @@ func (b *LocalBackend) Start(opts Options) error {
|
|||||||
b.hiCache = hi
|
b.hiCache = hi
|
||||||
b.state = NoState
|
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()
|
b.mu.Unlock()
|
||||||
return fmt.Errorf("loading requested state: %v", err)
|
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 == "" {
|
if prefs == nil && key == "" {
|
||||||
panic("state key and prefs are both unset")
|
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)
|
bs, err := b.store.ReadState(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == ErrStateNotExist {
|
if err == ErrStateNotExist {
|
||||||
|
if legacyPath != "" {
|
||||||
|
b.prefs = *LoadPrefs(legacyPath, true)
|
||||||
|
b.logf("Imported state from relaynode for %q", key)
|
||||||
|
} else {
|
||||||
b.prefs = NewPrefs()
|
b.prefs = NewPrefs()
|
||||||
b.stateKey = key
|
|
||||||
b.logf("Created empty state for %q", key)
|
b.logf("Created empty state for %q", key)
|
||||||
|
}
|
||||||
|
b.stateKey = key
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return fmt.Errorf("store.ReadState(%q): %v", key, err)
|
return fmt.Errorf("store.ReadState(%q): %v", key, err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user