Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
Prettify combined Linux script
Browse files Browse the repository at this point in the history
  • Loading branch information
binwiederhier committed Sep 2, 2014
1 parent 18f9f14 commit 2f176e0
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 192 deletions.
153 changes: 0 additions & 153 deletions gradle/daemon/syncanyd

This file was deleted.

178 changes: 178 additions & 0 deletions gradle/daemon/syncanyd.skel
@@ -0,0 +1,178 @@
### Daemon script begin ##########################################################

# Daemon variables
DAEMON_NAME=syncanyd
DAEMON_APPDIR=~/.config/syncany
DAEMON_CONTROLFILE=$DAEMON_APPDIR/daemon.ctrl
DAEMON_PIDFILE=$DAEMON_APPDIR/daemon.pid
DAEMON_LOGDIR=$DAEMON_APPDIR/logs
DAEMON_LOGFILE=$DAEMON_LOGDIR/daemon.log
DAEMON_OPTS="--log=$DAEMON_LOGFILE daemon"

# Daemon functions
daemon_get_pid() {
if [ -e $DAEMON_PIDFILE ]; then
echo $(cat $DAEMON_PIDFILE)
else
echo -1
fi
}

daemon_running() {
ID=$(daemon_get_pid)
if [ $ID -eq -1 ]; then
echo 0
elif [ -n $(ps -p$ID -opid=) ]; then
echo 1
else
echo 0
fi
}

daemon_start() {
DAEMON_RUNNING=$(daemon_running)

echo -n "Starting daemon: "

if [ $DAEMON_RUNNING -eq 1 ]; then
echo "$DAEMON_NAME already running (pid $DAEMON_PID)"
else
nohup "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.syncany.Syncany $DAEMON_OPTS > /dev/null 2>&1 &

DAEMON_PID=-1
TRIES=10

while [ $DAEMON_RUNNING -eq 0 -a $TRIES -gt 0 ]; do
DAEMON_RUNNING=$(daemon_running)
echo -n "."

DAEMON_PID=$(get_pid)
TRIES=$(($TRIES-1))
sleep 1
done

if [ $TRIES -eq 0 ]; then
echo " Failed to start process. EXITING."
echo "Failed command line: $ $DAEMON $DAEMON_OPTS"
exit 2
fi

echo " $DAEMON_NAME (pid $DAEMON_PID)."
fi
}

daemon_stop() {
DAEMON_RUNNING=$(daemon_running)

echo -n "Stopping daemon: "

if [ $DAEMON_RUNNING -eq 0 ]; then
echo "$DAEMON_NAME not running"
else
echo "shutdown" >> $DAEMON_CONTROLFILE

TRIES=10
while [ $DAEMON_RUNNING -eq 1 -a $TRIES -gt 0 ]; do
DAEMON_RUNNING=$(daemon_running)
echo -n "."

TRIES=$(($TRIES-1))
sleep 1
done

if [ $TRIES -eq 0 ]; then
echo " Failed to stop process $DAEMON_PID. Try 'force-stop'. EXITING."
exit 3
fi

echo " $DAEMON_NAME stopped."
fi
}

daemon_force_stop() {
DAEMON_RUNNING=$(daemon_running)

echo -n "Force-stopping daemon: "

if [ $DAEMON_RUNNING -eq 0 ]; then
echo "$DAEMON_NAME not running"
else
kill -9 $DAEMON_PID

DAEMON_RUNNING=$(daemon_running)

sleep 1

DAEMON_RUNNING=$(daemon_running)
if [ $DAEMON_RUNNING -eq 1 ]; then
echo "Failed to kill -9 $DAEMON_PID. EXITING."
else
rm $DAEMON_PIDFILE 2> /dev/null
rm $DAEMON_CONTROLFILE 2> /dev/null

echo "Killed $DAEMON_NAME (pid $DAEMON_PID)."
fi
fi
}

daemon_status() {
DAEMON_RUNNING=$(daemon_running)
echo -n "Checking daemon: "$DAEMON_NAME

if [ $DAEMON_RUNNING -eq 0 ]; then
echo " not running"
else
echo " running (pid $DAEMON_PID)."
fi
}

daemon_reload() {
DAEMON_RUNNING=$(daemon_running)
echo -n "Reloading daemon: "$DAEMON_NAME

if [ $DAEMON_RUNNING -eq 0 ]; then
echo " not running"
else
echo "reload" >> $DAEMON_CONTROLFILE
echo "."
fi
}

export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"

mkdir -p $DAEMON_APPDIR
mkdir -p $DAEMON_LOGDIR

DAEMON_PID=$(daemon_get_pid)

case "$1" in
daemon)
case "$2" in
start)
daemon_start
;;
stop)
daemon_stop
;;
restart)
daemon_stop
daemon_start
;;
status)
daemon_status
;;
reload)
daemon_reload
;;
force-stop)
daemon_force_stop
;;
*)
echo "Usage: sy daemon (start|stop|reload|restart|status|force-stop)"
;;
esac
;;
*)
#JAVA_EXEC_REPLACEMENT_MARKER#
;;
esac

0 comments on commit 2f176e0

Please sign in to comment.