SMS server setup: Perbedaan revisi

(Created page with "== Overview == This document describes the steps required to configure a Rasberry Pi computer as an SMS server, connected via the internet to the iSIKHNAS database server. A ...")
 
 
(1 revisi antara oleh pengguna yang sama tidak ditampilkan)
Baris 1: Baris 1:
== Overview ==  
+
=SMS Server Setup=
This document describes the steps required to configure a Rasberry Pi computer as an SMS server, connected via the internet to the iSIKHNAS database server. A USB GSM modem is attached to the Pi using a powered USB hub. It assumes that configuration is being done using a Windows computer.
+
The SMS server is managed by SMSTools3, and is installed on the Messaging server in the AWS Virtual Private Cloud. A second installation is present on the training (Sidecar) server.  
  
== Hardware ==
+
==Configuration file==
Requirements are:
+
The contents of smsd.conf on the live server are as follows (IP addresss removed)
* Raspberry Pi
 
* Powered USB hub
 
* GSM USB modem (this example uses a Huawei E173)
 
* Micro USB cable
 
* Standard USB cable
 
* Ethernet cable
 
* 4Gb SD card (or micro SD card with adapter)
 
  
== Installing the operating system (Windows) ==
+
# New Server smsd.conf
# Download the latest [http://www.raspberrypi.org/downloads Raspbian disk image] (fastest via BitTorrent if you have a client) and save it to your hard disk
+
 
# Create a new directory and unzip the image file into the new directory
+
  devices = SOV*4009-4024
# Download [http://sourceforge.net/projects/win32diskimager Win32DiskImager] and save it to your hard disk
+
 
# Unzip the program files and save them to your new directory
+
  logfile  = /var/log/smstools/smsd.log
# Put a blank 4Gb SD card into the SD card slot of your computer (or an attached USB card reader)
+
  loglevel = 5
# Start Win32DiskImager by double clicking
+
  smart_logging = yes
# Select the Raspbian image (e.g. 2013-02-09-wheezy-raspbian.img) as the file, and your card as the destination. '''Be careful''' to get the right drive. If you select your hard disk it will be overwritten and destroyed.
+
 
# Click write and wait for the image to be written
+
  stats    = /var/spool/sms/stats
# Close the software and remove the SD card
+
  outgoing = /var/spool/sms/outgoing
 +
  checked  = /var/spool/sms/checked
 +
  incoming = /var/spool/sms/incoming
 +
  infofile = /var/run/smstools/smsd.working
 +
  pidfile  = /var/run/smstools/smsd.pid
 +
  failed  = /var/spool/sms/failed
 +
  sent    = /var/spool/sms/sent
 +
 
 +
  errorsleeptime = 3
 +
  # eventhandler for incoming messages
 +
  eventhandler = /home/smsd/sms_in.sh
 +
  # regular run to send new messages with msgid of 0
 +
  regular_run = /home/smsd/sms_rr.sh
 +
  regular_run_interval = 300
 +
  user = smsd
 +
  group = dialout
 +
 
 +
  [queues]
 +
  MAIN = /var/spool/sms/queues/MAIN
 +
  OTHER = /var/spool/sms/queues/OTHER
 +
  HALO = /var/spool/sms/queues/HALO
 +
  SOV4009 = /var/spool/sms/queues/SOV4009
 +
  SOV4010 = /var/spool/sms/queues/SOV4010
 +
  SOV4011 = /var/spool/sms/queues/SOV4011
 +
  SOV4012 = /var/spool/sms/queues/SOV4012
 +
  SOV4013 = /var/spool/sms/queues/SOV4013
 +
  SOV4014 = /var/spool/sms/queues/SOV4014
 +
  SOV4015 = /var/spool/sms/queues/SOV4015
 +
  SOV4016 = /var/spool/sms/queues/SOV4016
 +
  SOV4017 = /var/spool/sms/queues/SOV4017
 +
  SOV4018 = /var/spool/sms/queues/SOV4018
 +
  SOV4019 = /var/spool/sms/queues/SOV4019
 +
  SOV4020 = /var/spool/sms/queues/SOV4020
 +
  SOV4021 = /var/spool/sms/queues/SOV4021
 +
  SOV4022 = /var/spool/sms/queues/SOV4022
 +
  SOV4023 = /var/spool/sms/queues/SOV4023
 +
  SOV4024 = /var/spool/sms/queues/SOV4024
 +
 
 +
  [providers]
 +
  # telkomsel
 +
  MAIN = 62811, 62812, 62813, 62821, 62822, 62823, 62852, 62853
 +
  # non-telkomsel
 +
  OTHER = 628
 +
  # other (primarily interntational - could be expensive so use postpaid)
 +
  HALO = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
 +
  # short numbers - admin.
 +
  SOV4017 = s
 +
 
 +
  [default]
 +
  regular_run_interval = 300
 +
  queues = modemname, MAIN, OTHER
 +
  socket_connection_retries = -1
 +
  socket_connection_errorsleeptime = 20
 +
  socket_connection_alarm_after = 10
 +
 
 +
  [SOV4009]
 +
  device = @ipaddress:4009
 +
  incoming = yes
 +
  regular_run =          /var/spool/sms/regular_run/SOV4009.sh
 +
  regular_run_post_run = /var/spool/sms/regular_run/SOV4009.sh
 +
  regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4009.cmdfile
 +
  regular_run_statfile = /var/spool/sms/regular_run/SOV4009.statfile
 +
 
 +
  [SOV4010]
 +
  device = @ipaddress:4010
 +
  incoming = yes
 +
  regular_run =          /var/spool/sms/regular_run/SOV4010.sh
 +
  regular_run_post_run = /var/spool/sms/regular_run/SOV4010.sh
 +
  regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4010.cmdfile
 +
  regular_run_statfile = /var/spool/sms/regular_run/SOV4010.statfile
 +
 
 +
  [SOV4011]
 +
  device = @ipaddress:4011
 +
  incoming = yes
 +
  regular_run =          /var/spool/sms/regular_run/SOV4011.sh
 +
  regular_run_post_run = /var/spool/sms/regular_run/SOV4011.sh
 +
  regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4011.cmdfile
 +
  regular_run_statfile = /var/spool/sms/regular_run/SOV4011.statfile
 +
 
 +
  [SOV4012]
 +
  device = @ipaddress:4012
 +
  incoming = yes
 +
  regular_run =          /var/spool/sms/regular_run/SOV4012.sh
 +
  regular_run_post_run = /var/spool/sms/regular_run/SOV4012.sh
 +
  regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4012.cmdfile
 +
  regular_run_statfile = /var/spool/sms/regular_run/SOV4012.statfile
 +
 
 +
  [SOV4013]
 +
  device = @ipaddress:4013
 +
  incoming = yes
 +
  regular_run =          /var/spool/sms/regular_run/SOV4013.sh
 +
  regular_run_post_run = /var/spool/sms/regular_run/SOV4013.sh
 +
  regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4013.cmdfile
 +
  regular_run_statfile = /var/spool/sms/regular_run/SOV4013.statfile
 +
 
 +
  [SOV4014]
 +
  device = @ipaddress:4014
 +
  incoming = yes
 +
  regular_run =          /var/spool/sms/regular_run/SOV4014.sh
 +
  regular_run_post_run = /var/spool/sms/regular_run/SOV4014.sh
 +
  regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4014.cmdfile
 +
  regular_run_statfile = /var/spool/sms/regular_run/SOV4014.statfile
 +
 
 +
  [SOV4015]
 +
  device = @ipaddress:4015
 +
  incoming = yes
 +
  regular_run =          /var/spool/sms/regular_run/SOV4015.sh
 +
  regular_run_post_run = /var/spool/sms/regular_run/SOV4015.sh
 +
  regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4015.cmdfile
 +
  regular_run_statfile = /var/spool/sms/regular_run/SOV4015.statfile
 +
 
 +
  [SOV4016]
 +
  device = @ipaddress:4016
 +
  incoming = yes
 +
  regular_run =          /var/spool/sms/regular_run/SOV4016.sh
 +
  regular_run_post_run = /var/spool/sms/regular_run/SOV4016.sh
 +
  regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4016.cmdfile
 +
  regular_run_statfile = /var/spool/sms/regular_run/SOV4016.statfile
 +
 
 +
  # main incoming modem
 +
  [SOV4017]
 +
  device = @ipaddress:4017
 +
  incoming = high
 +
  queues = SOV4017, HALO
 +
  regular_run =          /var/spool/sms/regular_run/SOV4017.sh
 +
  regular_run_post_run = /var/spool/sms/regular_run/SOV4017.sh
 +
  regular_run_cmdfile = /var/spool/sms/regular_run/SOV4017.cmdfile
 +
  regular_run_statfile = /var/spool/sms/regular_run/SOV4017.statfile
 +
 
 +
  [SOV4018]
 +
  device = @ipaddress:4018
 +
  incoming = yes
 +
  regular_run =          /var/spool/sms/regular_run/SOV4018.sh
 +
  regular_run_post_run = /var/spool/sms/regular_run/SOV4018.sh
 +
  regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4018.cmdfile
 +
  regular_run_statfile = /var/spool/sms/regular_run/SOV4018.statfile
 +
 
 +
  [SOV4019]
 +
  device = @ipaddress:4019
 +
  incoming = yes
 +
  regular_run =          /var/spool/sms/regular_run/SOV4019.sh
 +
  regular_run_post_run = /var/spool/sms/regular_run/SOV4019.sh
 +
  regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4019.cmdfile
 +
  regular_run_statfile = /var/spool/sms/regular_run/SOV4019.statfile
 +
 
 +
  [SOV4020]
 +
  device = @ipaddress:4020
 +
  incoming = yes
 +
  regular_run =          /var/spool/sms/regular_run/SOV4020.sh
 +
  regular_run_post_run = /var/spool/sms/regular_run/SOV4020.sh
 +
  regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4020.cmdfile
 +
  regular_run_statfile = /var/spool/sms/regular_run/SOV4020.statfile
 +
 
 +
  [SOV4021]
 +
  device = @ipaddress:4021
 +
  incoming = yes
 +
  regular_run =          /var/spool/sms/regular_run/SOV4021.sh
 +
  regular_run_post_run = /var/spool/sms/regular_run/SOV4021.sh
 +
  regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4021.cmdfile
 +
  regular_run_statfile = /var/spool/sms/regular_run/SOV4021.statfile
 +
 
 +
  [SOV4022]
 +
  device = @ipaddress:4022
 +
  incoming = yes
 +
  regular_run =          /var/spool/sms/regular_run/SOV4022.sh
 +
  regular_run_post_run = /var/spool/sms/regular_run/SOV4022.sh
 +
  regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4022.cmdfile
 +
  regular_run_statfile = /var/spool/sms/regular_run/SOV4022.statfile
 +
 
 +
  [SOV4023]
 +
  device = @ipaddress:4023
 +
  incoming = yes
 +
  regular_run =          /var/spool/sms/regular_run/SOV4023.sh
 +
  regular_run_post_run = /var/spool/sms/regular_run/SOV4023.sh
 +
  regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4023.cmdfile
 +
  regular_run_statfile = /var/spool/sms/regular_run/SOV4023.statfile
 +
 
 +
  [SOV4024]
 +
  device = @ipaddress:4024
 +
  incoming = yes
 +
  regular_run =          /var/spool/sms/regular_run/SOV4024.sh
 +
  regular_run_post_run = /var/spool/sms/regular_run/SOV4024.sh
 +
  regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4024.cmdfile
 +
  regular_run_statfile = /var/spool/sms/regular_run/SOV4024.statfile
 +
 
 +
==Event handler==
 +
This receives and processes incoming SMS messages. Replaced elements include username, ip address and database:
  
== Installing the operating system - Mac ==
+
  #!/bin/bash
# Download the latest [http://www.raspberrypi.org/downloads Raspbian disk image] (fastest via BitTorrent if you have a client) and save it to your hard disk
+
  if [ "$1" != 'RECEIVED' ]; then
# Create a new directory and unzip the image file into the new directory
+
          exit 0;  
# The next bit is quickest using the Terminal window (look in /Applications/Utilities/Terminal) - it only takes half a dozen lines, but requires the password of the Admin user to be enabled - if you don't know what this means you might be best to ask for help.
+
  fi
# First we need to find out the internal name of the SD card to be written. In the terminal window, on a new line, type:
+
  MSGID=$$`date +%s`
df -h
+
  MSG=`cat $2 | sed "s/'/''/g"`
# The lines that read <tt>/dev/disk0s2</tt> refer to a physical disk (ie <tt>disk0</tt>), and a partition on the disk (<tt>s2</tt>). Put a blank 4Gb or greater SD card into the SD card slot of your computer (or an attached USB card reader) and when it appears on the desktop again type:
+
  DBSERVER="ipaddress"
df -h
+
  psql -q -t -h $DBSERVER -U username -v VERBOSITY=terse database << EOF
# You should see a new disk has appeared - note the name of it - for example <tt>/dev/disk1s1</tt>. Using the name you noted, unmount (this is '''not''' the same as eject!) the disk from the operating system:
+
  select sms.sms_parse('$MSG','$1','$MSGID');
sudo diskutil unmount /dev/disk1s1
+
  EOF
# The SD card is now available for overwriting, but you need to put an '''r''' in front of the disk name and drop the '''s1''' part (for example /dev/sdisk1s1 becomes /dev/'''r'''disk1).
+
 
# If you get the above bit wrong, it will either not work at all (disappointing), or overwrite the operating system and all the data on your computer (also disappointing!).
+
  psql \
# Now use dd to copy the new image ('''i'''nput '''f'''ile) onto  the SD card ('''o'''utput '''f'''ile) using:
+
      -h $DBSERVER -U username \
sudo dd bs=1m if=~/Downloads/2013-02-09-wheezy-raspbian.img of=/dev/rdisk
+
      -qtAc "select phone, message, case when priority then 'T' else 'F' end, coalesce(modem,'MAIN') from sms.outbox where msgid = $MSGID"\
#x <- where the x the value you have noted above!
+
      --field-separator '|' \
# This does take some time (9 minutes?) - you can use SIGINFO (Ctrl-T) to see where it is up to.
+
      database| while IFS='|' read -ra Record ; do
# When finished, eject the card:
+
 
sudo diskutil eject /dev/rdisk1
+
      NUM=${Record[0]}
# You can now remove the SD card. To close the terminal window type:
+
      MSG1=${Record[1]}
exit
+
      if [ "${Record[2]}" == 'T' ]; then
 
+
        PRIORITY="\nPriority: High";
 
+
      else
== Connecting and starting the Pi ==
+
        PRIORITY="";
=== Connecting the hardware ===
+
      fi
# Insert the SD card into the slot in the Pi (face down)
+
      QUEUE=${Record[3]}
# Plug in the power to the USB Hub, and insert a USB GSM modem with a SIM card installed. Make sure the SIM card has had PIN protection disabled
+
      TMPFILE=`mktemp /var/spool/sms/outgoing/sms.XXXXX` || exit 1
# Connect the hub to the Pi via a USB cable
+
      echo -e "To: ${NUM}${PRIORITY}\nQueue: ${QUEUE}\n\n$MSG1" > $TMPFILE
# Connect an ethernet cable to the Pi and the network (probably an ethernet router)
+
  done
# Connect the micro USB power cable to a USB power adapter and to the Pi - the lights will start flashing
 
 
 
=== Getting access ===
 
You should be able to access the Pi via SSH to continue the configuration. Use [http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html| PuTTY] or a similar client for this.
 
# Connect to your router or modem and look at the DHCP table to see what address has been assigned to the Pi
 
# In PuTTY, create a connection using SSH to the IP address assigned to the Pi. Start the connection
 
# When prompted enter the user name '''pi''' and password '''raspberry'''
 
 
 
== Expanding the partition ==
 
After installation, Raspbian occupies only 2 Gb. You can expand the partition to use the entire space available, using the raspi-config script.
 
 
sudo raspi-config
 
 
 
A menu will be shown. Tab or down-arrow to select the ''expand_rootfs'' option. This will immediately resize the partition without asking. You need to reboot when asked for the changes to take effect.
 
 
 
== Configuring the software ==
 
=== Updating Aptitude ===
 
Make sure you have the latest software list
 
# sudo apt-get update
 
# sudo apt-get upgrade
 
 
 
=== Install required software ===
 
Install USB Mode Switch, which handles modems that also have a simulated CD drive
 
# sudo apt-get install usb-modeswitch
 
 
 
Install the PostgreSQL client to connect to the server
 
# sudo apt-get install postgresql-client
 
 
 
Install SMS Tools to handle communications
 
# sudo apt-get install smstools
 
 
 
=== Create a user directory ===
 
SMS tools runs under user '''smsd'''. To make life easier connecting to the database server, we'll create a home directory for smsd.
 
make a home directory for smsd user
 
 
 
First we need to give smsd bash access
 
# sudo chsh -s /bin/bash smsd
 
 
 
Then create a home directory
 
# sudo mkdir /home/smsd
 
 
 
Assign appropriate permissions
 
# sudo chown smsd:smsd /home/smsd
 
 
 
Create the password file for PostgreSQL at /home/smsd/.pgpass
 
# sudo nano /home/smsd/.pgpass
 
 
 
Enter just the first line to use the central database, or the second if creating a development machine to use a local database
 
 
 
sms.isikhnas.asia:5432:isikhnas:smsd:password
 
localhost:5432:isikhnas:smsd:password
 
 
 
(replacing password with the real password - but we're not going to record that here, are we)
 
 
 
Lock down the permissions
 
# sudo chown smsd:dialout /home/smsd/.pgpass
 
# sudo chmod 600 /home/smsd/.pgpass
 
 
 
=== Check where the modem is connected ===
 
Disconnect the modem and enter
 
# ls /dev
 
 
 
Connect the modem and enter
 
# ls /dev
 
 
 
Compare the two results. There should be some new entries when the modem is connected, an it is probable on the first of these entries (normally '''ttyUSB0''')
 
 
 
=== Add configuration files ===
 
Edit smsd.conf to look something like this:
 
# sudo nano /etc/smsd.conf
 
 
 
<nowiki>
 
#
 
# /etc/smsd.conf
 
#
 
# Description: Main configuration file for the smsd
 
#
 
 
 
devices = GSM1
 
outgoing = /var/spool/sms/outgoing
 
checked = /var/spool/sms/checked
 
incoming = /var/spool/sms/incoming
 
logfile = /var/log/smstools/smsd.log
 
infofile = /var/run/smstools/smsd.working
 
pidfile = /var/run/smstools/smsd.pid
 
outgoing = /var/spool/sms/outgoing
 
checked = /var/spool/sms/checked
 
failed = /var/spool/sms/failed
 
incoming = /var/spool/sms/incoming
 
sent = /var/spool/sms/sent
 
stats = /var/log/smstools/smsd_stats
 
loglevel = 5
 
#delaytime = 10
 
#errorsleeptime = 10
 
receive_before_send = no
 
# autosplit 0=no 1=yes 2=with text numbers 3=concatenated
 
autosplit = 3
 
# store_received_pdu 0=no, 1=unsupported, 2=unsupported and 8bit, 3=all
 
store_received_pdu = 3
 
store_sent_pdu = 3
 
eventhandler = /home/smsd/sms_in.sh
 
 
 
[GSM1]
 
# Huawei E173
 
init = AT+CNMI=2,1,2,2,0
 
# Huawei E1682
 
# init = AT^CURC=0
 
# init2 = AT+CPMS=\"ME\",\"ME\",\"ME\"
 
device = /dev/ttyUSB0
 
incoming = yes
 
</nowiki>
 
 
 
Note: the initialisation strings are different for each type of modem and are a little problematic. Just Google your model and see what comes up, then use trial and error. Sometimes it appears to be OK, but then won't receive messages so you need to try again.
 
 
 
Create the incoming message handler script
 
# sudo nano /home/smsd/sms_in.sh
 
 
 
  <nowiki>
 
#!/bin/bash
 
MSGID=$$`date +%s`
 
MSG=`cat $2 | sed \"s/'/''/g\"`
 
psql -q -t -h sms.isikhnas.asia isikhnas smsd << EOF
 
select sms.sms_parse('$MSG','$1','$MSGID');
 
EOF
 
/home/smsd/sms_out.sh $MSGID
 
</nowiki>
 
 
 
If using a local development server that has the SMS and PostgreSQL server on the same machine, you can change the fourth line to:
 
 
 
psql -q -t isikhnas smsd << EOF
 
 
 
Create the outgoing message handler script
 
# sudo nano /home/smsd/sms_out.sh
 
 
 
<nowiki>
 
#!/bin/bash
 
 
 
psql \\
 
    -h sms.isikhnas.asia\\
 
    -qtAc \"select phone, message from sms.sms_outbox where msgid = $1\"\\
 
    --field-separator '|' \\
 
    isikhnas | while IFS='|' read -ra Record ; do
 
 
 
    NUM=${Record[0]}
 
    MSG=${Record[1]}
 
    TMPFILE=`mktemp /var/spool/sms/outgoing/sms.XXXXX` || exit 1
 
    echo -e \"To: $NUM\
 
\
 
$MSG\" > $TMPFILE
 
done
 
</nowiki>
 
 
 
If using a local development server that has the SMS and PostgreSQL server on the same machine, you can change the fourth line to:
 
 
 
    -h localhost\\
 
 
 
Make both scripts executable
 
# cd /home/smsd
 
# sudo chown smsd:dialout *.sh
 
# sudo chmod 744 *.sh
 
 
 
== Test the system ==
 
=== Test the modem ===
 
Open a new PuTTY terminal and keep an eye on the smsd.log
 
# sudo tail -f /var/log/smstools/smsd.log
 
 
 
In the original terminal, restart the smsd services
 
# sudo service smstools restart
 
 
 
Check for errors. The output should be something like this:
 
<nowiki>2013-04-04 20:19:35,2, smsd: Smsd v3.1.14 started.
 
2013-04-04 20:19:35,2, smsd: Running as smsd:dialout.
 
2013-04-04 20:19:35,4, smsd: File mode creation mask: 022 (0644, rw-r--r--).
 
2013-04-04 20:19:35,5, smsd: Outgoing file checker has started. PID: 2591.
 
2013-04-04 20:19:35,5, GSM1: Modem handler 0 has started. PID: 2592.
 
2013-04-04 20:19:35,5, GSM1: Using check_memory_method 1: CPMS is used.
 
2013-04-04 20:19:36,3, GSM1: Unexpected input: OK
 
2013-04-04 20:19:40,5, GSM1: CGSN: 860872012247822
 
2013-04-04 20:19:40,5, GSM1: IMSI: 208103691590779
 
</nowiki>
 
 
 
=== Test database connectivity ===
 
Try to access the database server using psql
 
# sudo su smsd
 
# psql -h sms.isikhnas.asia isikhnas
 
 
 
You should get a response something like this:
 
 
 
<nowiki>psql (9.1.8, server 9.2.3)
 
WARNING: psql version 9.1, server version 9.2.
 
        Some psql features might not work.
 
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
 
Type \"help\" for help.
 
 
 
isikhnas=>
 
</nowiki>
 
 
 
To exit from psql, type:
 
isikhnas=> \\q
 
 
 
== Lock down the system ==
 
Add some security so others can't undo all our good work.
 
 
 
=== Changing the user password ===
 
To change the password for the '''pi''' use, you can use the raspi-config script.
 
 
 
# sudo raspi-config
 
 
 
then select the '''change_pass''' option.
 

Revisi terkini pada 2 September 2014 22.11

SMS Server Setup

The SMS server is managed by SMSTools3, and is installed on the Messaging server in the AWS Virtual Private Cloud. A second installation is present on the training (Sidecar) server.

Configuration file

The contents of smsd.conf on the live server are as follows (IP addresss removed)

  1. New Server smsd.conf
 devices = SOV*4009-4024
 
 logfile  = /var/log/smstools/smsd.log
 loglevel = 5
 smart_logging = yes
 
 stats    = /var/spool/sms/stats
 outgoing = /var/spool/sms/outgoing
 checked  = /var/spool/sms/checked
 incoming = /var/spool/sms/incoming
 infofile = /var/run/smstools/smsd.working
 pidfile  = /var/run/smstools/smsd.pid
 failed   = /var/spool/sms/failed
 sent     = /var/spool/sms/sent
 
 errorsleeptime = 3
 # eventhandler for incoming messages
 eventhandler = /home/smsd/sms_in.sh
 # regular run to send new messages with msgid of 0
 regular_run = /home/smsd/sms_rr.sh
 regular_run_interval = 300
 user = smsd
 group = dialout
 
 [queues]
 MAIN = /var/spool/sms/queues/MAIN
 OTHER = /var/spool/sms/queues/OTHER
 HALO = /var/spool/sms/queues/HALO
 SOV4009 = /var/spool/sms/queues/SOV4009
 SOV4010 = /var/spool/sms/queues/SOV4010
 SOV4011 = /var/spool/sms/queues/SOV4011
 SOV4012 = /var/spool/sms/queues/SOV4012
 SOV4013 = /var/spool/sms/queues/SOV4013
 SOV4014 = /var/spool/sms/queues/SOV4014
 SOV4015 = /var/spool/sms/queues/SOV4015
 SOV4016 = /var/spool/sms/queues/SOV4016
 SOV4017 = /var/spool/sms/queues/SOV4017
 SOV4018 = /var/spool/sms/queues/SOV4018
 SOV4019 = /var/spool/sms/queues/SOV4019
 SOV4020 = /var/spool/sms/queues/SOV4020
 SOV4021 = /var/spool/sms/queues/SOV4021
 SOV4022 = /var/spool/sms/queues/SOV4022
 SOV4023 = /var/spool/sms/queues/SOV4023
 SOV4024 = /var/spool/sms/queues/SOV4024
 
 [providers]
 # telkomsel
 MAIN = 62811, 62812, 62813, 62821, 62822, 62823, 62852, 62853
 # non-telkomsel
 OTHER = 628
 # other (primarily interntational - could be expensive so use postpaid)
 HALO = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
 # short numbers - admin.
 SOV4017 = s
 
 [default]
 regular_run_interval = 300
 queues = modemname, MAIN, OTHER
 socket_connection_retries = -1
 socket_connection_errorsleeptime = 20
 socket_connection_alarm_after = 10
 
 [SOV4009]
 device = @ipaddress:4009
 incoming = yes
 regular_run =          /var/spool/sms/regular_run/SOV4009.sh
 regular_run_post_run = /var/spool/sms/regular_run/SOV4009.sh
 regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4009.cmdfile
 regular_run_statfile = /var/spool/sms/regular_run/SOV4009.statfile
 
 [SOV4010]
 device = @ipaddress:4010
 incoming = yes
 regular_run =          /var/spool/sms/regular_run/SOV4010.sh
 regular_run_post_run = /var/spool/sms/regular_run/SOV4010.sh
 regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4010.cmdfile
 regular_run_statfile = /var/spool/sms/regular_run/SOV4010.statfile
 
 [SOV4011]
 device = @ipaddress:4011
 incoming = yes
 regular_run =          /var/spool/sms/regular_run/SOV4011.sh
 regular_run_post_run = /var/spool/sms/regular_run/SOV4011.sh
 regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4011.cmdfile
 regular_run_statfile = /var/spool/sms/regular_run/SOV4011.statfile
 
 [SOV4012]
 device = @ipaddress:4012
 incoming = yes
 regular_run =          /var/spool/sms/regular_run/SOV4012.sh
 regular_run_post_run = /var/spool/sms/regular_run/SOV4012.sh
 regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4012.cmdfile
 regular_run_statfile = /var/spool/sms/regular_run/SOV4012.statfile
 
 [SOV4013]
 device = @ipaddress:4013
 incoming = yes
 regular_run =          /var/spool/sms/regular_run/SOV4013.sh
 regular_run_post_run = /var/spool/sms/regular_run/SOV4013.sh
 regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4013.cmdfile
 regular_run_statfile = /var/spool/sms/regular_run/SOV4013.statfile
 
 [SOV4014]
 device = @ipaddress:4014
 incoming = yes
 regular_run =          /var/spool/sms/regular_run/SOV4014.sh
 regular_run_post_run = /var/spool/sms/regular_run/SOV4014.sh
 regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4014.cmdfile
 regular_run_statfile = /var/spool/sms/regular_run/SOV4014.statfile
 
 [SOV4015]
 device = @ipaddress:4015
 incoming = yes
 regular_run =          /var/spool/sms/regular_run/SOV4015.sh
 regular_run_post_run = /var/spool/sms/regular_run/SOV4015.sh
 regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4015.cmdfile
 regular_run_statfile = /var/spool/sms/regular_run/SOV4015.statfile
 
 [SOV4016]
 device = @ipaddress:4016
 incoming = yes
 regular_run =          /var/spool/sms/regular_run/SOV4016.sh
 regular_run_post_run = /var/spool/sms/regular_run/SOV4016.sh
 regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4016.cmdfile
 regular_run_statfile = /var/spool/sms/regular_run/SOV4016.statfile
 
 # main incoming modem
 [SOV4017]
 device = @ipaddress:4017
 incoming = high
 queues = SOV4017, HALO
 regular_run =          /var/spool/sms/regular_run/SOV4017.sh
 regular_run_post_run = /var/spool/sms/regular_run/SOV4017.sh
 regular_run_cmdfile = /var/spool/sms/regular_run/SOV4017.cmdfile
 regular_run_statfile = /var/spool/sms/regular_run/SOV4017.statfile
 
 [SOV4018]
 device = @ipaddress:4018
 incoming = yes
 regular_run =          /var/spool/sms/regular_run/SOV4018.sh
 regular_run_post_run = /var/spool/sms/regular_run/SOV4018.sh
 regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4018.cmdfile
 regular_run_statfile = /var/spool/sms/regular_run/SOV4018.statfile
 
 [SOV4019]
 device = @ipaddress:4019
 incoming = yes
 regular_run =          /var/spool/sms/regular_run/SOV4019.sh
 regular_run_post_run = /var/spool/sms/regular_run/SOV4019.sh
 regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4019.cmdfile
 regular_run_statfile = /var/spool/sms/regular_run/SOV4019.statfile
 
 [SOV4020]
 device = @ipaddress:4020
 incoming = yes
 regular_run =          /var/spool/sms/regular_run/SOV4020.sh
 regular_run_post_run = /var/spool/sms/regular_run/SOV4020.sh
 regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4020.cmdfile
 regular_run_statfile = /var/spool/sms/regular_run/SOV4020.statfile
 
 [SOV4021]
 device = @ipaddress:4021
 incoming = yes
 regular_run =          /var/spool/sms/regular_run/SOV4021.sh
 regular_run_post_run = /var/spool/sms/regular_run/SOV4021.sh
 regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4021.cmdfile
 regular_run_statfile = /var/spool/sms/regular_run/SOV4021.statfile
 
 [SOV4022]
 device = @ipaddress:4022
 incoming = yes
 regular_run =          /var/spool/sms/regular_run/SOV4022.sh
 regular_run_post_run = /var/spool/sms/regular_run/SOV4022.sh
 regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4022.cmdfile
 regular_run_statfile = /var/spool/sms/regular_run/SOV4022.statfile
 
 [SOV4023]
 device = @ipaddress:4023
 incoming = yes
 regular_run =          /var/spool/sms/regular_run/SOV4023.sh
 regular_run_post_run = /var/spool/sms/regular_run/SOV4023.sh
 regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4023.cmdfile
 regular_run_statfile = /var/spool/sms/regular_run/SOV4023.statfile
 
 [SOV4024]
 device = @ipaddress:4024
 incoming = yes
 regular_run =          /var/spool/sms/regular_run/SOV4024.sh
 regular_run_post_run = /var/spool/sms/regular_run/SOV4024.sh
 regular_run_cmdfile =  /var/spool/sms/regular_run/SOV4024.cmdfile
 regular_run_statfile = /var/spool/sms/regular_run/SOV4024.statfile
 

Event handler

This receives and processes incoming SMS messages. Replaced elements include username, ip address and database:

 #!/bin/bash
 if [ "$1" != 'RECEIVED' ]; then
         exit 0;  
 fi
 MSGID=$$`date +%s`
 MSG=`cat $2 | sed "s/'//g"`
 DBSERVER="ipaddress"
 psql -q -t -h $DBSERVER -U username -v VERBOSITY=terse database << EOF
 select sms.sms_parse('$MSG','$1','$MSGID');
 EOF
 
 psql \
     -h $DBSERVER -U username \
     -qtAc "select phone, message, case when priority then 'T' else 'F' end, coalesce(modem,'MAIN') from sms.outbox where msgid = $MSGID"\
     --field-separator '|' \
     database| while IFS='|' read -ra Record ; do
 
     NUM=${Record[0]}
     MSG1=${Record[1]}
     if [ "${Record[2]}" == 'T' ]; then
       PRIORITY="\nPriority: High";
     else
       PRIORITY="";
     fi
     QUEUE=${Record[3]}
     TMPFILE=`mktemp /var/spool/sms/outgoing/sms.XXXXX` || exit 1
     echo -e "To: ${NUM}${PRIORITY}\nQueue: ${QUEUE}\n\n$MSG1" > $TMPFILE
 done