How i can deploy nodejs in vps

302 views
Skip to first unread message

Fernando Segura Gòmez

unread,
Aug 25, 2013, 4:57:10 AM8/25/13
to nod...@googlegroups.com
Hi.
I need help, im very newbie about how deploy my nodejs app in production,i have always worked in localhost, but  i dont know how i can deploy an app and run always, when i run with the command node, and  i close my ssh program, my nodejs app is stopped.
How i can deploy and keep running my app?

Ryan Schmidt

unread,
Aug 25, 2013, 5:57:48 AM8/25/13
to nod...@googlegroups.com, Fernando Segura Gòmez

On Aug 25, 2013, at 03:57, Fernando Segura Gòmez wrote:

> I need help, im very newbie about how deploy my nodejs app in production,i have always worked in localhost, but i dont know how i can deploy an app and run always, when i run with the command node, and i close my ssh program, my nodejs app is stopped.
> How i can deploy and keep running my app?

What operating system will your server run? Each OS likely has its own preferred way of starting a service and keeping it running.


Ashutosh Das

unread,
Aug 25, 2013, 9:41:48 AM8/25/13
to nod...@googlegroups.com
You can use screen . Here is a tutorial : how-to-install-and-use-screen-on-an-ubuntu-cloud-server

José F. Romaniello

unread,
Aug 25, 2013, 11:17:57 AM8/25/13
to nod...@googlegroups.com

This is incorrect, screen allows you to partition a console but will not guarantee your service is automatically started at boot time or restarted if it fail.

As Ryan said, it depends what OS are you targeting. The way you do services in ubuntu is with upstart. You put an script under /etc/init/your-app.conf :


description "your-app"

author  "you"

setuid some-user

start on (local-filesystems and net-device-up IFACE=eth0)

stop on shutdown

respawn

respawn limit 15 5

script

  exec >>/var/log/$UPSTART_JOB.log 2>&1

  echo starting\ $UPSTART_JOB\ `date`

  cd /usr/local/lib/node_modules/your-app

  NODE_ENV=production CONFIG_FILE="/etc/your-app.json" npm start

end script

You can store your application in any path, usually /opt, the one i used for this example assumes you install your-app as a global node module.

This will redirect stdout and stderr to /var/log/your-app.log, make sure you create a logrotate rule.

It also assumes you have some sort of config file in /etc/your-app.json.

Then the service will be started when booting the OS, and restarted if it fails.

You can also start/stop/restart manually as follows:

service your-app stop/start/restart

If you symlink /etc/init/your-app.conf to /etc/init.d/your-app, you will get also tab-completion in bash when writing service yo.

Every SO has a different way of doing this :

  • initng

  • launchd

  • upstart

  • Service Management Facility

  • systemd

  • OpenRC

  • runit

  • daemontools

to name a few.


regards

 




El ago 25, 2013 10:41 a.m., "Ashutosh Das" <areo...@gmail.com> escribió:
You can use screen . Here is a tutorial : how-to-install-and-use-screen-on-an-ubuntu-cloud-server

--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
 
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Aria Stewart

unread,
Aug 25, 2013, 7:40:15 PM8/25/13
to nod...@googlegroups.com
Ubuntu: Upstart
Fedora & Arch: Systemd
SmartOS, Illumos and Solaris: SMF
CentOS 6 and lower, RHEL 6 and lower, most other linuxes: System V style init scripts
MacOS X: launchd
Other BSDs: use a simple daemonizing tool and add to /etc/rc or rc.local

Node-based tools: forever, daemonize and I'm sure others I can't think of.

Other tools of various quality: Monit, God, runit, daemontools, screen, dtach, tmux

You can often get away with `nohup yourapp & disown` in the shell, and it'll at
least keep it from hanging up when the SSH session ends, but there's more
robust tools above.

Aria

Michael Pisarski

unread,
Aug 26, 2013, 12:30:06 PM8/26/13
to nod...@googlegroups.com
I use forever and have not had any issues.

Gagle

unread,
Aug 26, 2013, 2:07:16 PM8/26/13
to nod...@googlegroups.com
Use the linux services

Tim Caswell

unread,
Aug 26, 2013, 5:35:34 PM8/26/13
to nod...@googlegroups.com
On Mon, Aug 26, 2013 at 11:30 AM, Michael Pisarski <mspi...@gmail.com> wrote:
I use forever and have not had any issues.

Does forever handle machine reboots?

--

Jeremy Darling

unread,
Aug 26, 2013, 7:34:34 PM8/26/13
to nodejs
Assuming your on linux: http://stackoverflow.com/questions/11275870/how-can-i-automatically-start-a-node-js-application-in-amazon-linux-ami-on-aws

Also, wrap your process in forever to keep it up and running in case of faults.

If you want to go all out, services like AppFog, NodeJitsu, and etc have opensourced the source to their systems.  You could always stand it up on your VIP

Dylan Hassinger

unread,
Aug 26, 2013, 7:34:49 PM8/26/13
to nod...@googlegroups.com
For machine reboots, I think you would need a boot script that re-launches Forever.

Pisarski, Michael S

unread,
Aug 26, 2013, 8:04:28 PM8/26/13
to nod...@googlegroups.com
Tim, 

I have a simple script in /etc/init.d (on CentOS/RHEL 5+)
Looks something like this:
#!/bin/sh
#
# chkconfig: 235 90 10
# description: Starts YOUR_SERVICE to control application.
# source function library
. /etc/rc.d/init.d/functions
NAME=YOUR_SERVICE
DAEMONDIR="/usr/bin"
DAEMON="/usr/bin/forever"
DAEMON_ARGS="-l /var/log/YOUR_SERVICE --append --silent --spinSleepTime 1000 --minUptime 1000"
APPDIR="/usr/lib/node_modules/Your_APP"
APP_ARGS=""
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 1

fail()
{
        failure
        echo
        echo $1
}
#
# Function that starts the daemon/service
#
start()
{
        echo -n $"Starting $NAME: "
        $DAEMON start $DAEMON_ARGS $APPDIR $APP_ARGS
        RETVAL=$?
        [ $RETVAL -eq 0 ] && success || failure
        echo
        return $RETVAL
}
#
# Function that stops the daemon/service THIS IS A LITTLE BRUTE FORCE but it works for me.
#
stop()
{
        echo -n $"Signaling $NAME to stop: "
        $DAEMON stopall
        RETVAL=$?
        [ $RETVAL -eq 0 ] && success || failure
        echo
        return $RETVAL
}
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        stop
        start
        RETVAL=$?
        ;;
  *)
        echo "Usage: $NAME {start|stop|restart}"
        exit 1
        ;;
esac
exit $RETVAL
That is all, then I can also use $ service YOUR_SERVICE stop|start|restart


You received this message because you are subscribed to a topic in the Google Groups "nodejs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nodejs/S8ujZwF6zXQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nodejs+un...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
Michael S. Pisarski
-------------------------------------------------------------------
mspi...@gmail.com
phone: 704.900.3130
-------------------------------------------------------------------
"I cannot imagine how the clockwork of the universe can exist without a clockmaker." - Voltaire

David Dias

unread,
Aug 27, 2013, 8:50:34 AM8/27/13
to nod...@googlegroups.com
I know this maybe be overkill for a little/single/attempt application, but check docker.io and dokku, it's very easy to set up and a joy to deploy :)

Nuno Job has written a very good post how to get it started here: https://medium.com/code-adventures/438bce155dcb

Cheers,
David
Reply all
Reply to author
Forward
0 new messages