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