SMS Server Tools 3
 Menu
Basic information:
Additional information:
Support:
Get SMS Server Tools 3:
Additional Options

 Sponsored links

 Search
Custom Search

 Visitor locations
 
 SMS Server Tools 3 Community
Welcome, Guest. The forum is currently read-only, but will open soon. Thu Nov 21, 2024 12:50
SMSTools3 Community » Sample scripts / setups Bottom

How to create config for failover smsd.conf?

Login and Post Reply

Page:  1

Author Post
Member
Registered:
Nov 2020
Location: SE, Sweden
I plan to use 2 modems connected to one server. How should the smsd.conf look like?

GSM1 should be prio1 and GSM2 only if GSM1 fails.

If GSM1 send files into /failed/ folder i should be picked up by GSM2.


Is it a way of solving this or in some other way?


Running smstools
Arch : x86_64
Version : 3.1.19.9

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
Failover device configuration needs queues and eventhandler script:

Smsd.conf global section:

eventhandler = /usr/local/bin/smsd_eventhandler

[queues]
GSM1 = /var/spool/sms/GSM1
GSM2 = /var/spool/sms/GSM2

[providers]
GSM1 = 0,1,2,3,4,5,6,7,8,9,s
GSM2 = 0

Smsd.conf modem sections:

[GSM1]
queues = GSM1

[GSM2]
queues = GSM2

With this kind of configuration GSM1 is used to send all messages (which are not specifically targeted to GSM2).

When sending fails, eventhandler script is called with "FAILED" as a first argument. Eventhandler code can check if a message was not already tried to send using GSM2, and if it was not, message can be moved back to the spooler with Queue: GSM2 header.

For example:
#!/bin/bash

if [ "$1" = "FAILED" ]; then

  # Check if there was Queue defined:
  queue=`formail -zx Queue: < $2`

  if [ "x$queue" != "xGSM2" ]; then

    # Was not already handled using GSM2.

    # Create a new message file:
    FILE=`mktemp /tmp/send_XXXXXX`

    # Copy a message and insert a Queue: header:
    formail -f -I "Queue: GSM2" < $2 > $FILE

    # Move message back to the spooler:
    FILE2=`mktemp /var/spool/sms/outgoing/send_XXXXXX`
    mv $FILE $FILE2

  fi
fi
 
'bash' Syntax Highlight powered by GeSHi


To use this example, the formail command is required. If your system does not have it, install the procmail package. You can also write the eventhandler in any other language you want.

Member
Registered:
Nov 2020
Location: SE, Sweden
Topic owner
Thanks for the answer. cannot get it to work though. Seems like the send_xyz files not movs to queue GSM2. Any ideas about that?

[root@test ~]# more /etc/smsd.conf
smart_logging=yes
eventhandler = /usr/local/bin/smsd_eventhandler
#loglevel=5
loglevel=8
failed=/var/spool/sms/failed
receive_before_send=no
delaytime=10
blocktime=10
infofile=/var/run/smsd.working
user=root
incoming=/var/spool/sms/incoming
sent=/var/spool/sms/sent
errorsleeptime=10
logfile=/var/log/smsd/smsd.log
stats_interval=3600
stats=/var/log/smsd/smsd_stats
autosplit=yes
devices=GSM1,GSM2
alarmlevel=4
pidfile=/var/run/smsd.pid
spool=/var/spool/sms/outgoing

[queues]
GSM1 = /var/spool/sms/GSM1
GSM2 = /var/spool/sms/GSM2


[GSM1]
queues = GSM1
cs_convert=yes
baudrate=115200
#pin=3342
report=no
mode=new
incoming=no
#device=/dev/ttyr01
device=@192.168.2.20:4001
#check_network=no
#queues=OTHER
rtscts=no
pre_init=no
init=ATE0
report = yes
report_device_details = yes

[GSM2]
queues = GSM2
cs_convert=yes
baudrate=115200
pin=ignore
report=no
mode=new
incoming=no
#device=/dev/ttyr01
device=@192.168.2.21:4001
#check_network=no
#queues=OTHER
rtscts=no
pre_init=no
init=ATE0
report = yes
report_device_details = yes


[providers]
GSM1=0, 1, 2, 3, 4, 5, 6, 7, 8, 9,s
GSM2=0
[root@test ~]#
[root@test ~]#
[root@test ~]#
[root@test ~]# more /usr/local/bin/smsd_eventhandler
#!/bin/bash

if [ "$1" = "FAILED" ]; then

# Check if there was Queue defined:
queue=`formail -zx Queue: < $2`

if [ "x$queue" != "xGSM2" ]; then

# Was not already handled using GSM2.

# Create a new message file:
FILE=`mktemp /tmp/send_XXXXXX`

# Copy a message and insert a Queue: header:
formail -f -I "Queue: GSM2" < $2 > $FILE

# Move message back to the spooler:
FILE2=`mktemp /var/spool/sms/outgoing/send_XXXXXX`
mv $FILE $FILE2

fi
fi
[root@test ~]#
[root@test ~]#
[root@test ~]# ls -la /var/spool/sms/*/
/var/spool/sms/checked/:
total 0
drwxr-x---. 2 smstools smstools 6 Nov 11 16:58 .
drwxr-xr-x. 9 smstools smstools 103 Nov 13 11:43 ..

/var/spool/sms/failed/:
total 0
drwxr-xr-x. 2 smstools smstools 6 Nov 18 13:19 .
drwxr-xr-x. 9 smstools smstools 103 Nov 13 11:43 ..

/var/spool/sms/GSM1/:
total 12
drwxr-xr-x 2 smstools smstools 63 Nov 18 13:20 .
drwxr-xr-x. 9 smstools smstools 103 Nov 13 11:43 ..
-rw-r--r-- 1 smstools smstools 19 Nov 18 12:18 send_P02tA3
-rw-r--r-- 1 smstools smstools 19 Nov 18 13:20 send_Xbm8qV
-rw-r--r-- 1 smstools smstools 19 Nov 18 13:12 send_XU0eLK

/var/spool/sms/GSM2/:
total 0
drwxr-xr-x 2 smstools smstools 6 Nov 18 13:19 .
drwxr-xr-x. 9 smstools smstools 103 Nov 13 11:43 ..

/var/spool/sms/incoming/:
total 0
drwxr-x---. 2 smstools smstools 6 Nov 18 13:19 .
drwxr-xr-x. 9 smstools smstools 103 Nov 13 11:43 ..

/var/spool/sms/outgoing/:
total 0
drwxrwx---. 2 smstools smstools 6 Nov 18 13:20 .
drwxr-xr-x. 9 smstools smstools 103 Nov 13 11:43 ..

/var/spool/sms/sent/:
total 8
drwxr-x---. 2 smstools smstools 44 Nov 18 13:19 .
drwxr-xr-x. 9 smstools smstools 103 Nov 13 11:43 ..
-rw-r--r-- 1 smstools smstools 99 Nov 18 11:07 send_hSXKbq
-rw-r--r-- 1 smstools smstools 99 Nov 18 13:15 send_itMUFn
[root@test ~]#

Member
Registered:
Nov 2020
Location: SE, Sweden
Topic owner
Sorry it works if send_xyz is forwarded to folder /var/spool/sms/failed . But if I remove GSM1 modem so only GSM2 is online the send_xyz stays in folder /var/spool/sms/GSM1 and it will not be handled by queue GSM2.

Is it a way of solving this?

Kind regards.

Member
Registered:
Nov 2020
Location: SE, Sweden
Topic owner
I can see what's happening now.

If GSM1 lost network connection and while that happens sending an sms. The following happens:

The first sms is correctly sent by GSM2 as the eventhandler should but then the modem disconnects.

2020-11-19 22:21:46,6, GSM2: SMS To: 12345667. Moved file /var/spool/sms/GSM2/send_s0uf88 to /var/spool/sms/sent/send_s0uf88
2020-11-19 22:21:46,7, GSM2: Running eventhandler: /usr/local/bin/smsd_eventhandler SENT /var/spool/sms/sent/send_s0uf88 209
2020-11-19 22:21:46,7, GSM2: Done: eventhandler, execution time 0 sec., status: 0 (0)
2020-11-19 22:21:48,3, GSM1: Couldn't connect socket @192.168.2.20:4001, error: No route to host, waiting 5 sec.
2020-11-19 22:21:56,6, GSM1: Couldn't connect socket @192.168.2.20:4001, error: No route to host, waiting 5 sec.
...
...
2020-11-19 22:22:35,5, smsd: SMS To: 1234567. Moved file /var/spool/sms/outgoing/send_Qb08Qt to /var/spool/sms/GSM1
2020-11-19 22:22:36,6, GSM1: Couldn't connect socket @192.168.2.20:4001, error: No route to host, waiting 5 sec.
2020-11-19 22:22:44,6, GSM1: Couldn't connect socket @192.168.2.20:4001, error: No route to host, waiting 5 sec.
2020-11-19 22:22:52,6, GSM1: Couldn't connect socket @192.168.2.20:4001, error: No route to host, waiting 5 sec.
2020-11-19 22:23:00,6, GSM1: Couldn't connect socket @192.168.2.20:4001, error: No route to host, waiting 5 sec.
2020-11-19 22:23:08,6, GSM1: Couldn't connect socket @192.168.2.20:4001, error: No route to host, waiting 5 sec.
2020-11-19 22:23:16,3, GSM1: Cannot open socket @192.168.2.20:4001, error: No route to host
2020-11-19 22:23:16,2, GSM1: Modem handler 0 terminated. PID: 23382, was started 20-11-19 22:17:53, up 5 min.
2020-11-19 22:23:16,2, smsd: Modem handler 0 (GSM1) terminated while mainprocess is still running. Exited, status 127.

After that every sms is stuck in the GSM1 queue.


Can I in some way check for the string 2020-11-19 22:23:16,2, smsd: Modem handler 0 (GSM1) terminated while mainprocess is still running. Exited, status 127.


and force restart of smsd in the eventhandler?

Login and Post Reply

Page:  1

SMSTools3 Community » Sample scripts / setups Top

 
Time in this board is UTC.  

Privacy Policy   SMS Server Tools 3 Copyright © Keijo Kasvi.