10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

node.js(express)をforeverでdaemon化

Last updated at Posted at 2015-10-20
Amazon linux2015.03上で行いました。

目的

expressをdaemonとして動かす。

設定

foreverのインストール

npm install -g forever

起動スクリプトを書く。

/etc/init.d/foreverへ下記を追加して実行権限をつける。

#!/bin/bash
# chkconfig: 2345 75 25
# description: forever stop:stop Script

# export NODE_ENV=
# export NODE_CONFIG_DIR= #お好みで
# harmonyで動かしています。
start() {
    echo -n "Starting forever: "
    /usr/node/bin/forever start --workingDir=/path/to -c "node --harmony" -a --uid hogehoge /path/to/bin/www
    return 0
}
stop() {
    /usr/node/bin/forever stop hogehoge
    return 0
}
case "$1" in
  start)
    stop
    start
    ;;
  restart)
    stop
    start
    ;;
  stop)
    stop
    ;;
   *)
    echo $"Usage: $0 {start|stop|restart}"
    exit 2

esac

OS起動時に動くよう設定する

chkconfig forever on
10
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?