Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aerth/spawn
Spawn like a salmon - Simple go package to respawn the current process
https://github.com/aerth/spawn
Last synced: 3 months ago
JSON representation
Spawn like a salmon - Simple go package to respawn the current process
- Host: GitHub
- URL: https://github.com/aerth/spawn
- Owner: aerth
- License: mit
- Created: 2016-10-22T00:18:10.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2020-12-28T06:27:12.000Z (almost 4 years ago)
- Last Synced: 2024-06-28T20:54:55.890Z (4 months ago)
- Language: Go
- Homepage: https://godoc.org/github.com/aerth/spawn
- Size: 18.6 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# spawn
### like a salmon
spawn the current process
[![Build Status](https://travis-ci.org/aerth/spawn.svg?branch=master)](https://travis-ci.org/aerth/spawn)
as seen in:
* server daemons
* http servers
* chat bots
* long running processes of all kinds"use *anywhere*!"
* go routines
* main function
* "click to run the program"
* hook it up to your `signal.Notify()` ?### Important notes
* this library sets the environmental variable SPAWNED=N where N is the number of levels into this we are
* this means if `$SPAWNED` is empty, we know its safe to spawn another process and exit (not an infinite loop).
* the arguments, environment are carried over to the new process, so consider setting those before calling spawn.Spawn()
* if your database (or something) is locked you may want to wait until after spawn check to lock the db
### Usage```
import "github.com/aerth/spawn"
if os.Getenv(spawn.SPAWNED) == "" {
err := spawn.Spawn()
if err == nil {
os.Exit(0)
}
}
```