domingo, 8 de maio de 2016

Instalando e configurando node.js e forever no CentOS

  1. Instalando
    • yum install nodejs npm
    • npm -g install forever
  2. Testando
    • crie o arquivo teste.js com os dados abaixo:
      • http.createServer(function (req, res) {
      •   res.writeHead(200, {'Content-Type': 'text/plain'});
      •   res.end('Hello Worldn');
      • }).listen(8080);
      • console.log('Server running at port 8080');
    • execute o comando "node teste.js" e verifique no seu navegador 
      • http://seu_server:8080
  3. Script de inicialização como forever
    • #!/bin/bash
    • # chkconfig: 345 88 08
    • # description: Forever for Node.js

    • DEAMON=/caminho/do/seu/app.js
    • LOG=/caminho/do/log/da/aplicacao/forever.log
    • PID=/root/.forever/pids/forever.pid

    • export PATH=$PATH:/usr/bin/node/bin
    • export NODE_PATH=$NODE_PATH:/usr/bin/node/lib/node_modules

    • node=node
    • forever=forever

    • case "$1" in
    •     start)
    •         $forever start -l $LOG --pidFile $PID -a $DEAMON
    •         ;;
    •     stop)
    •         $forever stop --pidFile $PID $DEAMON
    •         ;;
    •     stopall)
    •         $forever stopall --pidFile $PID
    •         ;;
    •     restartall)
    •         $forever restartall --pidFile $PID
    •         ;;
    •     reload|restart)
    •         $forever restart -l $LOG --pidFile $PID -a $DEAMON
    •         ;;
    •     list)
    •         $forever list
    •         ;;
    •     *)
    •         echo "Usage: /etc/init.d/forever {start|stop|restart|reload|stopall|restartall|list}"
    •         exit 1
    •         ;;
    • esac

Nenhum comentário:

Postar um comentário