A *nix cross-platform (OS agnostic) supervisor
If services need to run on behalf other system user www, nobody, www-data
,
not root
, immortal should be compiled from source for the desired
target/architecture, otherwise, this error may be returned:
Error looking up user: "www". user: Lookup requires cgo
See more: https://golang.org/cmd/cgo/
If using FreeBSD or macOS you can install using pkg/ports or homebrew, for other platforms work is in progress, any help for making the port/package for other systems would be appreciated.
Setup go environment https://golang.org/doc/install
go >= 1.9 is required
For example using $HOME/go for your workspace
$ export GOPATH=$HOME/go
Create the directory:
$ mkdir -p $HOME/go/src/github.com/immortal
Clone project into that directory:
$ git clone git@github.com:immortal/immortal.git $HOME/go/src/github.com/immortal/immortal
Build by just typing make:
$ cd $HOME/go/src/github.com/immortal/immortal
$ make
To install/uninstall:
$ make install
$ make uninstall
Content of file /usr/local/etc/immortal/www.yml
:
# pkg install go-www
cmd: www
cwd: /usr/ports
log:
file: /var/log/www.log
age: 10 # seconds
num: 7 # int
size: 1 # MegaBytes
wait: 1
require:
- foo
- bar
If foo
and bar
are not running, the service www
will not be started.
foo
andbar
are the names for the services defined on the same path www.yaml is located, foo.yml & bar.yml
When using immortaldir:
/usr/local/etc/immortal
|--foo.yml
|--bar.yml
`--www.yml
The name of the file.yml
will be used to reference the service to be
daemonized excluding the extension .yml
.:
foo
bar
www
/var/run/immortal
|--foo
| |-lock
| `-immortal.sock
|--bar
| |-lock
| `-immortal.sock
`--www
|-lock
`-immortal.sock
Any service launched like not using using immortaldir
will follow this
structure:
~/.immortal
|--(pid)
| |--lock
| `--immortal.sock
|--(pid)
| |--lock
| `--immortal.sock
`--(pid)
|--lock
`--immortal.sock
Will print current status and allow to manage the services
pgrep -fl "immortal -ctl" | awk '{print $1}' | xargs watch -n .1 pstree -p
Test status using curl & jq
status:
curl --unix-socket immortal.sock http:/status -s | jq
note the single '/' https://superuser.com/a/925610/284722
down:
curl --unix-socket immortal.sock http://im/signal/d -s | jq
up:
curl --unix-socket immortal.sock http://im/signal/u -s | jq