var _xhr = require("topsin.xmlhttprequest");
var _process = require('topsin.ioprocess');
var _ = require("lodash");
var _logger = require("topsin.logger");
var _crypto = require("topsin.crypto");

function pausecomp(millis) {
  var date = new Date();
  var curDate = null;
  do { curDate = new Date(); }
  while (curDate - date < millis);
}

var logger_config = {
  appender: {
    console: {
      'type': 'console',
      'typefilter': '*',
      'format': '{TIME} [{TYPE}]:{MSG}'
    },
    file: {
      'type': 'file',
      'typefilter': 'INFO,SQL,ERROR,WARN,FATAL',
      'format': '{TIME} [{TYPE}]:{MSG}',
      'filename': "D:/toplinker/nginx-1.6.1/php-monitor/log/" + _crypto.uuid() + ".crontab.log"
    }
  }
};
_logger.loadConfig(logger_config);

var url = "http://10.111.32.15/demo/index.php";
_xhr.timeout = 2000;
_xhr.open("GET", url, false);
_xhr.send();
if (_xhr.status != 200) {
  _logger.info("_xhr.status = " + _.toString(_xhr.status));
  _logger.info("restart php.");
  _process.startDetached("D:/toplinker/nginx-1.6.1/stop_php.bat", []);
  pausecomp(3000);
  _process.startDetached("D:/toplinker/nginx-1.6.1/start_php.bat", []);
  _logger.info("end.");
}