TUN-5893: Start windows service on install, stop on uninstall. Previously user had to manually start the service after running 'cloudflared tunnel install' and stop the service before running uninstall command.
This commit is contained in:
parent
e1a9e98cca
commit
398cc8b134
|
@ -212,12 +212,14 @@ func installWindowsService(c *cli.Context) error {
|
||||||
s.Delete()
|
s.Delete()
|
||||||
return errors.Wrap(err, "Cannot install event logger")
|
return errors.Wrap(err, "Cannot install event logger")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = configRecoveryOption(s.Handle)
|
err = configRecoveryOption(s.Handle)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Err(err).Msg("Cannot set service recovery actions")
|
log.Err(err).Msg("Cannot set service recovery actions")
|
||||||
log.Info().Msgf("See %s to manually configure service recovery actions", windowsServiceUrl)
|
log.Info().Msgf("See %s to manually configure service recovery actions", windowsServiceUrl)
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
|
return s.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
func uninstallWindowsService(c *cli.Context) error {
|
func uninstallWindowsService(c *cli.Context) error {
|
||||||
|
@ -236,6 +238,14 @@ func uninstallWindowsService(c *cli.Context) error {
|
||||||
return fmt.Errorf("Service %s is not installed", windowsServiceName)
|
return fmt.Errorf("Service %s is not installed", windowsServiceName)
|
||||||
}
|
}
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
|
||||||
|
if status, err := s.Query(); err == nil && status.State == svc.Running {
|
||||||
|
log.Info().Msg("Stopping Cloudflare Tunnel agent service")
|
||||||
|
if _, err := s.Control(svc.Stop); err != nil {
|
||||||
|
log.Info().Err(err).Msg("Failed to stop Cloudflare Tunnel agent service, you may need to stop it manually to complete uninstall.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err = s.Delete()
|
err = s.Delete()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Cannot delete service")
|
return errors.Wrap(err, "Cannot delete service")
|
||||||
|
|
Loading…
Reference in New Issue