Stagecoach + nginx questions

34 views
Skip to first unread message

Matthew Crider

unread,
Jul 27, 2015, 4:33:51 PM7/27/15
to apostrophenow
Hey all,

I'm having some trouble with Stagecoach that hopefully somebody can help me out with (Ubuntu 14.04).  I think part of the confusion is that I'm reading a tutorial on http://justjs.com/ and it seems out of date, but the github docs are more of a collection of facts rather than a guide. 

Anyway, I've got stagecoach to successfully deploy to my server and if i go in and start app.js with forever my Apostrophe site works (nginx proxies the site to port 80).  

Here's the weird thing. If I run

forever --minUptime=1000 --spinSleepTime=10000 -o data/console.log -e data/error.log start `pwd`/app.js && echo "Site started"

or if I depend on sc-deploy to start the site, the site doesn't actually run.  If i go into the project and run this, the site does work:

cd /opt/stagecoach/apps/projectname/current/ && forever --minUptime=1000 --spinSleepTime=10000 -o data/console.log -e data/error.log start app.js && echo "Site started"


So, a few questions about that:
- Why would the latter work and not the former?  Not that it really matters, but the former should totally work unless there is a permission issue or something i'm overlooking.
- Why doesn't sc-deploy start the server?  Does sc-deploy just run the deployment/start/ script in my project?  It seems like it does, but even when i change the above command in the script, sc-deploy still doesn't start the site.
- Is there any way to prevent npm install from being run on each deploy?  I'm assuming not, at least not easily.
- Whats your recommended way for starting the site when the server reboots?  An upstart script to run app.js with forever?

Thanks guys!  I'm building a pretty cool site with Apostrophe, looking forward to getting it live.

- Matt

Fotis Paraskevopoulos

unread,
Jul 28, 2015, 5:27:28 AM7/28/15
to apostr...@googlegroups.com
I was having the same problem and came up to the same solution, and just let it go :)

FP





--
You received this message because you are subscribed to the Google Groups "apostrophenow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apostropheno...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matthew Crider

unread,
Jul 28, 2015, 8:37:25 AM7/28/15
to apostrophenow, fot...@gmail.com
I *think* it might have to do with the permissions of my deploy user.  I get different behavior from forever when I try to use it with root vs. my deploy user.  I'll investigate some more today.

- Matt

Tom Boutell

unread,
Jul 28, 2015, 9:53:35 AM7/28/15
to apostr...@googlegroups.com
We use this without issues every day... but, the stagecoach README is confusing and doesn't really reflect our internal best practices anymore. We should rewrite that.

The key things to remember are:

* Never run anything as root! Ever! Why would you dooooo that?

Seriously, use root to configure nginx, then make a regular "nodeapps" user, give the /opt/stagecoach/apps folder away to your "nodeapps" user, and then never log in as root again as far as stagecoach is concerned. Nothing powered by node needs to run as root (:

* If forever is running as root, stop all those processes.

* If you ever ran stuff as root, "chown -R nodeapps /opt/stagecoach/apps" to clean up the permissions mess.

* In settings.production, settings.staging, etc. in your deployment folder set the username to nodeapps.

* Deploy. The site starts up.

* You can manually start or stop a site correctly by logging in as nodeapps (NOT root), and doing:

cd /opt/stagecoach/apps/myappname/current
bash deployment/stop
bash deployment/start

This is what stagecoach does.

* One exception to not running things as root: you might want to check out "mechanic," a utility we wrote that gives you all our best practices for nginx in a simple command line utility. We use it for all newer server setups. It's in npm. But, you don't have to use it.

* As for running things at boot time, that's another exception to the root rule. Just make sure that something runs /opt/stagecoach/sc-proxy/sc-start-all as root at boot time. That script will take care of using "su" to start the sites as the nodeapps user.

So one simple way is to pop that command in /etc/rc.local. That's not as classy as an upstart script but it works.


--


THOMAS BOUTELL, DEV & OPS
P'UNK AVENUE | (215) 755-1330  |  punkave.com

Matthew Crider

unread,
Jul 28, 2015, 10:38:22 AM7/28/15
to apostrophenow, t...@punkave.com
Woah, mechanic is really cool.  Also, it has a great README, Stagecoach could use that clarity in its docs :)

Thanks for the tips.  I know I should be using a deploy user, but was just testing things out with root on the server.  But, I must've done something stupid with my deploy user, including but not limited to giving it sudo access.  I blasted away that user and created a new basic user (and gave it ownership of the /opt/stagecoach/apps directory) and everything seems to be working peachy now (including the boot command in rc.local).

Next time i'm in Philly i'm buying you guys a case of beer.  Seriously good stuff coming out of p'unk ave!

-Matt

Tom Boutell

unread,
Jul 28, 2015, 10:40:51 AM7/28/15
to Matthew Crider, apostrophenow
You're welcome! Thanks for the nudge to do something about the stagecoach README. 
Reply all
Reply to author
Forward
0 new messages