log_daemon_msg "Starting $DESC" "$NAME"
if start-stop-daemon --start --test --pidfile $RED5_PID \
--startas "$JAVA_HOME/bin/java" \
>/dev/null; then
wait_1935_close
start-stop-daemon --start --background --make-pidfile --chuid red5 --umask $UMASK \
--chdir $RED5_HOME --pidfile $RED5_PID --startas "$JAVA_HOME/bin/java" -- $JAVA_OPTS
sleep 5
# Because we pushed it into the background, we need to check it's status
if start-stop-daemon --test --start --pidfile $RED5_PID --startas "$JAVA_HOME/bin/java" >/dev/null; then
log_end_msg 1
else
log_end_msg 0
fi
else
log_progress_msg "(already running)"
log_end_msg 0
fi
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
if start-stop-daemon --start --test --pidfile $RED5_PID \
--startas "$JAVA_HOME/bin/java" \
>/dev/null; then
log_progress_msg "(not running)"
else
start-stop-daemon --stop --pidfile $RED5_PID \
--startas "$JAVA_HOME/bin/java"
sleep 5
rm -f $RED5_PID
fi
log_end_msg 0
;;
status)
if start-stop-daemon --start --test --pidfile $RED5_PID \
--startas "$JAVA_HOME/bin/java" \
>/dev/null; then
if [ -f "$RED5_PID" ]; then
log_success_msg "$DESC is not running, but pid file exists."
exit 1
else
log_success_msg "$DESC is not running."
exit 3
fi
else
log_success_msg "$DESC is running with pid `cat $RED5_PID`"
fi
;;
restart|force-reload)
if start-stop-daemon --test --stop --pidfile "$RED5_PID" \
--startas "$JAVA_HOME/bin/java" \
>/dev/null; then
$0 stop
sleep 1
fi
$0 start
;;
*)
log_success_msg "Usage: $0 {start|stop|restart|force-reload|status}"
exit 1
;;
esac