~ubuntu-branches/ubuntu/quantal/smstools/quantal

« back to all changes in this revision

Viewing changes to scripts/load_balancing.sh

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Schoenfeld
  • Date: 2009-12-04 15:05:03 UTC
  • mfrom: (4.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20091204150503-c1fj03yolimkgha8
Tags: 3.1.6-1
* New upstream version
  (Closes: #494274)
* Remove patch to fix modem timeouts; upstream includes changes that
  obsolete it
* Switch to debhelper 7 and minimize the rules file
* Add a file debian/manpage for manpage installation
* Add a debian/install file for files which need to be installed
* Add an ignore.d.server file for logcheck (Closes: #516158)
* [INTL:ja] Add Japanese po-debconf template translation
  (ja.po); thanks to Hideki Yamane
  (Closes: #558073)
* Change my email address at some places
* Make ucf call on purge conditional, so that purge does not fail if
  ucf is not installed.
* Fix pathname of smsd configuration in ucf call (its smsd.conf not
  smstools.conf)
* Remove the last changed header from smsd.conf because its annoying
  on every upgrade
* Fix a bug in the init script, that would cause the daemon to not
  properly run, if /var/run/smstools does not exist, because it
  wouldn't respect its user settings anymore.
* Make sure a symlink from /var/log/smsd.log to /var/log/smstools/smsd.log
  is created on upgrades, if /var/log/smsd.log exists.
* Change the logfile path in the default configuration to
  /var/log/smstools/smsd.log

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
# ---------------------------------------------------------------------------------------
 
3
# This example is for three modems, named GSM1, GSM2 and GSM3 using queues Q1, Q2 and Q3.
 
4
# In the global part of smsd.conf, enable message counters:
 
5
# stats = /var/spool/sms/stats
 
6
# Use zero value for interval if statistics files are not used:
 
7
# stats_interval = 0
 
8
#
 
9
# Enable checkhandler (this script):
 
10
# checkhandler = /usr/local/bin/load_balancing.sh
 
11
#
 
12
# Define queues and providers:
 
13
# [queues]
 
14
# Q1 = /var/spool/sms/Q1
 
15
# Q2 = /var/spool/sms/Q2
 
16
# Q3 = /var/spool/sms/Q3
 
17
 
18
# [providers]
 
19
# Q1 = 0,1,2,3,4,5,6,7,8,9,s
 
20
# Q2 = 0,1,2,3,4,5,6,7,8,9,s
 
21
# Q3 = 0,1,2,3,4,5,6,7,8,9,s
 
22
#
 
23
# Add queue definition for each modem:
 
24
# [GSM1]
 
25
# queues = Q1
 
26
# etc...
 
27
# ---------------------------------------------------------------------------------------
 
28
 
 
29
STATSDIR=/var/spool/sms/stats
 
30
 
 
31
read_counter()
 
32
{
 
33
  RESULT=0
 
34
  FILE=$STATSDIR/$1.counter
 
35
 
 
36
  if [[ -e $FILE ]]
 
37
  then
 
38
    COUNTER=`formail -zx $1: < $FILE`
 
39
    if [ "$COUNTER" != "" ]; then
 
40
      RESULT=$COUNTER
 
41
    fi
 
42
  fi
 
43
  return $RESULT
 
44
}
 
45
 
 
46
# If there is Queue (or Provider) defined, load balancing is ignored:
 
47
QUEUE=`formail -zx Queue: < $1`
 
48
if [ "$QUEUE" = "" ]; then
 
49
  QUEUE=`formail -zx Provider: < $1`
 
50
  if [ "$QUEUE" = "" ]; then
 
51
    # Read current counters:
 
52
    read_counter GSM1
 
53
    COUNTER1=$?
 
54
    read_counter GSM2
 
55
    COUNTER2=$?
 
56
    read_counter GSM3
 
57
    COUNTER3=$?
 
58
 
 
59
    QUEUE=Q1
 
60
    COUNTER=$COUNTER1
 
61
    if [ $COUNTER2 -lt $COUNTER ]; then
 
62
      QUEUE=Q2
 
63
      COUNTER=$COUNTER2
 
64
    fi
 
65
    if [ $COUNTER3 -lt $COUNTER ]; then
 
66
      QUEUE=Q3
 
67
      COUNTER=$COUNTER3
 
68
    fi
 
69
 
 
70
    TMPFILE=`mktemp /tmp/smsd_XXXXXX`
 
71
    cp $1 $TMPFILE
 
72
    formail -f -I "Queue: $QUEUE" < $TMPFILE > $1
 
73
    unlink $TMPFILE
 
74
  fi
 
75
fi
 
76
exit 0