Ben, thanks for sticking with this, its looking better definitely. A few more things before this is ready for the charm store (and really, I'm excited, I think this is one of the cooler webapps I've looked at for the charm store):
[1] install_error on local provider:
The local provider only gives us a very bare bones system. One thing missing is 'make'. This causes npm to fail to install the needed modules because of:
2012-03-20 05:29:57,555: hook.output@INFO:
> bcrypt@0.5.0 install /var/lib/juju/units/subway-1/charm/subway/node_modules/bcrypt
> make build
2012-03-20 05:29:57,559: hook.output@ERROR: sh:
2012-03-20 05:29:57,560: hook.output@ERROR: make: not found
2012-03-20 05:29:57,560: hook.output@ERROR:
So, in addition to npm, you need to install the full build suite, as some of the npm packages seem to need a C or C++ compiler, so
apt-get -y install npm build-essential
Should work and be general enough to handle most modules. It resolved the issue on my system anyway.
[2] start hook never returns
Its good that you moved the service startup to the start hook, however, the start hook never returns, so the juju unit agent will be unable to run further hooks until that happens. nohup is not sufficient to run a daemon. At the very least, you need to use start-stop-daemon to background it like this:
Even better would be to make an upstart job. Its quite simple:
cat >> /etc/init/subway.conf <<EOF
start on runlevel [2345]
stop on runlevel [^2345]
chdir $PWD
exec node subway
EOF
Then start/stop are just
start subway || :
and
stop subway || :
--- non blockers below ---
[3] non idempotent install hook
Sometimes install needs to be run over and over again, especially if there is a transient error with one of the mirrors used to install software, somebody might need to retry the hook Right now, install will fail on the git clone when run a second time because the subway directory is there.
I'd suggest this
if [ -d subway ] ; then
(cd subway && git pull)
else
git clone .... subway
fi
[4] open-port before software is running
This is just a style thing, but typically you don't want to open the port until the software is fully configured and running. So I'd move the 'open-port 3000' command to the start hook, after the service is started.
Ben, thanks for sticking with this, its looking better definitely. A few more things before this is ready for the charm store (and really, I'm excited, I think this is one of the cooler webapps I've looked at for the charm store):
[1] install_error on local provider:
The local provider only gives us a very bare bones system. One thing missing is 'make'. This causes npm to fail to install the needed modules because of:
2012-03-20 05:29:55,901: hook.output@ERROR: npm http 200 https:/ /registry. npmjs.org/ connect- assets/ -/connect- assets- 2.1.6.tgz
2012-03-20 05:29:57,555: hook.output@INFO: juju/units/ subway- 1/charm/ subway/ node_modules/ bcrypt
> bcrypt@0.5.0 install /var/lib/
> make build
2012-03-20 05:29:57,559: hook.output@ERROR: sh:
2012-03-20 05:29:57,560: hook.output@ERROR: make: not found
2012-03-20 05:29:57,560: hook.output@ERROR:
So, in addition to npm, you need to install the full build suite, as some of the npm packages seem to need a C or C++ compiler, so
apt-get -y install npm build-essential
Should work and be general enough to handle most modules. It resolved the issue on my system anyway.
[2] start hook never returns
Its good that you moved the service startup to the start hook, however, the start hook never returns, so the juju unit agent will be unable to run further hooks until that happens. nohup is not sufficient to run a daemon. At the very least, you need to use start-stop-daemon to background it like this:
start-stop-daemon --start --oknodo --background --pidfile /run/subway.pid --startas /usr/bin/node -- subway
This has the added benefit of making stop more clear:
start-stop-daemon --stop --oknodo --pidfile /run/subway.pid --retry 5
Even better would be to make an upstart job. Its quite simple:
cat >> /etc/init/ subway. conf <<EOF
start on runlevel [2345]
stop on runlevel [^2345]
chdir $PWD
exec node subway
EOF
Then start/stop are just
start subway || :
and
stop subway || :
--- non blockers below ---
[3] non idempotent install hook
Sometimes install needs to be run over and over again, especially if there is a transient error with one of the mirrors used to install software, somebody might need to retry the hook Right now, install will fail on the git clone when run a second time because the subway directory is there.
I'd suggest this
if [ -d subway ] ; then
(cd subway && git pull)
else
git clone .... subway
fi
[4] open-port before software is running
This is just a style thing, but typically you don't want to open the port until the software is fully configured and running. So I'd move the 'open-port 3000' command to the start hook, after the service is started.