How do I daemonize an arbitrary script in unix?

后端 未结 12 969
陌清茗
陌清茗 2020-11-30 16:33

I\'d like a daemonizer that can turn an arbitrary, generic script or command into a daemon.

There are two common cases I\'d like to deal with:

  1. I hav

12条回答
  •  星月不相逢
    2020-11-30 16:55

    You could give a try to immortal It is a *nix cross-platform (OS agnostic) supervisor.

    For a quick try on macOS:

    brew install immortal
    

    In case you are using FreeBSD from the ports or by using pkg:

    pkg install immortal
    

    For Linux by downloading the precompiled binaries or from source: https://immortal.run/source/

    You can either use it like this:

    immortal -l /var/log/date.log date
    

    Or by a configuration YAML file which gives you more options, for example:

    cmd: date
    log:
        file: /var/log/date.log
        age: 86400 # seconds
        num: 7     # int
        size: 1    # MegaBytes
        timestamp: true # will add timesamp to log
    

    If you would like to keep also the standard error output in a separate file you could use something like:

    cmd: date
    log:
        file: /var/log/date.log
        age: 86400 # seconds
        num: 7     # int
        size: 1    # MegaBytes
    stderr:
        file: /var/log/date-error.log
        age: 86400 # seconds
        num: 7     # int
        size: 1    # MegaBytes
        timestamp: true # will add timesamp to log
    

提交回复
热议问题