#!/usr/bin/php
<?php
/*
* Purpose: Restart the cron process of a single ProjeQtOr application site.
* Inputs: None.
* Outputs: Prints for logging when a restart is initiated and if it fails.
* Security: Ensure that this script file is only readable & writeable by root
* and/or the specific Linux user that will be running this script!
* Version: 1.0.0
*/
/* ----------------------------------
* ENTER SITE SPECIFIC VARIABLES HERE
* ----------------------------------
*/
/* Define the site's url with trailing slash (usually https://yourdomain/projeqtor/) */
$siteUrl="https://yourdomain/projeqtor/";
/* Define the ProjeQtOr API's httppass username & password */
$httpUser="{username}";
$httpPass="{password}";
/* Define the maximum time in seconds allowed for the API call.
* Required because the api call to start the cron process runs indefinitely.
* Must be long enough to execute at peek loads, but not so long that it disturbs the system's cron.
*/
$maxtime="10";
/* ----------------------
* DO NOT EDIT BELOW HERE
* ----------------------
*/
/* Perform an initial check to see if a restart is actually required */
$fullUrl=$siteUrl."api/Cron/check";
$api_response = callapi( $fullUrl, $httpUser, $httpPass, $maxtime );
if ( preg_replace("#{.*:\"(.*)\"}.*#", "$1", $api_response) <> 'running' ) {
/* The cron process is not running, so attempt to start it */
echo "Info: Starting ProjeQtOr cron process for ".$siteUrl."\n";
$fullUrl=$siteUrl."api/Cron/start";
callapi( $fullUrl, $httpUser, $httpPass, $maxtime );
/* Perform a final check to see if the restart was successful */
$fullUrl=$siteUrl."api/Cron/check";
$api_response = callapi( $fullUrl, $httpUser, $httpPass, $maxtime );
if ( preg_replace("#{.*:\"(.*)\"}.*#", "$1", $api_response) <> 'running' ) {
echo "Error: failed to start ProjeQtOr cron process\n";
}
}
/* ---------
* Functions
* ---------
*/
/* Make an API call given:
* 1) the full api url as a string
* 2) the http username protecting the api directory as a string
* 3) the http password protecting the api directory as a string
* 4) the maximum time in seconds to allow for the call as a string
* Returns the api's response as a string
*/
function callapi( $url, $user, $pass, $time ) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $user.":".$pass);
curl_setopt($curl, CURLOPT_TIMEOUT, $time);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
$curl_response = curl_exec($curl);
curl_close($curl);
return $curl_response;
}
?>