init_daemon();
already_running();
openlog(NULL, LOG_CONS | LOG_PID, LOG_LOCAL1);
while(1) {
/* 1.检查cron进程是否已经运行 */
ret = run_system_cmd(SYSCMD1);
if (!ret) {
writelog("The cron process is not running, now start it! \n");
sleep(1);
system(SYSCMD5);
goto CHECK_CRON;
}
/* 2.如果已经运行,查看是否有僵尸进程 */
ret = run_system_cmd(SYSCMD2);
if (ret) {
writelog("The cron process is defunct, now restart it! \n");
sleep(1);
system(SYSCMD4);
sleep(1);
system(SYSCMD5);
goto CHECK_CRON;
}
/* 3.如果进程运行正常,检查任务是否正常调度 */
ret = run_system_cmd(SYSCMD3);
if (!ret) {
writelog("The cron work is down, now restart it! \n");
sleep(1);
system(SYSCMD4);
sleep(1);
system(SYSCMD5);
goto CHECK_CRON;
}
/* 4.crontab进程运行正常 */
writelog("The cron process is ok! \n");
CHECK_CRON:
/* 休眠5分钟后,继续检测 */
sleep(300);
}
closelog();
return 0;