Restart kill the running process and reruns the command with the updated cmd and args.
(ctx context.Context, cmd string, args ...string)
| 82 | // Restart kill the running process and reruns the command with the updated |
| 83 | // cmd and args. |
| 84 | func (d *Process) Restart(ctx context.Context, cmd string, args ...string) error { |
| 85 | d.mu.Lock() |
| 86 | defer d.mu.Unlock() |
| 87 | |
| 88 | err := d.kill(syscall.SIGTERM) |
| 89 | if err != nil { |
| 90 | return xerrors.Errorf("kill cmd: %w", err) |
| 91 | } |
| 92 | |
| 93 | ctx, cancel := context.WithCancel(ctx) |
| 94 | d.ctx = ctx |
| 95 | d.cancel = cancel |
| 96 | d.cmd = xunix.GetExecer(ctx).CommandContext(ctx, cmd, args...) |
| 97 | d.waitCh = make(chan error, 1) |
| 98 | d.userKilled = i64ptr(0) |
| 99 | d.binName = cmd |
| 100 | |
| 101 | return d.startProcess() |
| 102 | } |
| 103 | |
| 104 | func (d *Process) startProcess() error { |
| 105 | var ( |
no test coverage detected