상세 컨텐츠

본문 제목

[Node.js]서버 실행 모듈 - forever

WEB & Mobile

by mobile 2015. 5. 8. 15:24

본문

반응형

■ forever

기존의 멀티스레드 기반의 웹 서비스는 예외가 발생해도 전체 웹 서비스에 크게 영향을 주지 않습니다.

Node.js 같은 단일 스레드 기반의 웹서비시는 예외 하나로 웹서비스가 죽어 버립니다. 이러한 예외상황을 대비하는 모듈이 forever 모듈 입니다.


- 사이트

https://github.com/foreverjs/forever


-npm을 통한 설치

npm install -g forever


- 설명

You can use forever to run scripts continuously (whether it is written in node.js or not).


Example


forever start app.js

Options


  $ forever --help

  usage: forever [action] [options] SCRIPT [script-options]


  Monitors the script specified in the current process or as a daemon


  actions:

    start               Start SCRIPT as a daemon

    stop                Stop the daemon SCRIPT by Id|Uid|Pid|Index|Script

    stopall             Stop all running forever scripts

    restart             Restart the daemon SCRIPT

    restartall          Restart all running forever scripts

    list                List all running forever scripts

    config              Lists all forever user configuration

    set <key> <val>     Sets the specified forever config <key>

    clear <key>         Clears the specified forever config <key>

    logs                Lists log files for all forever processes

    logs <script|index> Tails the logs for <script|index>

    columns add <col>   Adds the specified column to the output in `forever list`

    columns rm <col>    Removed the specified column from the output in `forever list`

    columns set <cols>  Set all columns for the output in `forever list`

    cleanlogs           [CAREFUL] Deletes all historical forever log files


  options:

    -m  MAX          Only run the specified script MAX times

    -l  LOGFILE      Logs the forever output to LOGFILE

    -o  OUTFILE      Logs stdout from child script to OUTFILE

    -e  ERRFILE      Logs stderr from child script to ERRFILE

    -p  PATH         Base path for all forever related files (pid files, etc.)

    -c  COMMAND      COMMAND to execute (defaults to node)

    -a, --append     Append logs

    -f, --fifo       Stream logs to stdout

    -n, --number     Number of log lines to print

    --pidFile        The pid file

    --uid            Process uid, useful as a namespace for processes (must wrap in a string)

                     e.g. forever start --uid "production" app.js

                         forever stop production

    --sourceDir      The source directory for which SCRIPT is relative to

    --workingDir     The working directory in which SCRIPT will execute

    --minUptime      Minimum uptime (millis) for a script to not be considered "spinning"

    --spinSleepTime  Time to wait (millis) between launches of a spinning script.

    --colors         --no-colors will disable output coloring

    --plain          Disable command line colors

    -d, --debug      Forces forever to log debug output

    -v, --verbose    Turns on the verbose messages from Forever

    -s, --silent     Run the child script silencing stdout and stderr

    -w, --watch      Watch for file changes

    --watchDirectory Top-level directory to watch from

    --watchIgnore    To ignore pattern when watch is enabled (multiple option is allowed)

    --killSignal     Support exit signal customization (default is SIGKILL),

                     used for restarting script gracefully e.g. --killSignal=SIGTERM

    -h, --help       You're staring at it


  [Long Running Process]

    The forever process will continue to run outputting log messages to the console.

    ex. forever -o out.log -e err.log my-script.js


  [Daemon]

    The forever process will run as a daemon which will make the target process start

    in the background. This is extremely useful for remote starting simple node.js scripts

    without using nohup. It is recommended to run start with -o -l, & -e.

    ex. forever start -l forever.log -o out.log -e err.log my-daemon.js

        forever stop my-daemon.js

There are several examples designed to test the fault tolerance of forever. Here's a simple usage example:


  $ forever -m 5 examples/error-on-timer.js




반응형

관련글 더보기

댓글 영역