项目作者: immortal

项目描述 :
⭕ A *nix cross-platform (OS agnostic) supervisor
高级语言: Go
项目地址: git://github.com/immortal/immortal.git
创建时间: 2016-06-30T17:02:27Z
项目社区:https://github.com/immortal/immortal

开源协议:BSD 3-Clause "New" or "Revised" License

下载


⭕ immortal

CircleCI
Build Status
Coverage Status
codecov
Go Report Card

A *nix cross-platform (OS agnostic) supervisor

https://immortal.run/

GitHub release
GoDoc
contributions welcome

Linux precompiled binaries

deb
rpm

run on behalf other system user

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:

  1. 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.

Compile from source

Setup go environment https://golang.org/doc/install

go >= 1.12 is required

For example using $HOME/go for your workspace

  1. $ export GOPATH=$HOME/go

Create the directory:

  1. $ mkdir -p $HOME/go/src/github.com/immortal

Clone project into that directory:

  1. $ git clone git@github.com:immortal/immortal.git $HOME/go/src/github.com/immortal/immortal

Build by just typing make:

  1. $ cd $HOME/go/src/github.com/immortal/immortal
  2. $ make

To install/uninstall:

  1. $ make install
  2. $ make uninstall

configuration example

Content of file /usr/local/etc/immortal/www.yml:

  1. # pkg install go-www
  2. cmd: www
  3. cwd: /usr/ports
  4. log:
  5. file: /var/log/www.log
  6. age: 10 # seconds
  7. num: 7 # int
  8. size: 1 # MegaBytes
  9. wait: 1
  10. require:
  11. - foo
  12. - bar

If foo and bar are not running, the service www will not be started. Skip age, num & size options to avoid log-rotation completely.

foo and bar are the names for the services defined on the same path www.yaml is located, foo.yml & bar.yml

Paths

When using immortaldir:

  1. /usr/local/etc/immortal
  2. |--foo.yml
  3. |--bar.yml
  4. `--www.yml

The name of the file.yml will be used to reference the service to be
daemonized excluding the extension .yml.:

  1. foo
  2. bar
  3. www

/var/run/immortal/

  1. /var/run/immortal
  2. |--foo
  3. | |-lock
  4. | `-immortal.sock
  5. |--bar
  6. | |-lock
  7. | `-immortal.sock
  8. `--www
  9. |-lock
  10. `-immortal.sock

immortal like non-root user

Any service launched like not using using immortaldir will follow this
structure:

  1. ~/.immortal
  2. |--(pid)
  3. | |--lock
  4. | `--immortal.sock
  5. |--(pid)
  6. | |--lock
  7. | `--immortal.sock
  8. `--(pid)
  9. |--lock
  10. `--immortal.sock

The -name argument takes a non-path (e.g., “myservice”), and the argument will be used instead of the pid in the directory structure. For example, immortal -ctl myservice sleep 1000 will be:

  1. ~/.immortal
  2. |--myservice
  3. | |--lock
  4. | `--immortal.sock

The -ctl argument takes precedence over the -name argument.

immortalctl

Will print current status and allow to manage the services

debug

  1. pgrep -fl "immortal -ctl" | awk '{print $1}' | xargs watch -n .1 pstree -p

Test status using curl & jq

status:

  1. curl --unix-socket immortal.sock http:/status -s | jq

note the single ‘/‘ https://superuser.com/a/925610/284722

down:

  1. curl --unix-socket immortal.sock http://im/signal/d -s | jq

up:

  1. curl --unix-socket immortal.sock http://im/signal/u -s | jq