I have a NodeJS app that I want to start with Upstart. So far the process works, Upstart initiates the app, but when I load the page, the CSS are not loading. The curious thing is that if I start the app using #node myapp.js, it will start and load the files correctly. I can't the difference, if any, that makes this issue possible. ANy help would be appreciated.
This is how I've set up the app:
var express = require('express'),
config = require('getconfig'),
path = require('path'),
expressValidator = require('express-validator'),
crypto = require('crypto'),
app = express();
app.configure('development', function () {
app.use(express.logger('dev'));
});
app.configure(function () {
app.use(require('less-middleware')({ src: path.join(__dirname, 'public') }));
app.use(express.static('public'));
require('./bootstraps/handlebars')(app);
app.use(express.favicon());
app.use(express.limit('5mb'));
app.use(express.urlencoded({limit: '5mb'}));
app.use(express.multipart({limit: '5mb'}));
app.use(express.json({limit: '5mb'}));
app.use(express.cookieParser(config.http.cookieSecret));
app.use(expressValidator());
app.use(express.methodOverride());
require('./bootstraps/session')(app);
app.use(function(req,resp,next){
resp.locals.session = req.session;
next();
});
app.use(app.router);
require('./bootstraps/controllers')(app);
});
app.listen(process.env.PORT || config.http.port);
module.exports = app;
... and this is my Upstart script:
#!upstart
description "My Project"
author "Author"
start on startup
stop on shutdown
script
export HOME="/root"
echo $$ > /var/run/myprocess.pid
su -s /bin/sh -c 'exec "$0" "$@"' theuser -- /root/local/bin/node /path/to/my_project/myapp.js >> /var/log/my_project/system.log 2>&1
end script
pre-start script
# Date format same as (new Date()).toISOString() for consistency
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting" >> /var/log/my_project/system.log
end script
pre-stop script
rm /var/run/dreamcasino.pid
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> /var/log/my_project/system.log
end script
You can use chdir so that the working directory is correct
script
export HOME="/root"
chdir /path/to/my_project/
echo $$ > /var/run/myprocess.pid
exec sudo -u theuser /root/local/bin/node /path/to/my_project/myapp.js >> /var/log/my_project/system.log 2>&1
end script