Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.47 KB | None | 0 0
  1. #!/usr/bin/php -q
  2. <?php
  3.  
  4. // Allowed arguments & their defaults
  5. $runmode = array(
  6.     "no-daemon" => false,
  7.     "help" => false,
  8.     "write-initd" => false
  9. );
  10.  
  11. // Scan command line attributes for allowed arguments
  12. foreach ($argv as $k=>$arg) {
  13.     if (substr($arg, 0, 2) == "--" && isset($runmode[substr($arg, 2)])) {
  14.         $runmode[substr($arg, 2)] = true;
  15.     }
  16. }
  17.  
  18. // Help mode. Shows allowed argumentents and quit directly
  19. if ($runmode["help"] == true) {
  20.     echo "Usage: ".$argv[0]." [runmode]\n";
  21.     echo "Available runmodes:\n";
  22.     foreach ($runmode as $runmod=>$val) {
  23.         echo " --".$runmod."\n";
  24.     }
  25.     die();
  26. }
  27.  
  28. // Include Class
  29. error_reporting(E_ALL);
  30. require_once "includes/System/Daemon.php";
  31.  
  32. // Setup
  33. $options = array(
  34.     "appName" => "3bot",
  35.     "appDir" => dirname(__FILE__),
  36.     "appDescription" => "An IRC bot that does stuff",
  37.     "authorName" => "Brian Steere",
  38.     "authorEmail" => "dianoga7@3dgo.net",
  39.     "sysMaxExecutionTime" => "0",
  40.     "sysMaxInputTime" => "0",
  41.     "sysMemoryLimit" => "20M",
  42.     "appRunAsGID" => 1003,
  43.     "appRunAsUID" => 1002,
  44.     "usePEAR" => false,
  45.     "logVerbosity" => System_Daemon::LOG_INFO
  46. );
  47.  
  48. System_Daemon::setOptions($options);
  49.  
  50. // Overrule the signal handler with any function
  51. System_Daemon::setSigHandler(SIGCONT, array("System_Daemon",
  52.     "defaultSigHandler"));
  53.  
  54.  
  55. // This program can also be run in the forground with runmode --no-daemon
  56. if (!$runmode["no-daemon"]) {
  57.     // Spawn Daemon
  58.     System_Daemon::start();
  59. }
  60.  
  61. // With the runmode --write-initd, this program can automatically write a
  62. // system startup file called: 'init.d'
  63. // This will make sure your daemon will be started on reboot
  64. if (!$runmode["write-initd"]) {
  65.     System_Daemon::log(System_Daemon::LOG_INFO, "not writing ".
  66.         "an init.d script this time");
  67. } else {
  68.     if (($initd_location = System_Daemon::writeAutoRun()) === false) {
  69.         System_Daemon::log(System_Daemon::LOG_NOTICE, "unable to write ".
  70.             "init.d script");
  71.     } else {
  72.         System_Daemon::log(System_Daemon::LOG_INFO, "sucessfully written ".
  73.             "startup script: ".$initd_location);
  74.     }
  75.     die();
  76. }
  77.  
  78. set_include_path(get_include_path() . PATH_SEPARATOR . "/home/threebot/3bot/");
  79. require_once('3bot.php');
  80.  
  81. System_Daemon::log(System_Daemon::LOG_INFO, print_r($ThreeBot, false));
  82.  
  83. // Shut down the daemon nicely
  84. // This is ignored if the class is actually running in the foreground
  85. System_Daemon::stop();
  86. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement