[SOLVED] How to automate starting a process in gnu screen and restart it when it crashes
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to automate starting a process in gnu screen and restart it when it crashes
I have a java service that needs to be run in a gnu screen session so that I can -r into it to access it's interactive shell. I would like this to run at start-up. More importantly, it crashes frequently so I need the service to restart itself when it crashes.
How do I go about doing this myself? My previous experience with shell scripting amounts to putting ./service in a file and marking it executable.
This will be running on a FreeBSD server, but I might put it on a Linux server soon also. So any caveats on the differences would be useful information.
1. To restart service you can use simple bash script with infinite loop. It should check if your script is running and restart it if not.
2. Simplest way to run script at startup is init.d (for Linux) or rc.d (for FreeBSD) script with dtach. There a lot of examples.
It's something like screen but with minimal functionality.
I've used dtach before, it shouldn't take much to re-familiarize myself. The loop should be easy enough, but how do I perform a check to see if the process is running?
I figured I'd need some kind of way to set the pid and check for it. Your simpler solution is much better and so obvious I feel foolish for not thinking of it myself.
When the process dies so does the dtach session right?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.