Mini opgave - How To Use a Simple Bash Script To Restart Server Programs - How To Use a Simple Bash Script To Restart Server Programs To ensure

Mini opgave - How To Use a Simple Bash Script To Restart Server Programs

This preview shows page 1 - 3 out of 3 pages.

How To Use a Simple Bash Script To Restart Server Programs To ensure that the most imperative programs remain online as much as possible (even after a server crash or reboot), one can create a simple bash script to check if the program is running, and if it is not, to launch it. By using cron to schedule the script to be executed on a regular basis, we can make sure that program relaunches whenever it goes down. Bash Script The first step in this process is to create the script itself. There are a variety of programs such as upstart, supervisor, and monit, that have the capability to start and monitor applications on a virtual private server in a very nuanced way— this bash script will simply provide an on switch. Below is a sample script that starts apache if it finds it off. nano launch.sh #!/bin/sh ps auxw | grep apache2 | grep -v grep > /dev/null if [ $? != 0 ] then /etc/init.d/apache2 start > /dev/null fi
Once you have saved the script, you must give it executable permissions in order to be able to run it: chmod +x launch.sh

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture