Ok, so the last post: Node Day 1: Pre project planning thoughts, all the new toys, listed what I was planning, this is what I actually managed to get done.
I've been using Nodejitsu for all my node stuff for the moment, but for various reasons, mainly lack of monitoring and no idea what a "drone" actually is other than I can pay for 1, 3, 5 or 10 of them, I'm moving away. I'm currently paying $33/month for 3 drones and I'm not sure if I can run several apps off a single drone (with careful coding) or if a big app needs just 1 drone or 10.
I like their deployment tools and github hooks but now seems like the time to branch out on my own into the wilderness. With this in mind this is what happened today.
- Went to MediaTemple and grabbed a DV Developer Linux VPS hosting box for $30/month.
- Pick "whatever the most recent LTS is" as per Tom Armitage's tweet, which is Ubuntu 12.04 LTF Precise.
- Wait for it to start up, etc. etc.
- Set up the root account password as per these instructions.
- Then created "normal" none root users, and disable root user SSH login using these instructions. Note, for me adding a new user and setting the password all happened in one step, not two steps like these instructions.
- Stuffed all the login, server and passwords into 1Password so I don't lose it all.
- SSH in as the new "normal" user and made sure you can "su -" superuser up to root, if so, log out of the root account never to SSH into root again.
- Follow these instructions when acting as the root user to install node.
- Test that node works as my "normal" user, do a happy dance.
Now the next thing was to make sure two things happened...
- The node apps to start-up automatically when the server starts or restarts
- The node apps to restart if (when) they crash
I installed PM2 as the root user as described here: https://github.com/Unitech/pm2.
Some things I found useful, starting a node app and giving it a name makes it a lot easier to deal with, like this...
pm2 start web.js --name HelloWorldApp"Hot" restarting an app is awesome, this is what I'd do after deploying new files...
pm2 reload HelloWorldAppSo that deals with starting and restarting an app, stopping is what you'd expect. This I found interesting...
pm2 start www/helloworld/web.js -i max --name HelloWorldAppWhich starts the app in cluster mode on as many CPUs as possible. When I did this it fired up 16 instances of the app, I later tried
-i 4to just use 4 instances. I have no idea what cluster does in node, or if I need or can use it, so that's something else to add to my look-up list.
Of course the whole point of this was to make sure it always stays up, running this command seems to do that...
pm2 startupOnce that was run I tried restarting the whole server and sure enough the nodeapp started serving right away. I ran 4 instances the app, killed one and saw a new one spawn to take it's place. So that all seems to do what it's supposed to do.
I did hit one problem in that I needed to
sudo up to run the
pm2 startup command but because of the order I'd created my users the user I was running as apparently wasn't a "sudoer" so I needed to
su - up to root and ran...
usermod -a -G admin revdancatt...to add myself to the admin group. Totally logging out and SSHing back in then allowed me to use
sudowhen trying to run PM2 with the
And that's pretty much where I got up to.
For my current apps I have Mongo databases over at MongoHQ that node connects to via URL connection strings, so in theory I should just be able to move the apps over and they'll still work. Tomorrow the plan is to try and move a not very important app over and then leave it to see how it runs, while researching Grunt or something. If that all works then I can pull over the main app and get started on that.
This is slightly different to trying to get jquery to do something :)