Using at to implement linux delayed startup tasks

Recently we encountered a scenario where our service was not working well after the customer's power outage was restored, because our server A relied on the customer service's server B, but the customer's server B started slower than our server A. So I want to find a way to delay the service startup to solve this problem. After searching for a while, we sorted out a solution suitable for us, using the at command of Linux to achieve delayed startup.

Common execution methods of at (assuming that the task needs to be executed 5 minutes from now):

#执行单条命令
echo "/etc/init.d/your_service restart" | at now +5 minutes

#执行一个脚本
at now +5 minutes -f /home/test/your_script.sh

To achieve delayed start of tasks, one condition is required, which is to put the above statement into the task started when Linux is started. This is how Linux manages user-defined boot tasks: /etc/rc.local. The system will execute the contents here after other startup tasks are completed.

Although you can manually edit the /etc/rc.local file with vim directly, the advantage of writing it as a statement is that it facilitates subsequent batch deployment. The time that needs to be delayed can also be implemented by using variable parameters. This is more flexible.

おすすめ

転載: blog.csdn.net/herbertyellow/article/details/126707398