I'm having issue setting up a node app as a service under Fedora 17.
If I start the app/service manually by using:
node server.js
All works fine, the server starts and uses almost no CPU.
But this needs to be an always running service that needs to be restarted
if it crashes and needs to be started at boot time. To do this I've created
a start script in init.d like so:
#!/bin/bash
#
# chkconfig: - 99 01
# description: node server
. /etc/rc.d/init.d/functions
USER="nodeuser"
DAEMON="/usr/local/bin/supervisor"
ROOT_DIR="/home/nodeuser/nodeserver"
SERVER="$ROOT_DIR/server.js"
LOG_FILE="$ROOT_DIR/app.js.log"
LOCK_FILE="/var/lock/subsys/node-server"
do_start()
{
if [ ! -f "$LOCK_FILE" ] ; then
echo -n $"Starting $SERVER: "
runuser -l "$USER" -c "$DAEMON $SERVER >> $LOG_FILE &" &&
echo_success || echo_failure
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $LOCK_FILE
else
echo "$SERVER is locked."
RETVAL=1
fi
}
do_stop()
{
echo -n $"Stopping $SERVER: "
pid=`ps -aefw | grep "$DAEMON $SERVER" | grep -v " grep " | awk
'{print $2}'`
kill -9 $pid > /dev/null 2>&1 && echo_success || echo_failure
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $LOCK_FILE
}
case "$1" in
start)
do_start
;;
stop)
do_stop
;;
restart)
do_stop
do_start
;;
*)
echo "Usage: $0 {start|stop|restart}"
RETVAL=1
esac
exit $RETVAL
If I start the server using this method the node process uses significant
CPU (on my VPS it sits at 15-20% CPU while idle).
Doing an strace on the process gives output like (and never stops):
epoll_wait(5, {?} 0xbfe55240, 1024, 85) = 1
clock_gettime(CLOCK_MONOTONIC, {2817, 89100171}) = 0
read(8, "\1\0\0\0\0\0\0\0", 1024) = 8
clock_gettime(CLOCK_MONOTONIC, {2817, 89464229}) = 0
epoll_wait(5, {}, 1024, 16) = 0
clock_gettime(CLOCK_MONOTONIC, {2817, 105857441}) = 0
clock_gettime(CLOCK_MONOTONIC, {2817, 105979957}) = 0
futex(0x88656e4, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x88656e0, {FUTEX_OP_SET, 0,
FUTEX_OP_CMP_GT, 1}) = 1
futex(0x88656c4, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x88656e4, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x88656e0, {FUTEX_OP_SET, 0,
FUTEX_OP_CMP_GT, 1}) = 1
futex(0x88656c4, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x88656e4, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x88656e0, {FUTEX_OP_SET, 0,
FUTEX_OP_CMP_GT, 1}) = 1
futex(0x88656c4, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x88656e4, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x88656e0, {FUTEX_OP_SET, 0,
FUTEX_OP_CMP_GT, 1}) = 1
futex(0x88656c4, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x88656e4, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x88656e0, {FUTEX_OP_SET, 0,
FUTEX_OP_CMP_GT, 1}) = 1
futex(0x88656c4, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x88656e4, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x88656e0, {FUTEX_OP_SET, 0,
FUTEX_OP_CMP_GT, 1}) = 1
futex(0x88656c4, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x88656e4, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x88656e0, {FUTEX_OP_SET, 0,
FUTEX_OP_CMP_GT, 1}) = 1
futex(0x88656c4, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x88656e4, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x88656e0, {FUTEX_OP_SET, 0,
FUTEX_OP_CMP_GT, 1}) = 1
futex(0x88656c4, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x88656e4, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x88656e0, {FUTEX_OP_SET, 0,
FUTEX_OP_CMP_GT, 1}) = 1
futex(0x88656c4, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x88656e4, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x88656e0, {FUTEX_OP_SET, 0,
FUTEX_OP_CMP_GT, 1}) = 1
futex(0x88656c4, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x88656e4, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x88656e0, {FUTEX_OP_SET, 0,
FUTEX_OP_CMP_GT, 1}) = 1
futex(0x88656c4, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x88656e4, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x88656e0, {FUTEX_OP_SET, 0,
FUTEX_OP_CMP_GT, 1}) = 1
futex(0x88656c4, FUTEX_WAKE_PRIVATE, 1) = 1
I'm at a loss for how to fix this..
I'd be grateful for any solution - even if it involves using a different
method to start and monitor the process (if there is a better way)
I'm using node version: v0.10.2
Any help will be greatly appreciated.
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.