Page 1 of 1

Simple start/stop shell-script

PostPosted: Thu Feb 05, 2009 6:54 am
by wintermute
Nothing fancy but maybe useful for someone.

Code: Select all
#!/bin/bash

PID=""

function get_pid {
   PID=`ps ax |grep java |grep subsonic |cut -d " " -f 1`
}

function stop {
   get_pid
   if [ -z $PID ]; then
      echo "Subsonic is not running."
      exit 1
   else
      echo -n "Stopping Subsonic.."
      kill $PID
      sleep 1
      echo ".. Done."
   fi
}


function start {
   get_pid
   if [ -z $PID ]; then
      echo  "Starting Subsonic.."
      /var/subsonic/subsonic.sh
      get_pid
      echo "Done. PID=$PID"
   else
      echo "Subsonic is already running, PID=$PID"
   fi
}

function restart {
   echo  "Restarting Subsonic.."
   get_pid
   if [ -z $PID ]; then
      start
   else
      stop
      start
   fi
}


function status {
   get_pid
   if [ -z  $PID ]; then
      echo "Subsonic is not running."
      exit 1
   else
      echo "Subsonic is running, PID=$PID"
   fi
}

case "$1" in
   start)
      start
   ;;
   stop)
      stop
   ;;
   restart)
      restart
   ;;
   status)
      status
   ;;
   *)
      echo "Usage: $0 {start|stop|restart|status}"
esac

PostPosted: Sat Jun 13, 2009 4:32 am
by drewkeller
Here's one that can start/stop/restart/status without using terminal commands. Requires the zenity package, which I think is fairly common.

I haven't figured out a good way to get a sudo prompt if needed, although another script could ask for sudo password and then pass it to this script as described at http://techrepublic.com.com/5208-12853- ... ID=2541628

Code: Select all
#!/bin/bash

PID=""

function get_pid {
   PID=`ps ax |grep java |grep subsonic |cut -d " " -f 1`
}

function stop {
   (
      echo "# Stopping Subsonic..."
      get_pid
      until [ -z $PID ]; do
         kill $PID; sleep 1
         get_pid
      done
      echo "# Subsonic stopped."; sleep 1
   ) |
   zenity --progress --pulsate
}


function start {
   (
      echo "# Starting Subsonic..."
      get_pid
      /var/subsonic/standalone/subsonic.sh | $ZENITY
      echo "# " $ZENITY
      while [ -z $PID ]; do
         get_pid; sleep 1
      done
      get_pid;
      echo "# Subsonic started. PID = " $PID
   ) |
   zenity --progress --pulsate
}

get_pid
if [ -z  $PID ]; then
   ans=$(zenity --list \
      --text "Subsonic is not running. What do you want to do?" \
      --radiolist \
      --column "" --column "Action" \
      TRUE "Start Subsonic")

   case $ans in
      "Start Subsonic")
         start
      ;;
      *)
   esac

else
   ans=$(zenity --list \
      --text "Subsonic is running with PID=$PID. What do you want to do?" \
      --radiolist \
      --column "" --column "Action" \
      TRUE "Restart Subsonic" \
      FALSE "Stop Subsonic")

   case $ans in
      "Restart Subsonic")
         stop
         start
      ;;
      "Stop Subsonic")
         stop
      ;;
      *)
   esac

fi
exit 0


PostPosted: Sat Jun 13, 2009 5:17 am
by wintermute
I haven't figured out a good way to get a sudo prompt if needed

How about gksu / gksudo?

I updated my script recently (using the PID file now and fixed some other quirks), I'll post it soon.

PostPosted: Sat May 29, 2010 4:45 pm
by WannaBeGeekster
I would still be curious to see the changes you have made? Did you just re-edit your last post and I didn't notice?

Thanks!

Re: Simple start/stop shell-script

PostPosted: Mon Jan 16, 2012 12:50 am
by Linkz57
To future Googlers, I found this form looking for a simple way to manually start and stop the Subsonic service on Linux. The easiest way I found to do that is:

sudo service subsonic restart
sudo service subsonic start
sudo service subsonic stop
sudo service subsonic status


This works like a charm on my 32-bit Ubuntu 11.10, hope it helps.

Re: Simple start/stop shell-script

PostPosted: Mon Jan 16, 2012 1:14 am
by ytechie
Yup. That is how I run my subsonic services.

Re: Simple start/stop shell-script

PostPosted: Sat Aug 16, 2014 7:57 pm
by ebasta
Linkz57 wrote:To future Googlers, I found this form looking for a simple way to manually start and stop the Subsonic service on Linux. The easiest way I found to do that is:

sudo service subsonic restart
sudo service subsonic start
sudo service subsonic stop
sudo service subsonic status


This works like a charm on my 32-bit Ubuntu 11.10, hope it helps.


This future Googler thanks you in the past!