diff --git a/sparkleshare b/sparkleshare index 3c6adfc8..a7079b9f 100644 --- a/sparkleshare +++ b/sparkleshare @@ -1,20 +1,28 @@ #!/bin/bash +pidfile=/tmp/sparkleshare/sparkleshare.pid + # Create a directory to save the pid to -mkdir -p /tmp/sparkleshare/ - if [[ "$1" == "start" ]]; then - if [ -e "/tmp/sparkleshare/sparkleshare.pid" ]; then - echo "SparkleShare is already running." - else - echo -n "Starting SparkleShare..." - - # Start SparkleShare in the background and save the pid - mono /usr/local/share/sparkleshare/SparkleShare.exe $2 & - PID=$! - echo $PID > /tmp/sparkleshare/sparkleshare.pid - echo " Done." + if [ -e "${pidfile}" ]; then + sparklepid=`cat ${pidfile}` + if [ -n "`ps -p ${sparklepid} | grep ${sparklepid}`" ] + then + echo "SparkleShare is already running" + exit 0 + else + echo "SparkleShare stale pid file found, starting a new instance" + rm -f $pidfile + fi fi + + echo -n "Starting SparkleShare..." + mkdir -p /tmp/sparkleshare/ + # Start SparkleShare in the background and save the pid + mono /usr/local/share/sparkleshare/SparkleShare.exe $2 & + PID=$! + echo $PID > /tmp/sparkleshare/sparkleshare.pid + echo " Done." fi if [[ "$1" == "stop" ]]; then