You are not logged in.

#1 2010-04-09 04:33:00

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

serv - a q&d daemon monitor that should have stayed in Bash

I wanted an excuse to poke around with C, so I rewrote the Bash script presented here with some extra bells and whistles.

Usage:

Show status of all daemons:
  serv

Show status of a single daemon:
  serv <daemon>

Interact with a daemon's init script:
  serv <daemon> <action>

This isn't worthy of the AUR, but here's a PKGBUILD:

# Contributor: Dave Reisner <d@falconindy.com>
pkgname=serv
pkgver=20100409
pkgrel=1
pkgdesc="A daemon tool that should have stayed in Bash"
arch=('i686' 'x86_64')
url="VERSION"
license=('MIT')
depends=()
makedepends=('git')

_gitroot="git://github.com/falconindy/serv.git"
_gitname="serv"

build() {
  cd "$srcdir"
  msg "Connecting to GIT server...."

  if [ -d $_gitname ] ; then
    cd $_gitname && git pull origin
    msg "The local files are updated."
  else
    git clone $_gitroot $_gitname
  fi

  msg "GIT checkout done or server timeout"
  msg "Starting make..."

  rm -rf "$srcdir/$_gitname-build"
  git clone "$srcdir/$_gitname" "$srcdir/$_gitname-build"
  cd "$srcdir/$_gitname-build"

  make || return 1
  install -m755 serv -D ${pkgdir}/usr/bin/serv
}

Offline

#2 2010-05-03 13:18:10

MutantTurkey
Member
Registered: 2010-02-07
Posts: 17

Re: serv - a q&d daemon monitor that should have stayed in Bash

this is really nice smile

it simplifys working with daemons


good work!

MutantTurkey

Offline

#3 2010-05-03 13:26:02

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,799
Website

Re: serv - a q&d daemon monitor that should have stayed in Bash

a while back i got a bash function from someone on here called service, the real gem was the bash completion function that came with it.  you could probably sed s/service/serv the following and use it with your tool as well:

_service_complete()
{
  local cur prev

  COMPREPLY=()
  cur=${COMP_WORDS[COMP_CWORD]}
  prev=${COMP_WORDS[COMP_CWORD-1]}

  if [ "$prev" == service ]; then
    COMPREPLY=( $(compgen -W "\
                $(  for service in /etc/rc.d/*; do
                    echo ${service##*/}
                    done )" -- $cur ) )
  else
    COMPREPLY=( $(compgen -W '\
                  start
                  stop
                  restart
                  reload' -- $cur ) )
  fi
}

complete -F _service_complete service

Offline

#4 2010-05-19 01:16:45

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: serv - a q&d daemon monitor that should have stayed in Bash

Nifty. bash completion seems pretty straight forward. Going to have to implement this in some of my other projects...

Took your provided script and improved it somewhat:

_serv_complete() {
  local cur prev

  COMPREPLY=()
  cur=${COMP_WORDS[COMP_CWORD]}
  prev=${COMP_WORDS[COMP_CWORD-1]}

  case "$prev" in
    "serv") COMPREPLY=( $(compgen -W "\
                    $(  for service in /etc/rc.d/*; do
                        echo ${service##*/}
                        done )" -- $cur ) ) ;;

    "start"|"stop"|"restart") ;;

    *) [ -f /var/run/daemons/$prev ] &&
            COMPREPLY=( $(compgen -W '\
                          stop 
                          restart' -- $cur ) ) ||
            COMPREPLY=( $(compgen -W '\
                          start' -- $cur ) ) ;;
  esac
}

complete -F _serv_complete serv

Running daemons complete only 'stop' and 'reload', and stopped daemons complete only 'start'.

Now to port this to ZSH.

Offline

Board footer

Powered by FluxBB