Changeset 525


Ignore:
Timestamp:
Jun 14, 2010, 7:50:45 PM (10 years ago)
Author:
zecrazytux
Message:

Use `start-stop-daemon' instead of reinventing the wheel, see #18

Location:
jobq
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • jobq/README

    r249 r525  
    1313
    1414  http://forge.bearstech.com/trac/wiki/JobQueue
     15
     16Note: as of version 0.8.1, jobq depends on start-stop-daemon (from Debian).
     17On other distributions than Debian, either install that tool or hack jobq's
     18run_daemon method.
    1519
    1620Example usage:
  • jobq/debian/changelog

    r456 r525  
     1jobq (0.8.1) stable; urgency=low
     2
     3  * Use start-stop-daemon instead of custom deamonization method
     4
     5 -- Sebastien Bocahu <sbocahu@bearstech.com>  Thu, 10 Jun 2010 20:32:18 +0200
     6
    17jobq (0.8) stable; urgency=low
    28
  • jobq/debian/control

    r457 r525  
    88Package: jobq
    99Architecture: all
    10 Depends: bash (>= 3.2), mailx, perl, ${shlibs:Depends}, ${misc:Depends}
     10Depends: bash (>= 3.2), mailx, perl, ${shlibs:Depends}, ${misc:Depends}, dpkg
    1111Description: Simple job queue
    1212 jobq handles any nimber of job queues, where jobs are run as soon
  • jobq/jobq

    r456 r525  
    2222
    2323PROGRAM=jobq
    24 VERSION=0.8
     24VERSION=0.8.1
    2525
    2626# Hardcoded value for now, should fit most people
     
    5858 
    5959  # Automatically start queue runner
    60   cd - >/dev/null && exec $0 -q $queue -d $debug
     60  cd - >/dev/null && run_daemon
    6161}
    6262
    6363queue_runner() {
     64  cd $JOBPATH/$queue
     65
    6466  if [ -z "$debug" ]; then
    6567    trap ":" INT HUP
     
    105107
    106108run_daemon() {
    107   cd $JOBPATH/$queue
     109  pidfile=$JOBPATH/$queue/.runner
     110  jobqpath="$(cd "$(dirname "$0")"; pwd)/$(basename $0)"
    108111
    109   pidfile=.runner
    110   pid=`cat $pidfile 2>/dev/null`
    111   if kill -0 "$pid" 2>/dev/null; then
    112     # OK, queue runner is alive for this queue
    113     exit 0
     112  mkdir -m 0700 -p $JOBPATH/$queue
     113
     114  /sbin/start-stop-daemon --quiet --make-pidfile --pidfile $pidfile --startas $jobqpath --background --start -- -q $queue -s $debug
     115  if [ $? -eq 1 ]; then
     116    if [ -n "$daemon" ]; then
     117      echo 'Jobq is already running !'
     118    fi
     119  else
     120    echo "queue runner started for user/queue '$LOGNAME/$queue' (pid $pid)" | logger -t $PROGRAM
    114121  fi
    115   # No queue runner at all or some dead pid, cleanup
    116   rm -f $pidfile
    117 
    118   export debug queue pidfile
    119   queue_runner &
    120 
    121   pid=$!
    122   echo $pid > $pidfile
    123   echo "queue runner started for user/queue '$LOGNAME/$queue' (pid $pid)" | logger -t $PROGRAM
    124122}
    125123
     
    160158  case "$1" in
    161159    -d|--daemon)  shift; daemon=yes;;
     160    -s)           shift; startqueue=yes;; # internal usage only
    162161    -q|--queue)   shift; queue="$1"; shift;;
    163162    -h|--help)    help;;
     
    171170done
    172171
     172if [ -n "$startqueue" ]; then
     173  queue_runner
     174  exit 0
     175fi
    173176if [ -n "$daemon" ]; then
    174177  run_daemon
Note: See TracChangeset for help on using the changeset viewer.