Simple start/stop shell-script

Tutorials, tips and tricks.

Moderator: moderators

Simple start/stop shell-script

Postby wintermute » Thu Feb 05, 2009 6:54 am

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
wintermute
 
Posts: 14
Joined: Tue Jan 27, 2009 5:10 am

Postby drewkeller » Sat Jun 13, 2009 4:32 am

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

drewkeller
 
Posts: 2
Joined: Wed Jun 10, 2009 2:37 am

Postby wintermute » Sat Jun 13, 2009 5:17 am

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.
5.257 artists
5.902 albums
69.903 songs
458.50 GB (~ 7.122 hours)
wintermute
 
Posts: 14
Joined: Tue Jan 27, 2009 5:10 am

Postby WannaBeGeekster » Sat May 29, 2010 4:45 pm

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!
WannaBeGeekster
 
Posts: 1
Joined: Sat May 29, 2010 3:40 pm

Re: Simple start/stop shell-script

Postby Linkz57 » Mon Jan 16, 2012 12:50 am

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.
Linkz57
 
Posts: 1
Joined: Mon Jan 16, 2012 12:45 am

Re: Simple start/stop shell-script

Postby ytechie » Mon Jan 16, 2012 1:14 am

Yup. That is how I run my subsonic services.
User avatar
ytechie
 
Posts: 547
Joined: Sun Dec 12, 2010 5:05 am
Location: Manhattan, New York

Re: Simple start/stop shell-script

Postby ebasta » Sat Aug 16, 2014 7:57 pm

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!
ebasta
 
Posts: 92
Joined: Fri Dec 17, 2010 8:07 pm


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 9 guests