Advertisement
opexxx

webrtc-tracker-nodejs.sh

Mar 24th, 2015
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.95 KB | None | 0 0
  1. #!/bin/sh
  2. # http://catchvar.com/nodejs-server-and-web-sockets-on-amazon-ec2-w
  3. sudo apt-get update
  4. sudo apt-get install -y g++ curl libssl-dev apache2-utils
  5. sudo apt-get install -y make
  6. sudo apt-get install -y git-core
  7. # Install node
  8. sudo git clone --depth 1 https://github.com/joyent/node.git
  9. cd node
  10. sudo git checkout v0.6.15
  11. sudo ./configure --prefix=/usr
  12. sudo make
  13. sudo make install
  14. # Install haproxy
  15. cd ~
  16. wget http://haproxy.1wt.eu/download/1.5/src/devel/haproxy-1.5-dev6.tar.gz
  17. tar xzf haproxy-1.5-dev6.tar.gz
  18. cd haproxy*
  19. sudo make install
  20. sudo mkdir /etc/haproxy
  21. sudo sh -c 'cat > /etc/haproxy/haproxy.cfg << EOF
  22. global
  23. maxconn 4096
  24. defaults
  25. mode http
  26. frontend all 0.0.0.0:80
  27. timeout client 86400000
  28. default_backend www_nodejs
  29. acl is_websocket hdr(upgrade) -i websocket
  30. acl is_websocket hdr_beg(host) -i ws
  31. use_backend www_nodejs if is_websocket
  32. backend www_nodejs
  33. option forwardfor
  34. timeout server 86400000
  35. timeout connect 4000
  36. server nodejs 127.0.0.1:3000 weight 1 maxconn 10000 check
  37. EOF'
  38. # Test haproxy config
  39. haproxy -c -f /etc/haproxy/haproxy.cfg
  40. # Install Upstart
  41. sudo apt-get install -y upstart
  42. sudo sh -c 'cat > /etc/init/nodeServer.conf << EOF
  43. #!upstart
  44. description "node.js server"
  45. author "jsermeno"
  46. start on startup
  47. stop on shutdown
  48. script
  49. export HOME="/root"
  50. NODE_ENV=production node /root/www/webrtc-tracker-nodejs/main.js 2>&1 >> /var/log/node.log
  51. end script
  52. EOF'
  53. sudo chmod +x /etc/init/nodeServer.conf
  54. # Install Monit
  55. sudo apt-get install -y monit
  56. sudo sh -c 'cat > /etc/monit/monitrc << EOF
  57. #!monit
  58. set logfile /var/log/monit.log
  59. check host nodejs with address 127.0.0.1
  60. start program = "/sbin/start nodeServer"
  61. stop program = "/sbin/stop nodeServer"
  62. if failed port 3000 protocol HTTP
  63. request /
  64. with timeout 10 seconds
  65. then restart
  66. EOF'
  67. # Get the tracker
  68. mkdir ~/www
  69. cd ~/www
  70. sudo git clone git://github.com/hcliff/webrtc-tracker-nodejs.git
  71. cd webrtc-tracker-nodejs
  72. sudo npm install
  73. sudo start nodeServer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement