LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 06-25-2007, 11:39 AM   #1
murray_linux
Member
 
Registered: Nov 2003
Distribution: Slackware Current
Posts: 210

Rep: Reputation: 30
scripting help: how to restart an application that fails to start sometimes?


Hi Everyone,

I've created a script to restart the mouse/keyboard sharing application "synergy". i use cron to run this script every hour, because there is a known issue with the current version of synergy where the copy/paste function fails after a period of time, and the only known workaround is to restart the app.

the script works 50% of the time, other times, synergy does not start up. running dmesg, i see this error message:

synergys[17128]: segfault at 0000000000000009 rip 00000000004424da rsp 00007fff305648b0 error 4

i wonder, first, does anyone know why this would be happening, and second, is there a way to make my script retry launching the application again if it fails to start? (kinda new to scripting).

here is the script i am using to restart synergy:

#!/bin/sh
/usr/bin/killall synergys
synergys --config synergy.conf

Thanks,

Murray
 
Old 06-25-2007, 12:27 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,446
Blog Entries: 54

Rep: Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890
I'd suggest running an automated process checker like Monit instead. Dunno bout the seg.


Code:
#!/bin/sh
runMe() { synergys --config synergy.conf || runMe; }
pgrep -lf "synergys --conf" /dev/null 2>&1 && killall synergys
runMe
exit 0

Last edited by unSpawn; 06-25-2007 at 12:36 PM.
 
Old 06-25-2007, 12:55 PM   #3
murray_linux
Member
 
Registered: Nov 2003
Distribution: Slackware Current
Posts: 210

Original Poster
Rep: Reputation: 30
thanks,

the thing is, synergy isn't going down automatically. it will stay up and running no problem. i am manually restarting it every hour because of a known issue, and it only happens to start every second time or so. that script looks like it just checks to see if it stops and restarts it automatically, am i right?
 
Old 06-25-2007, 01:07 PM   #4
almatic
Member
 
Registered: Mar 2007
Distribution: Debian
Posts: 547

Rep: Reputation: 67
maybe like that ?

Code:
#!/bin/bash

PCHECK=$(ps -A | grep synergys)

while [ "$PCHECK" = "" ]
do
     synergys --config synergy.conf &
     sleep 2
     PCHECK=$(ps -A | grep synergys)
done
it will check if the process is running and, if not, will restart it until it's finally running .

edit: sorry, forgot to delete the if-stuff.

Last edited by almatic; 06-25-2007 at 01:18 PM.
 
Old 06-25-2007, 05:45 PM   #5
rupertwh
Member
 
Registered: Sep 2006
Location: Munich, Germany
Distribution: Debian / Ubuntu
Posts: 297

Rep: Reputation: 49
Quote:
Originally Posted by murray_linux
#!/bin/sh
/usr/bin/killall synergys
synergys --config synergy.conf
Hi, maybe the problem is that the process isn't killed properly and somehow keeps the new process from starting successfully. You restart immediately after sending it a kill signal. Maybe the process just needs a bit more time to terminate or doesn't terminate at all and needs a -KILL.
 
Old 06-25-2007, 06:55 PM   #6
murray_linux
Member
 
Registered: Nov 2003
Distribution: Slackware Current
Posts: 210

Original Poster
Rep: Reputation: 30
interesting.. how would i add a 1 second or so wait time to my script?
 
Old 06-25-2007, 07:04 PM   #7
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,211

Rep: Reputation: 292Reputation: 292Reputation: 292
sleep 1

damn 10 character post limit
 
Old 06-25-2007, 07:07 PM   #8
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,211

Rep: Reputation: 292Reputation: 292Reputation: 292
Maybe you could also add a loop

while [[ ! `pgrep synergy` ]]
do
synergy --config synergy.conf
done

Last edited by dive; 06-25-2007 at 07:13 PM.
 
Old 06-26-2007, 10:21 AM   #9
murray_linux
Member
 
Registered: Nov 2003
Distribution: Slackware Current
Posts: 210

Original Poster
Rep: Reputation: 30
i like the loop, im gonna give it a shot, i'll let you know how it goes.

Thanks
 
Old 06-26-2007, 11:13 AM   #10
murray_linux
Member
 
Registered: Nov 2003
Distribution: Slackware Current
Posts: 210

Original Poster
Rep: Reputation: 30
the loop didn't seem to work for some reason.. here's my script:

#!/bin/bash

/usr/bin/killall synergys

#synergys --config /home/mhachey/synergy.conf

while [[ ! `pgrep synergy` ]]

do

synergys --config /home/mhachey/synergy.conf

done


i'm going to try the pause now.
 
Old 06-26-2007, 11:57 AM   #11
rupertwh
Member
 
Registered: Sep 2006
Location: Munich, Germany
Distribution: Debian / Ubuntu
Posts: 297

Rep: Reputation: 49
Quote:
Originally Posted by murray_linux
the loop didn't seem to work for some reason.. here's my script:
[...]
i'm going to try the pause now.
Well the loop didn't make too much sense that way. You should combine the two:

Code:
#!/bin/bash

killall synergys

# check every second if it's still there for e.g. 10 seconds:
COUNT=10
while [ $COUNT -gt 0 ] ; do

    if ! pgrep synergys ; then
        synergys --config /home/mhachey/synergy.conf
        exit 0
    fi

    sleep 1

    COUNT=$((COUNT-1))

    # get rough if it's still there after 5 seconds:
    if [ $COUNT -eq 5 ] ; then
        killall -KILL synergys
    fi

done

echo Giving up. 
exit 1
 
Old 06-26-2007, 12:06 PM   #12
murray_linux
Member
 
Registered: Nov 2003
Distribution: Slackware Current
Posts: 210

Original Poster
Rep: Reputation: 30
the sleep didn't work either, i'll give the new script a shot.

Thanks!
 
Old 06-26-2007, 01:08 PM   #13
murray_linux
Member
 
Registered: Nov 2003
Distribution: Slackware Current
Posts: 210

Original Poster
Rep: Reputation: 30
no luck, the same issue is happening...

[96926.442155] synergys[16127]: segfault at 0000000000000009 rip 00000000004424da rsp 00007fff0d40b790 error 4
 
Old 06-26-2007, 01:59 PM   #14
dawkcid
Member
 
Registered: May 2007
Location: UK
Distribution: LFS,Slackware,Slamd64,NetBSD
Posts: 102

Rep: Reputation: 15
A segfault means either you have hardware problems (unlikely if everything else is OK) or the program is broken. You should report this to the developers. In the meantime, what about:

Code:
#!/bin/sh
false
while [[ $? != 0 ]]; then
    synergys --config /home/mhachey/synergy.conf
done
 
Old 06-27-2007, 10:07 AM   #15
murray_linux
Member
 
Registered: Nov 2003
Distribution: Slackware Current
Posts: 210

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by dawkcid
A segfault means either you have hardware problems (unlikely if everything else is OK) or the program is broken. You should report this to the developers. In the meantime, what about:

Code:
#!/bin/sh
false
while [[ $? != 0 ]]; then
    synergys --config /home/mhachey/synergy.conf
done
Thanks dawkcid. This is a known issue with synergy, and the only workaround at the moment is to restart the server.

I'm not sure about the code you sent, is it just checking to see if the program is down, and if it is, restart it? I'm simply trying to stop the server and start it back up on an hourly basis to get around the issue.

Thanks for your help.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to restart application services on remote systems vinayhr Programming 3 09-04-2006 12:37 AM
Automate Application Restart wfernley Linux - Software 2 07-20-2006 06:24 PM
apache fails to restart nde Linux - Newbie 7 09-13-2005 04:26 PM
restart application if it dies N_A_J_M Linux - General 4 09-30-2004 06:18 PM
GUI abruptly fails to load on restart JevidL Linux - General 1 08-30-2003 05:20 PM


All times are GMT -5. The time now is 11:53 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration