Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/php -q
- <?php
- // Allowed arguments & their defaults
- $runmode = array(
- "no-daemon" => false,
- "help" => false,
- "write-initd" => false
- );
- // Scan command line attributes for allowed arguments
- foreach ($argv as $k=>$arg) {
- if (substr($arg, 0, 2) == "--" && isset($runmode[substr($arg, 2)])) {
- $runmode[substr($arg, 2)] = true;
- }
- }
- // Help mode. Shows allowed argumentents and quit directly
- if ($runmode["help"] == true) {
- echo "Usage: ".$argv[0]." [runmode]\n";
- echo "Available runmodes:\n";
- foreach ($runmode as $runmod=>$val) {
- echo " --".$runmod."\n";
- }
- die();
- }
- // Include Class
- error_reporting(E_ALL);
- require_once "includes/System/Daemon.php";
- // Setup
- $options = array(
- "appName" => "3bot",
- "appDir" => dirname(__FILE__),
- "appDescription" => "An IRC bot that does stuff",
- "authorName" => "Brian Steere",
- "authorEmail" => "dianoga7@3dgo.net",
- "sysMaxExecutionTime" => "0",
- "sysMaxInputTime" => "0",
- "sysMemoryLimit" => "20M",
- "appRunAsGID" => 1003,
- "appRunAsUID" => 1002,
- "usePEAR" => false,
- "logVerbosity" => System_Daemon::LOG_INFO
- );
- System_Daemon::setOptions($options);
- // Overrule the signal handler with any function
- System_Daemon::setSigHandler(SIGCONT, array("System_Daemon",
- "defaultSigHandler"));
- // This program can also be run in the forground with runmode --no-daemon
- if (!$runmode["no-daemon"]) {
- // Spawn Daemon
- System_Daemon::start();
- }
- // With the runmode --write-initd, this program can automatically write a
- // system startup file called: 'init.d'
- // This will make sure your daemon will be started on reboot
- if (!$runmode["write-initd"]) {
- System_Daemon::log(System_Daemon::LOG_INFO, "not writing ".
- "an init.d script this time");
- } else {
- if (($initd_location = System_Daemon::writeAutoRun()) === false) {
- System_Daemon::log(System_Daemon::LOG_NOTICE, "unable to write ".
- "init.d script");
- } else {
- System_Daemon::log(System_Daemon::LOG_INFO, "sucessfully written ".
- "startup script: ".$initd_location);
- }
- die();
- }
- set_include_path(get_include_path() . PATH_SEPARATOR . "/home/threebot/3bot/");
- require_once('3bot.php');
- System_Daemon::log(System_Daemon::LOG_INFO, print_r($ThreeBot, false));
- // Shut down the daemon nicely
- // This is ignored if the class is actually running in the foreground
- System_Daemon::stop();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement