0

I am having an Ubuntu box on which I am having a Haskell process (think of it as a random server process) that I built. I want to start it on boot and restart it in case it fails for whatever reason (ideally with some kind of logging that it failed, what exec code it failed with, etc.).

How to do that?

Right now I wrote a shell script which is located in /etc/init.d/ which will fire up the haskell process and pipes it output to /var/log/.log . How to do the monitoring/restarting though?

0

Checking/restarting is typically done by writing a checker script along these lines:

#!/bin/sh
if ! pgrep -l name-of-executable >/dev/null 2>&1; then
    /etc/init.d/your-startup-script.sh
fi

and invoking it every N minutes in a cron like so:

*/N * * * * /usr/local/bin/checker-script.sh

If you want to actually monitor the Haskell process as it runs (so you can capture its exit code or be notified the instant it dies), then you'll want a more sophisticated wrapper. I typically use Python for this; its subprocess module has all the tools you need to launch and monitor a running subprocess.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.