I'm working on Amazon Linux and am running into an issue with my init.d script. I'm trying to run Kibana 4, which is just a script that calls nodejs to run as a service, but it's not working.
Typing service kibana status
works fine, but whenever I type service kibana start
the command just hangs (i.e. doesn't run in the background). When I Ctrl-C
it, I get a [FAILED]
response, but the process has been created and is running.
When I look in my /var/run/
directory for kibana.pid
I don't see anything, even though the process is actually running. Can anyone help me understand what I'm doing wrong?
I have a feeling I'm not using daemon
correctly...
#!/bin/bash
#
# /etc/init.d/kibana
# Set defaults.
exec="/kibana/kibana-{{ kibana.version }}-linux-x64/bin/kibana > /var/log/kibana/kibana.log"
prog="kibana"
pid_file="/var/run/${prog}.pid"
lock_file="/var/lock/subsys/$prog"
kibana_user="kibana"
# Execute init.d functions
. /etc/rc.d/init.d/functions
case "$1" in
start)
echo -n "Start Kibana: "
daemon --user $kibana_user --pidfile $pid_file $exec
retval=$?
echo
[ $retval -eq 0 ] && touch $lock_file
;;
stop)
echo -n "Stopping Kibana: "
su $kibana_user -c "kill `cat $pid_file`"
retval=$?
[ $retval -eq 0 ] && rm -f $lock_file
echo "OK"
;;
status)
status -p $pid_file kibana
exit $?
;;
*)
echo "Usage: `basename $0` start|stop|status"
exit 1
esac
exit 0