#!/bin/sh # # /etc/init.d/ringojs -- startup script for the Ringo JavaScript runtime # # Written by Miquel van Smoorenburg . # Modified for Debian GNU/Linux by Ian Murdock . # Modified for Tomcat by Stefan Gybas . # Modified for Tomcat6 by Thierry Carrez . # Modified for RingoJS by Hannes Wallnoefer . # ### BEGIN INIT INFO # Provides: ringojs # Required-Start: $local_fs $remote_fs $network # Required-Stop: $local_fs $remote_fs $network # Should-Start: $named # Should-Stop: $named # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start RingoJS # Description: Start RingoJS ### END INIT INFO set -e PATH=/bin:/usr/bin:/sbin:/usr/sbin NAME=ringojs DESC="Ringo JavaScript runtime" DAEMON=/usr/bin/jsvc RINGO_HOME=/usr/share/$NAME DEFAULT=/etc/default/$NAME # direct both stdout and stderr to ringo-out.log RINGO_OUT=/var/log/ringojs/ringo-out.log RINGO_ERR="&1" # fix for Rhino on bootclasspath in OpenJDK RHINO_CLASSPATH=-Xbootclasspath/p:/usr/share/ringojs/lib/js.jar if [ `id -u` -ne 0 ]; then echo "You need root privileges to run this script" exit 1 fi # Make sure ringo is started with system locale if [ -r /etc/default/locale ]; then . /etc/default/locale export LANG fi . /lib/lsb/init-functions . /etc/default/rcS # The following variables can be overwritten in $DEFAULT # Run Ringo as this user ID RINGO_USER=ringojs # Run this application RINGO_APPLICATION=modules/ringo/webapp/daemon.js # Arguments to pass to RingoJS runtime RINGO_OPTS="" # Arguments to pass to the application script APPLICATION_OPTS="" # Set the RingoJS module search path RINGO_MODULE_PATH=apps/demo export RINGO_MODULE_PATH # The first existing directory is used for JAVA_HOME (if JAVA_HOME is not # defined in $DEFAULT) JDK_DIRS="/usr/lib/jvm/java-6-sun /usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-1.5.0-sun /usr/lib/j2sdk1.5-sun /usr/lib/j2sdk1.5-ibm" # Look for the right JVM to use for jdir in $JDK_DIRS; do if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then JAVA_HOME="$jdir" fi done export JAVA_HOME # Directory for per-instance configuration files and webapps RINGO_BASE=/usr/share/$NAME # Default Java options # Set java.awt.headless=true if JAVA_OPTS is not set so the # Xalan XSL transformer can work without X11 display on JDK 1.4+ # It also looks like the default heap size of 64M is not enough for most cases # so the maximum heap size is set to 128M if [ -z "$JAVA_OPTS" ]; then JAVA_OPTS="-Djava.awt.headless=true -Xmx128M" fi # End of variables that can be overwritten in $DEFAULT # overwrite settings from default file if [ -f "$DEFAULT" ]; then . "$DEFAULT" fi if [ ! -f "$RINGO_HOME/run.jar" ]; then log_failure_msg "$NAME is not installed" exit 1 fi if [ ! -f "$DAEMON" ]; then log_failure_msg "missing $DAEMON" exit 1 fi JAVA_OPTS="$JAVA_OPTS "-Dringo.home="$RINGO_HOME" # Set logging.properties if provided if [ -r "$RINGO_BASE"/config/log4j.properties ]; then JAVA_OPTS="$JAVA_OPTS "-Dlog4j.configuration="$RINGO_BASE/config/log4j.properties" fi # Define other required variables RINGO_PID="/var/run/$NAME.pid" BOOTSTRAP_CLASS=org.ringojs.tools.launcher.Main JSVC_CLASSPATH="/usr/share/java/commons-daemon.jar:$RINGO_HOME/run.jar" case "$1" in start) if [ -z "$JAVA_HOME" ]; then log_failure_msg "no JDK found - please set JAVA_HOME" exit 1 fi if [ ! -d "$RINGO_BASE" ]; then log_failure_msg "invalid RINGO_BASE: $RINGO_BASE" exit 1 fi log_daemon_msg "Starting $DESC" "$NAME" if start-stop-daemon --test --start --pidfile "$RINGO_PID" \ --user $RINGO_USER --startas "$JAVA_HOME/bin/java" \ >/dev/null then cd "$RINGO_BASE" $DAEMON $RHINO_CLASSPATH -cp "$JSVC_CLASSPATH" \ -user "$RINGO_USER" -outfile "$RINGO_OUT" -errfile "$RINGO_ERR" \ -pidfile "$RINGO_PID" $JAVA_OPTS "$BOOTSTRAP_CLASS" \ $RINGO_OPTS "$RINGO_APPLICATION" $APPLICATION_OPTS sleep 1 if start-stop-daemon --test --start --pidfile "$RINGO_PID" \ --user $RINGO_USER --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 --test --start --pidfile "$RINGO_PID" \ --user "$RINGO_USER" --startas "$JAVA_HOME/bin/java" \ >/dev/null then log_progress_msg "(not running)" else $DAEMON $RHINO_CLASSPATH -cp "$JSVC_CLASSPATH" \ -pidfile "$RINGO_PID" -stop "$BOOTSTRAP_CLASS" fi log_end_msg 0 ;; status) if start-stop-daemon --test --start --pidfile "$RINGO_PID" \ --user $RINGO_USER --startas "$JAVA_HOME/bin/java" \ >/dev/null then if [ -f "$RINGO_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 $RINGO_PID`" fi ;; restart|force-reload) if start-stop-daemon --test --stop --pidfile "$RINGO_PID" \ --user $RINGO_USER --startas "$JAVA_HOME/bin/java" \ >/dev/null then $0 stop sleep 1 fi $0 start ;; try-restart) if start-stop-daemon --test --start --pidfile "$RINGO_PID" \ --user $RINGO_USER --startas "$JAVA_HOME/bin/java" \ >/dev/null then $0 start fi ;; *) log_success_msg "Usage: $0 {start|stop|restart|try-restart|force-reload|status}" exit 1 ;; esac exit 0