Here is a script that you can use to start your application on Linux. What this script will do is read in all the arguments from the command line and store them in a special shell variable. If the application segmentation faults, the script will automatically start the application using all the command line arguments. Also this will write that the application has died to any syslog on the system.
Here is how it should be called.
1 |
/usr/bin/appstarter.ksh /opt/bin/program_binary arg1 arg2 arg3 arg4 arg5 arg6 argN |
And here is the actual code written in KSH.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#!/bin/ksh while true; do while [[ `/bin/ps -e -o command | /bin/egrep "^$*$" | /bin/grep -v grep|/usr/bin/wc -l` -eq 0 ]] ; do echo "Starting $* ..."; wait $!; /bin/logger -p local1.notice "Application died on `/usr/bin/whoami`@`/bin/hostname`: $*"; echo "Application died: $*"; sleep 10; done; sleep 30; done; |