Can this be done? Automatically restarting a program when it cashes?

I have a piece of amateur radio software I want to run that runs flawlessly on Windows. It is also available on Linux except the versions I have tried to run on openSUSE crash randomly. The Author(s) are scratching their own itch and really don’t seem to be interested in resolving this issue. This software does DSP to received signals that are sent over approximately two minute interval every two minutes with stations sending at random times and receiving the rest of the time and the reception reports sent to a central clearing point where they are added to a database and map. What I want to check to see if the program is running approximately every two minutes and if it isn’t to restart it. IS it possible to do this? It would save me from having to run a second computer and thereby save much electricity.

I have no knowledge of programming or scripting so I am coming from zero knowledge of how or if this can even be done.

Giving some starting points and questions:

. When you want to do things every so many minutes, there is cron for you. Read

man 5 crontab

to give you an idea what it can do for you and

man 1 crontab

to see how you can create/alter your own crontab.
No need to study it to the latest detail, we can of course help you, but it helps when you at least understand the basics.

. Does this application run under a normal user, or as root?

. Does this application ahs to run from system boot until shutdown (best solved with an inittab solution imho), or from a user login in until logout or different?

Waiting for answers to make further steps to a solution.

It runs as a user launched program in user space. It needs for all the sound cards to be up an enumerated as one ( a usb device) is used as a modem for the receiver and transmit audio streams employed. Launching at boot time is not necessary or wanted actually. Sometimes I would choose not to run it due to external factors. I’ll read the man pages when Iv’e settled down a bit and had some sleep. I am running inetd now too. It’s really not suitable to running at boot. Too much stuff that might need to be fiddled with before it’s launched initially.

Thanks.

Thanks for thye explanation.

I am not evaluating everything you explain about sound cards etc, but my conclusion is you want to start it when a particular user logs in in the GUI. You want then run it from that session (that is it will not run in the background) and has thus to stop when the logout closes that GUI session.

When that is correct it is interesting to know which GUI session you use. I seached trough this thread, but neither the words *kde, *nor gnome give a result. My conclusion you failed to tell or you use another DE.

Well actually no. It is preferably launched from the cli and has an accompanying GUI type program window that opens and also information sometimes appears in the terminal window. There are settings that can change and those settings might need to be configured and tested when the program is first launched but not after it’s been set and has been running.

WSJT Home Page

WSPRnet | Weak Signal Propagation Reporter Network

Well, I try to concentrate in this. Please do the same.

When you say " It is preferably launched from the cli and has an accompanying GUI type program window that opens", that means to me that it should NOT run in the background but from a GUI session. I guess you now also start it from a running GUI sesion (in a terminal window, that is part of a GUI session).

I have now asked several questions, some explicit, some may be a bit implicit. You did not answer them all. I try to repeat them here:

. What desktop envioinmnet are you running?

. When EXACTLY (we are talking about programming, thus everything should be defined precise), must the program be started (including if this is to be automatic, or at the will of the loged in user)?

. When has the program to be stopped.

. Am I correct that between those two actions the prgram must be watched every two (2) minutes and restarted when it is not running?

And the above of course in the final production stage, not what you are doing now in testing things.

(1) KDE is the DE

(2) At the will of the logged in user

(3) It must be be able to be shut down manually.

What I need is to check to see if it’s exited when it has not explicitly been shut down by the user (me.) Around every two minutes is when it needs to be checked due to issues it has always had through several versions. If it has halted without user intervention it needs to be restarted.

Usually I would have it running 24/7 without intervention but I might need to change the band it’s operating on or the power level it’s running at. This means putting the program in “idle” mode and configuring the software and the hardware it is attached too manually then putting it back in the active mode again. It can be made to default to the active mode on restarting so restarting the program automatically presents no issues.

This makes it clearer (which is not the sameaseasier :wink: ).

As we hve to find out what is the definition of it “running as usual” against “running in idle mode” gainst “running not wanted” (and may be more variations), you could start finding out what processes are running belonging toi the application.

You could start with

ps -ef| grep <name-of-program>>

Well, I think you did not even mention the name of the program (why so shy?)

I gave the URL to the program. WSPR is it’s name. It’s in the ham radio repos

flamebait@fuuyuu:~> ps -ef| grep wspr
500      10397 10385  0 04:46 pts/1    00:00:00 /bin/sh /usr/bin/wspr
500      10398 10397  4 04:46 pts/1    00:00:02 python -O /usr//share/wspr/wspr.py
500      10422 10407  0 04:47 pts/2    00:00:00 grep --color=auto wspr

I am user 500

I a going to bed now so I can’t respond right away.
Thanks for your patience.

Well, that gives me some time answering this. I was running to and fro from work on the garden terraces. But when you go to sleep, I can finish that.
. Is

 /bin/sh /usr/bin/wspr

how you start it from your terminal emulator?

can you give me

ls -l /usr/bin/wspr

and

file /usr/bin/wspr

and

head -1 /usr/bin/wspr

On 2012-03-17 12:36, FlameBait wrote:

> (1) KDE is the DE
>
> (2) At the will of the logged in user
>
> (3) It must be be able to be shut down manually.
>
> What I need is to check to see if it’s exited when it has not
> explicitly been shut down by the user (me.) Around every two minutes is
> when it needs to be checked due to issues it has always had through
> several versions. If it has halted without user intervention it needs to
> be restarted.

I think you need to run it from a loop in a script. If you are fortunate,
it will exit with an exitcode different from zero, and this be used as a
signal to the loop to restart it.

If you are not fortunate, restart it always, or examine the printed text
(not that simple).


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)

No I start it with



wspr




flamebait@fuuyuu:~> ls -l /usr/bin/wspr
-rwxr-xr-x 1 root root 353 Oct 29 19:53 /usr/bin/wspr




flamebait@fuuyuu:~> file /usr/bin/wspr
/usr/bin/wspr: POSIX shell script, ASCII text




flamebait@fuuyuu:~> head -1 /usr/bin/wspr
#!/bin/sh


I thought you had gone to bed :wink:

Nevertheless thanks for the answers. Explains things to me. Looks logical.

Now please let me think a bit about it. It is getting later here, so my sleep could interfere, but I will come back to you.

OK. Very good and thank you.

I didn’t get much sleep. But I am awake and going at the day. Have a better sleep than I had.

Here is what it looks like running. The info about jack can be disregarded as it ‘just works’ with the pulse audio piping.

http://www.slhess.com/pictures/wspr3.0.png

That is OK. I do get the general message.

When it crashes, then the GUI disappers I assume and the terminal shows an error (or not) and then gives a prompt. Correct?

The GUI disappears and it gives a error about crashing at a certain line usually. Sometimes it’s more verbose. and it may or may not return to the prompt. Sometimes you have to give it a line feed.

Oops, especialy the last does not seem to make it easy. Because the process is then still alive.
Hope I have a fruitfull night (sometimes solutions come up while asleep :slight_smile: )

On 2012-03-17 22:36, hcvv wrote:
>
> FlameBait;2449071 Wrote:
>> The GUI disappears and it gives a error about crashing at a certain line
>> usually. Sometimes it’s more verbose. and it may or may not return to
>> the prompt. Sometimes you have to give it a line feed.
> Oops, especialy the last does not seem to make it easy. Because the
> process is then still alive.

Maybe not. Some processes write something when closing, but forget to print
a newline, so that bash does not print the prompt. The process is dead, but
the prompt does not return till you press enter. A script would
nevertheless get the exitcode, i think.


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)

Contemplating your information, I switched from thinking about using cron to sometthing more in line with Carlos’ ideas.

This is a first try and it depends upon the fact that you do not type input to the wspr program once it is running in the terminal, apart from the extra Return you have somethimes to give when it crashes.

I gave the script below the name runwspr because then we have a real name to use in the discussions. You can give it of course any name you like.

Create the file with the name runwspr in the bin directory from your home directory with the contents:

#!/bin/bash

# This runs the wspr program in an endless loop.
# Because sometimes a line is read after wspr crashes, it reads from /dev/null.
# To stop the endless loop type Ctrl-C.

while true
do      wspr </dev/null
        echo "=== Restarting ==="
done

You may alter the line with echo command. It is only there to show that a restart is done, you may even delete it.

Make it executable with

chmod u+x $HOME/bin/runwspr

I tested this, but used a different X program then wspr because I do not have *wspr. *This is what the test shows in the terminal:


henk@boven:~> runwspr
=== Restarting ===
=== Restarting ===
^C
henk@boven:~

I aborted the X program two times by closing it’s window. It restarted immediatly.
I then stopped the whole thing by typing Ctrl-C.

Please try this and test it. You can of course do the tests I did above, but I understand that for a real crash we hav to wait for it to happen. And when you are waiting for it, that will of course not happen (such is live :frowning: ).

I think that this solution has he following advantages:

  • almost the same as you start it now;
  • you can still start the old way because nothing is altered to the product;
  • easy to see what to script does, even for someone with almost no bash
    knowledge.

It has imho the following disadvantage:

  • stopping wspr
    from it’s GUI window will restart it, you must go to the terminal window and type Ctrl-C. - maybe you find more, please tell them.

Waiting for your test results and you general impression about the solution.