I am currently struggling with building a script that starts my web-application.
I would like to use foreverjs as I already start my backend with it. My json-file, which will be executed by foreverjs looks like the following:
[
{
"uid": "my_backend",
"append": true,
"script": "app.js",
"sourceDir": "/path/to/backend/"
},
{
"uid": "my_frontend",
"append": true,
"script": "???",
"command": "gulp dist && gulp production"
"sourceDir": "/path/to/frontend/"
}
]
I am not quite sure what I should use in the frontend. I need to use gulp so I would assume I have to add it in 'command'. However, my script would need to be empty, which is not allowed from foreverjs. Any suggestion of how I can run gulp via foreverjs?
I solved it myself, using the following script for my init.d:
WORKINGDIR=/usr/local/app/my/app
SCRIPT='/usr/local/app/my/app/node_modules/gulp/bin/gulp.js production'
LOG=/usr/local/app/my/app/log
PID=/root/.forever/pids/myapp.pid
FOREVER=/usr/local/node/node-default/bin/forever
UID_APP='myapp'
case "$1" in
start)
$FOREVER start --workingDir $WORKINGDIR --uid $UID_APP -l $LOG/forever.log -o $LOG/forever_out.log -e $LOG/forever_err.log --pidFile $PID -a $SCRIPT
;;
stop)
$FOREVER stop $UID_APP --pidFile $PID
;;
stopall)
$FOREVER stopall --pidFile $PID
;;
restartall)
$FOREVER restartall --pidFile $PID
;;
reload|restart)
$FOREVER restart -l $LOG/forever.log -o $LOG/forever_out.log -e $LOG/forever_err.log --pidFile $PID -a $SCRIPT
;;
list)
$FOREVER list
;;
logs)
$FOREVER logs
;;
*)
echo "Usage: /etc/init.d/myservice {start|stop|restart|reload|stopall|restartall|list}"
exit 1
;;
esac
exit 0
Basically using /path/to/forever start --workingDir 'mydir' /path/to/gulp [gulpTask] works.