feat: reload when config apply
This commit is contained in:
@ -93,6 +93,7 @@ func newConfigCmd() *cobra.Command {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
m.CoreConfig.Apply()
|
m.CoreConfig.Apply()
|
||||||
|
m.Core.ReloadService()
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -155,7 +155,6 @@ func newServiceRestartCmd() *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newServiceReloadCmd() *cobra.Command {
|
func newServiceReloadCmd() *cobra.Command {
|
||||||
var name string
|
|
||||||
c := &cobra.Command{
|
c := &cobra.Command{
|
||||||
Use: "reload",
|
Use: "reload",
|
||||||
Short: "Reload mihomo service configuration (via API)",
|
Short: "Reload mihomo service configuration (via API)",
|
||||||
@ -165,13 +164,12 @@ func newServiceReloadCmd() *cobra.Command {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !m.Core.ReloadService(name) {
|
if !m.Core.ReloadService() {
|
||||||
return errSilentFailure
|
return errSilentFailure
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
withNameFlag(c, &name)
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -57,7 +57,7 @@ func newSubscriptionRefreshCmd() *cobra.Command {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
m.Subscription.RefreshSubscription(args[0], backup)
|
m.Subscription.RefreshSubscription(args[0], backup)
|
||||||
m.Core.ReloadService("mihomo")
|
m.Core.ReloadService()
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -141,7 +141,7 @@ func newSubscriptionActivateCmd() *cobra.Command {
|
|||||||
}
|
}
|
||||||
m.Subscription.ActivateSubscription(args[0])
|
m.Subscription.ActivateSubscription(args[0])
|
||||||
if m.CoreConfig.Apply() {
|
if m.CoreConfig.Apply() {
|
||||||
m.Core.ReloadService("mihomo")
|
m.Core.ReloadService()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
@ -160,7 +160,7 @@ func newSubscriptionDeactivateCmd() *cobra.Command {
|
|||||||
}
|
}
|
||||||
m.Subscription.DeactivateSubscription(args[0])
|
m.Subscription.DeactivateSubscription(args[0])
|
||||||
if m.CoreConfig.Apply() {
|
if m.CoreConfig.Apply() {
|
||||||
m.Core.ReloadService("mihomo")
|
m.Core.ReloadService()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|||||||
@ -383,7 +383,7 @@ func (m *Manager) GetServiceStatus(serviceName string) string {
|
|||||||
|
|
||||||
// ReloadService reloads mihomo configuration via its external-controller API
|
// ReloadService reloads mihomo configuration via its external-controller API
|
||||||
// without restarting the service.
|
// without restarting the service.
|
||||||
func (m *Manager) ReloadService(serviceName string) bool {
|
func (m *Manager) ReloadService() bool {
|
||||||
configPath := filepath.Join(m.CoreConfigManager.Storage.ConfigDir, "generated_config.yaml")
|
configPath := filepath.Join(m.CoreConfigManager.Storage.ConfigDir, "generated_config.yaml")
|
||||||
if _, err := os.Stat(configPath); err != nil {
|
if _, err := os.Stat(configPath); err != nil {
|
||||||
fmt.Printf("❌ Configuration file not found: %s\n", configPath)
|
fmt.Printf("❌ Configuration file not found: %s\n", configPath)
|
||||||
|
|||||||
Reference in New Issue
Block a user