Thursday, November 5, 2020

How to auto restart service's in linux

Due to the reason of Reliability: We make a script that automatically restarts the service in the event of a failure can help ensure that the service is always available to clients.


Step 1) Let's Create New File and Add below Script Code.

$ vim script.sh



Step 2) Give executable permission on that file.

$ sudo chmod +x script.sh


Step 3) Let's Execute it manually, Once It run successfully then also append it on crontab.

$ sh script.sh 


------------<END>-------------


For Your Information in crontab:

/dev/null is a special file in Linux that discards all data written to it. It is often used as a way to discard unwanted output from a command or script.

2>&1 is used to redirect error messages (stderr) to the same place as standard output (stdout). In other words, it combines the error messages with the normal output of the command.


Example Command of /dev/null

*/5 * * * * /usr/bin/bash /home/apache2_restart.sh > /dev/null  2>&1

Example Command of 2>&1

*/5 * * * * /usr/bin/bash /home/apache2_restart.sh >> /var/log/script.log 2>&1

 

 

No comments:

Post a Comment

testing