Skip to content

Instantly share code, notes, and snippets.

@freekrai
Created March 10, 2012 02:24
Show Gist options
  • Save freekrai/2009751 to your computer and use it in GitHub Desktop.
Save freekrai/2009751 to your computer and use it in GitHub Desktop.
<?php
define('LOCK_FILE', isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : '/tmp/secondcrack-updater.pid');
// Ensure that no other instances are running
if (file_exists(LOCK_FILE) &&
($pid = intval(trim(file_get_contents(LOCK_FILE)))) &&
posix_kill($pid, 0)
) {
fwrite(STDERR, "Already running [pid $pid]\n");
exit(1);
}
function cleanupp() {
try { unlink(LOCK_FILE); } catch (Exception $e) {
fwrite(STDERR, "Cannot remove lock file [" . LOCK_FILE . "]: " . $e->getMessage() . "\n");
}
}
if (file_put_contents(LOCK_FILE, posix_getpid())) {
register_shutdown_function('cleanupp');
} else {
fwrite(STDERR, "Cannot write lock file: " . LOCK_FILE . "\n");
exit(1);
}
$fdir = dirname(__FILE__);
require_once($fdir . '/Post.php');
$config_file = realpath(dirname(__FILE__) . '/..') . '/config.php';
if (! file_exists($config_file)) {
fwrite(STDERR, "Missing config file [$config_file]\nsee [$config_file.default] for an example\n");
exit(1);
}
require_once($config_file);
Updater::update();
exit(Updater::$changes_were_written ? 2 : 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment