[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Problem with init script.. :-[



On Thu, Jan 31, 2002 at 01:19:04AM -0600, Adam Majer wrote:

> NAME=yiff
> <snip>
>   stop)
>         echo -n "Stopping $DESC":
>         k=`ls /var/run/$NAME*.pid 2>/dev/null`
>         for i in non $k; do
>                 if [ "$i" != non ]; then
>                         kill `cat $i` 2> /dev/null;
>                         rm -f $i;
>                 fi;
>         done;
>         echo "$NAME."
>         ;;
> 
> 
> It works, _BUT_ if no server is running, it bails out on me
> so people can't upgrade if they have yiff-server installed
> but not running.

What you want is something like:

         echo -n "Stopping $DESC:"
         for pidfile in $(find /var/run -maxdepth 1 -name "$NAME*.pid"); do
           start-stop-daemon --stop --quiet --pidfile $pidfile --oknodo
         done
         echo "$NAME."

- Use find to avoid the globbing error when no matching files exist
- It is OK if the list is empty in the for statement
- Use start-stop-daemon, that's what it's there for
- You don't need those semicolons; a newline will terminate the statements
  fine
- If the daemon doesn't remove its PID file when it exits, then it's broken
  and needs to be fixed

-- 
 - mdz



Reply to: