gcald

#This is a startup script for GCalDaemon (Java application)

#! /bin/sh
### BEGIN INIT INFO
# Provides:          gcald
# Required-Start:    $network $local_fs $remote_fs
# Required-Stop:     $network $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      S 0 1 6
# Short-Description: GCALDaemon 
### END INIT INFO

PATH=/usr/sbin:/usr/bin:/sbin:/bin
DESC="Google Calendar and address book sync daemon"
NAME=gcald
PIDFILE="/var/run/$NAME.pid"
SCRIPTNAME="/etc/init.d/$NAME"

BASEDIR=/opt/GCALDaemon
makepath()
{
	local IFS=:
	echo "$*"
}
CLASSPATH=$(makepath "$BASEDIR"/lib/*)
CLASS=org.gcaldaemon.standalone.Main
ARGS=$BASEDIR/conf/gcal-daemon.cfg
DAEMON=/usr/bin/java
DAEMON_ARGS="-Xmx256m -cp $CLASSPATH $CLASS $ARGS"

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
[ -d "$BASEDIR" ] || exit 0

# Define LSB log_* functions.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start()
{
	# Return
	#   0 if daemon has been started
	#   1 if daemon was already running
	#   2 if daemon could not be started
	start-stop-daemon --start --pidfile $PIDFILE --exec "$DAEMON" --test > /dev/null \
		|| return 1
	start-stop-daemon --start --pidfile $PIDFILE --exec "$DAEMON" --background --make-pidfile -- \
		$DAEMON_ARGS \
		|| return 2
}

#
# Function that stops the daemon/service
#
do_stop()
{
	# Return
	#   0 if daemon has been stopped
	#   1 if daemon was already stopped
	#   2 if daemon could not be stopped
	#   other if a failure occurred
	start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile "$PIDFILE" --exec "$DAEMON"
	RETVAL="$?"
	[ "$RETVAL" = 2 ] && return 2
	rm -f "$PIDFILE"
	return "$RETVAL"
}

case "$1" in
  start)
	log_daemon_msg "Starting $DESC"
	do_start
	case "$?" in
		0|1) log_end_msg 0 ;;
		2) log_end_msg 1 ;;
	esac
	;;
  stop)
	log_daemon_msg "Stopping $DESC"
	do_stop
	case "$?" in
		0|1) log_end_msg 0 ;;
		2) log_end_msg 1 ;;
	esac
	;;
  restart|force-reload)
	log_daemon_msg "Restarting $DESC"
	do_stop
	case "$?" in
	  0|1)
		do_start
		case "$?" in
			0) log_end_msg 0 ;;
			1) log_end_msg 1 ;; # Old process is still running
			*) log_end_msg 1 ;; # Failed to start
		esac
		;;
	  *)
		# Failed to stop
		log_end_msg 1
		;;
	esac
	;;
  *)
	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
	exit 3
	;;
esac

One thought on “gcald

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s