Run NodeJS in Ubuntu 11.04 EC2 With User Permission and Run as Service

In this post, i show you how to install & run NodeJS in Production Mode without ROOT permission. I make this runing and tested on Amazon EC2 on Ubuntu Natty 11.04. I user user permission NodeJS installation on [my NodeJS how to installation] (
Set environment

Our node is installed on ~/local/node. We will make this also can be accessed in GLOBAL environment. My home path is /home/ubuntu.

Editing /etc/environment :


And restart your server to load NODE in ENV.
Install Runit

We will using Runit for running NodeJS application.

sudo apt-get install runit
cd /etc/sv && sudo mkdir userservice
sudo touch run && sudo chmod a+x run
sudo chown ubuntu:ubuntu -R /etc/sv/userservice

We will make service running by users, not by root access.

Edit run files :

exec 2>&1
exec chpst -U ubuntu:ubuntu runsvdir /home/ubuntu/service

Registering User service

Now we creating service in user home. All application that in this service folder, will running by Runit with user permission.

cd ~/
mkdir service && cd service
mkdir nodejs && cd nodejs
touch run && chmod a+x run

Edit run files :

exec 2>&1
exec sudo -i -u ubuntu node /var/yodi/ >> /var/yodi/ 2>&1

In this example, my nodejs application located in /var/yodi/
Start service

Register userservice into /etc/services by symbolic links : sudo ln -s /etc/sv/userservice /etc/service/

Now you can start nodejs by sv start userservice.

Do ps aux | grep node and you will get this results :

root      7728  0.0  0.0    160     4 ?        S    07:13   0:00 runsv nodejs
root      7729  0.0  0.0   2400  1160 ?        S    07:13   0:00 sudo -i -u ubuntu node /var/yodi/
ubuntu    7730  0.5  0.8  58536 14216 ?        Sl   07:13   0:27 node /var/yodi/
ubuntu    8482  0.0  0.0   3612   860 pts/5    S+   08:33   0:00 grep –color=auto node

Mission complete!

Copy from


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s