Skip to content

Commit 398cc8b

Browse files
committed
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.
1 parent e1a9e98 commit 398cc8b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

cmd/cloudflared/windows_service.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,14 @@ func installWindowsService(c *cli.Context) error {
212212
s.Delete()
213213
return errors.Wrap(err, "Cannot install event logger")
214214
}
215+
215216
err = configRecoveryOption(s.Handle)
216217
if err != nil {
217218
log.Err(err).Msg("Cannot set service recovery actions")
218219
log.Info().Msgf("See %s to manually configure service recovery actions", windowsServiceUrl)
219220
}
220-
return nil
221+
222+
return s.Start()
221223
}
222224

223225
func uninstallWindowsService(c *cli.Context) error {
@@ -236,6 +238,14 @@ func uninstallWindowsService(c *cli.Context) error {
236238
return fmt.Errorf("Service %s is not installed", windowsServiceName)
237239
}
238240
defer s.Close()
241+
242+
if status, err := s.Query(); err == nil && status.State == svc.Running {
243+
log.Info().Msg("Stopping Cloudflare Tunnel agent service")
244+
if _, err := s.Control(svc.Stop); err != nil {
245+
log.Info().Err(err).Msg("Failed to stop Cloudflare Tunnel agent service, you may need to stop it manually to complete uninstall.")
246+
}
247+
}
248+
239249
err = s.Delete()
240250
if err != nil {
241251
return errors.Wrap(err, "Cannot delete service")

0 commit comments

Comments
 (0)