| 195 | } |
| 196 | |
| 197 | func (ep *EtcdServerProcess) Stop() (err error) { |
| 198 | if ep == nil || ep.proc == nil { |
| 199 | return nil |
| 200 | } |
| 201 | |
| 202 | ep.cfg.lg.Info("stopping server...", zap.String("name", ep.cfg.Name)) |
| 203 | |
| 204 | defer func() { |
| 205 | ep.proc = nil |
| 206 | }() |
| 207 | |
| 208 | err = ep.proc.Stop() |
| 209 | if err != nil { |
| 210 | return err |
| 211 | } |
| 212 | err = ep.proc.Close() |
| 213 | if err != nil && !strings.Contains(err.Error(), "unexpected exit code") { |
| 214 | return err |
| 215 | } |
| 216 | <-ep.donec |
| 217 | ep.donec = make(chan struct{}) |
| 218 | if ep.cfg.PeerURL.Scheme == "unix" || ep.cfg.PeerURL.Scheme == "unixs" { |
| 219 | err = os.Remove(ep.cfg.PeerURL.Host + ep.cfg.PeerURL.Path) |
| 220 | if err != nil && !os.IsNotExist(err) { |
| 221 | return err |
| 222 | } |
| 223 | } |
| 224 | ep.cfg.lg.Info("stopped server.", zap.String("name", ep.cfg.Name)) |
| 225 | if ep.proxy != nil { |
| 226 | ep.cfg.lg.Info("stopping proxy...", zap.String("name", ep.cfg.Name)) |
| 227 | err = ep.proxy.Close() |
| 228 | ep.proxy = nil |
| 229 | if err != nil { |
| 230 | return err |
| 231 | } |
| 232 | } |
| 233 | if ep.lazyfs != nil { |
| 234 | ep.cfg.lg.Info("stopping lazyfs...", zap.String("name", ep.cfg.Name)) |
| 235 | err = ep.lazyfs.Stop() |
| 236 | ep.lazyfs = nil |
| 237 | if err != nil { |
| 238 | return err |
| 239 | } |
| 240 | } |
| 241 | return nil |
| 242 | } |
| 243 | |
| 244 | func (ep *EtcdServerProcess) Close() error { |
| 245 | ep.cfg.lg.Info("closing server...", zap.String("name", ep.cfg.Name)) |