package module
Version: v0.0.0-...-22c3f5b Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2022 License: ISC Imports: 14 Imported by: 3




Go library to restart (via exec) a program when a new version is written to disk.

Basic usage

To restart daemons in conjunction with autoinstall, call RestartOnChange during initialization, e.g.:

import ""
func main() {
    go autorestart.RestartOnChange()

This restarts the daemon by calling syscall.Exec, which is not portable and is unsupported on Windows. Exec replaces the current process with the new one, maintaining the same PID as before and such. This a super-convenient way to restart processes, but it can be a bit different than what you might expect when being restarted by a parent process; you might want to read about it a little first: wikipedia

Specifically, if your daemon accumulates zombie subprocesses over restarts, the CleanUpChildZombies function might help.

See documentation for additional details.




This section is empty.


This section is empty.


func CleanUpChildZombies

func CleanUpChildZombies()

This is a utility function to clean up zombie subprocesses that can get left behind by RestartOnChange, due to the fashion in which it restarts the process. This will synchronously execute `pgrep` to get a list of child process IDs, and then asychronously call syscall.Wait4 on each one to remove zombies. In addition, if those processes are not yet terminated, this calls SIGHUP, SIGINT, and finally SIGTERM over the course of a few minutes in order to encourage them to die.

func CleanUpChildZombiesQuietly

func CleanUpChildZombiesQuietly()

This is identical to CleanUpChildZombies except that it outputs nothing to stderr.

func NotifyOnChange

func NotifyOnChange(usePolling bool) chan bool

Subscribe to a notification when the current process' executable file is modified. Returns a channel to which notifications (just `true`) will be sent whenever a change is detected.

func NotifyOnSighup

func NotifyOnSighup() chan os.Signal

func NotifyOnSigterm

func NotifyOnSigterm() chan os.Signal

func RestartOnChange

func RestartOnChange()

Restart the current program when the program's executable is updated. This function is a wrapper around NotifyOnChange and RestartViaExec, calling the latter when the former signals that a change was detected.

func RestartViaExec

func RestartViaExec()

Restart the current process by calling syscall.Exec, using os.Args (with filepath.LookPath) and os.Environ() to recreate the same args & environment that was used when the process was originally started. Due to using syscall.Exec, this function is not portable to systems that don't support exec.


This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL