SMS Server Tools 3
This site is hosted by Kekekasvi.com
 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. Please login or register. Sat May 25, 2024 11:24
SMSTools3 Community » Help and support Bottom

[outdated] Restart smsd

  This topic is locked

Page:  1

Author Post
Member
Registered:
Apr 2010
Location: Malaysia
Operating system name and version: Linux CentOS 4.8
Version of smsd: 3.1.6
Smsd installed from: sources
Name and model of a modem / phone: Wavecomm Fastrak Supreme 10
Interface: Serial


My eventhandler is written such that it processes RECEIVED messages. The script will then send me a text to confirm.

Just now, I sent in a text message and I waited for several minutes (no confirmation received from my eventhandler) before deciding to open up my log and noticed this:



I restarted smsd (without any changes to eventhandler) and this time the eventhandler script confirmed that it processes the instruction and sent me a text msg that I have received. Here is the log:



I wonder why I need to restart smsd. Would an upgrade to 3.1.11 be a good idea or am I missing something obvious here. Appreciate some thoughts. TIA.

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
I think that upgrading to 3.1.11 does not make any difference.

Perhaps you have "exit 1" somewhere in your eventhandler, which usually is not correct. As I cannot guess what your code does, you could show the code here.

Member
Registered:
Apr 2010
Location: Malaysia
Topic owner
keke wrote
Perhaps you have "exit 1" somewhere in your eventhandler, which usually is not correct.

I have a few of those actually. Wonder if I need to replace those with just exit ?

Anyway,
#!/bin/bash
# 1. Helpdesk admin fillup webform when there is a problem with a PC
# 2. Information will be sent via SMS to a technician
# 3. Then technician will acknowledge receipt of the SMS alert by replying with
#    log ticket-number receive
# eg log 123 receive
#
# 4. When done, technician will send another SMS to close the ticket and also what action were taken with
#    log ticket-number done action-taken
# eg log 123 done replace hard drive

if [ "$1" != "RECEIVED" ]; then exit; fi;

#general function to send SMS
sendsms ()
{
FILENAME=`mktemp /var/spool/sms/outgoing/answerXXXXXX`
echo "To: $1" >$FILENAME
echo "" >> $FILENAME
echo "** HELP DESK **" >>$FILENAME
echo "" >> $FILENAME
echo "$2" >>$FILENAME
}


#Extract data from the SMS file
FROM=`formail -zx From: < $2`
TEXT=`formail -I "" <$2 | sed -e"1d"`


#put content of TEXT into an array named PARAM
PARAM=($TEXT)
ARGS=${#PARAM[@]}

#convert to lowercase
LOG_TEXT="$(echo ${PARAM[0]} | tr 'A-Z' 'a-z')"
TICKET_NUMBER=${PARAM[1]}
RECEIVE_OR_DONE_TEXT="$(echo ${PARAM[2]} | tr 'A-Z' 'a-z')"

if [ $LOG_TEXT = 'log' ]; then
  #ticket MUST be integer
  if [ "$TICKET_NUMBER" -ge 0 -o "$TICKET_NUMBER" -lt 0 2>/dev/null ]; then

    #check if that ticket number exist in the first place
    EXIST=`mysql -uroot -pnosecret ticket -s -e "select count(*) from tickets where id=$TICKET_NUMBER;"`
    if [ $EXIST -gt 0 ]; then
      case $RECEIVE_OR_DONE_TEXT in
        receive)
          ARR=`mysql -uroot -pnosecret ticket -s -e "select t1.amid,t1.amname,t2.title from tickets as t1,members as t2 where t1.id=$TICKET_NUMBER and t1.amid=t2.id ;"`
          detail=($ARR)
          TECH_ID=${detail[0]}
          TECH_NAME=${detail[1]}
          TECH_MOBILE=${detail[2]}

          #send technician a msg on how to close this ticket
          sendsms "$FROM" "$TECH_NAME acknowledged receipt of ticket number: $TICKET_NUMBER

After your job is done, pls close this ticket with
log $TICKET_NUMBER done
and send it to 60193522587"


          exit 0
          ;;

        done)
          #Is this person have rights to close this particular ticket?
          ARR=`mysql -uroot -pnosecret ticket -s -e "select t1.amid,t1.amname,t2.title from tickets as t1,members as t2 where t1.id=$TICKET_NUMBER and t1.amid=t2.id ;"`
          detail=($ARR)
          TECH_ID=${detail[0]}
          TECH_NAME=${detail[1]}
          TECH_MOBILE=${detail[2]}

          if [ $TECH_MOBILE -ne $FROM ] || [ ${#ARR} = 0 ]; then
            #No perm error
            sendsms "$FROM" "You have no permission to close ticket $TICKET_NUMBER"
            exit 1
          else


            #check number of arguments
            if [ $ARGS -lt 4 ]; then
              sendsms "$FROM" "arg = $ARGS  Please indicate what action(s) were taken to resolve ticket number $TICKET_NUMBER"
              exit 1
            else
              ACTION_TAKEN=""
              for ((i=3; i<=$ARGS ; i++))  # log 123 done changed hard disk
              do
                  ACTION_TAKEN=$ACTION_TAKEN"${PARAM[$i]} "  #concatenation
              done
            fi


            result=$(mysql -uroot -pnosecret ticket -sN -e "update tickets set status=6,close_mid=$TECH_ID,close_mname='$TECH_NAME' where id=$TICKET_NUMBER;")

            #Acknowlege the close ticket request
            sendsms "$FROM" "$TECH_NAME have succssfully closed ticket number $TICKET_NUMBER
action taken: $ACTION_TAKEN"


            exit 0
          fi
          ;;

        *)
          #Must be an error at the 3rd parameter. No SMS sent, just silent
          exit 1;
      esac
    else
      sendsms "$FROM" "Directive Error: Ticket $TICKET_NUMBER does not exist"
      exit 1;
    fi
  else
    #Ticket number was not an integer. No SMS sent, just silent
    exit 1;
  fi
else
  #Must be an error at the 1st parameter. No SMS sent, just silent
  exit 1;
fi
 
 
'bash' Syntax Highlight powered by GeSHi


Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
almangkok wrote
keke wrote
Perhaps you have "exit 1" somewhere in your eventhandler, which usually is not correct.

I have a few of those actually. Wonder if I need to replace those with just exit ?

Anyway,

Yes, exit or exit 0 is good.

In your first post in this topic, no confirmation was received because there has been a "No SMS sent, just silent" case. Perhaps you should log those cases, to avoid confusions. This kind of a code could be used, as an example:

#!/bin/bash

APPNAME="smsd_eventhandler"
LOGFILENAME="/var/log/smsd_eventhandler.log"

#--------------------------------------------------------------------------
write_log()
{
  local DATE=`date +"%Y-%m-%d %T"`
  echo "$DATE,7, $APPNAME: $1" >> $LOGFILENAME
}
#--------------------------------------------------------------------------

...

else
  #Must be an error at the 1st parameter. No SMS sent, just silent
  write_log "Error at the 1st parameter. ${FROM}. ${TEXT}"
  exit
fi
 
'bash' Syntax Highlight powered by GeSHi


Another thing: you are creating outgoing files directly to the outgoing directory. This usually works, but may cause conflicts. It's better to create files to the /tmp directory (in the same partition where outgoing directory is), and move file when it's complete:



I have also changed echo "$2" to echo -n "$2", because without -n there will be an extra linefeed which may cause that length goes over 160 characters. Version 3.1.6 does not strip trailing whitespaces, later versions will do it.

Member
Registered:
Apr 2010
Location: Malaysia
Topic owner
Man I learnt alot today. I will implement the changes asap. And thank you so much for your advises Keke.

Member
Registered:
Apr 2010
Location: Malaysia
Topic owner
I noticed that, initially, the problem came when smsd was idle for several hours. I have incorporated all changes and will report here soon if things are stable.

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
almangkok wrote
I noticed that, initially, the problem came when smsd was idle for several hours.

The idle time should not have any effect. Perhaps some external command like formail has become unavailable, but this is very unusual.

You had a message:
2010-08-03 10:54:19,6, GSM1: Wrote an incoming message file: /var/spool/sms/incoming/GSM1.aKjwsO

Is this file still available and can you check if the syntax of message is correct?

Member
Registered:
Apr 2010
Location: Malaysia
Topic owner
keke wrote
You had a message:
2010-08-03 10:54:19,6, GSM1: Wrote an incoming message file: /var/spool/sms/incoming/GSM1.aKjwsO

Is this file still available and can you check if the syntax of message is correct?

Yes it is still available and the syntax is correct.

OK I came to office early today to run another test. To summarized:
1. Launch help desk system and fillup web form, hit Submit button
2. I received the SMS that was sent
3. I read the SMS, ticket number is 92 and decided to acknowledge receipt
4). I sent an SMS: log 92 receive
5. I received an SMS that notified me that ticket 92 does NOT exist
6. I ran mysql thru command line and confirmed that the ticket exist, the ticket status on help desk system showed Open
(meaning update has NOT taken place in database)
7. I restarted smsd
8. I sent another SMS to acknowledge receipt of ticket 92: log 92 receive
9. This time round I received an SMS notifying me that I have acknowledged receipt of ticket 92. Help desk system showed ticket status as Acknowledged
(meaning update has taken place in database)
10. I am now very confused :|

Here are some truncated log messages from some of the steps above, and hope they can shed some light on the problem:

After step 5), /var/log/smsd.log shows


and /var/log/smsd_eventhandler.log shows


Ran mysql to confirm that ticket 92 does exist:


Restarted smsd


Looks OK:


This is /var/log/smsd.log after step 9)


and /var/log/smsd_eventhandler.log shows:


If there is/are anything wrong with my eventhandler script, then things should not have work out even if I restarted smsd. I was hoping that there is something that I can do to fix the eventhandler script. But I also agree with you that the idle time should not have any effect, yet after restarting smsd, things work the way they should.

Here is my eventhandler script, just in case:
 
'bash' Syntax Highlight powered by GeSHi


Member
Registered:
Apr 2010
Location: Malaysia
Topic owner
... and this is my smsd.conf


Member
Registered:
Apr 2010
Location: Malaysia
Topic owner
I decided to try out and restart smsd every hour via cron:
0 * * * * /etc/init.d/sms3 restart

Then got this mail


BUT surprisingly, whenever I sent

log 94 receive

I got a reply saying that ticket 94 does not exist. I tried a few variant with cron like changing restart with reset and also stop followed by start, BUT they all gave identical result.

BUT if I were to restart smsd thru the command line, everything works fine. I am running out of idea. Please please help. Dateline is nearing :(

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
almangkok wrote
I decided to try out and restart smsd every hour via cron:
0 * * * * /etc/init.d/sms3 restart

Then got this mail



When smsd received a termination signal, it was checking for incoming messages. Because of this, it did not terminate within one second. This caused the message. While sms3 was waiting for termination after message, smsd terminated in one second (single dot). This is completely normal. If you continue using cron, you could call the script with "> /dev/null 2>&1".

almangkok wrote
BUT surprisingly, whenever I sent

log 94 receive

I got a reply saying that ticket 94 does not exist. I tried a few variant with cron like changing restart with reset and also stop followed by start, BUT they all gave identical result.

BUT if I were to restart smsd thru the command line, everything works fine. I am running out of idea. Please please help. Dateline is nearing :(

I believe that it is a coincidence. It should not matter how sms3 is called.

When your system works fine, how many messages you can handle before the problem starts? This could give some kind of clue.

It seems that the problem is related with mysql. Your call in the eventhandler is correct, but it still does not return "1" even when there is a record available (if there really is). You could add some kind of retry to the code, if [ $EXIST -lt 1 ]; then wait couple of seconds and try again. If the result still is zero, collect some logs like tail -50 /var/log/mysql/mysql.log >> your.log. With this you can see if the call is actually done or not.

Eventhandler is a sub-process for the modem process. Restarting smsd should not have anything to do with this problem. The problem is elsewhere, but I'm unable to tell right now where the problem is.

When you run your test, can you check the database before sending the SMS acknowledge? Is it completely sure that the ticket exists, and there is no remarkable delays when a record is initially created?

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
almangkok wrote
Please please help. Dateline is nearing :(

Is this problem still active?

I have created a database which has required fields, and my smsd was running your eventhandler. No answers were sent, and incoming SMS were taken from pdu_from_file. Cron job created this file once per minute with a content "log 94 receive". It has now been running nearly two days. More than 2500 acknowledges were handled, and all without problems.

If your database surely contains a ticket when it's queried, you have unstable installation of mysql.

Member
Registered:
Apr 2010
Location: Malaysia
Topic owner
keke wrote
Is this problem still active?

Hi Keke,
Yes the problem is still active. I was outstation for 2 days to attend to some family problem. Hence I was offline during that time.

keke wrote
If your database surely contains a ticket when it's queried, you have unstable installation of mysql.

Yes I CONFIRMED that the database contain that ticket number. I am conducting more tests now actually. And thank you for your tips.

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
almangkok wrote
keke wrote
If your database surely contains a ticket when it's queried, you have unstable installation of mysql.

Yes I CONFIRMED that the database contain that ticket number. I am conducting more tests now actually. And thank you for your tips.

Ok. While testing, use the default value for check_memory_method. Define pdu_from_file = /var/spool/sms/GSM1_pdu. Use the PDU Converter to create a PDU. For example, with receiver 123 it could be (Log 92 receive):

001100039121F30000FF0ECCF719949381E4E571396D2F03

Change the eventhandler: when sending SMS, check the number and skip actual sending if a message was a test message:

if [ "$1" != "123" ]; then
FILENAME2=`mktemp /var/spool/sms/outgoing/answerXXXXXX`
mv $FILENAME $FILENAME2
fi

With these changes you can "receive" messages without needing to send anything to your device. Just put the PDU into the file /var/spool/sms/GSM1_pdu.

  This topic is locked

Page:  1

SMSTools3 Community » Help and support Top

 
Time in this board is UTC.  

Privacy Policy   SMS Server Tools 3 Copyright © Keijo Kasvi.