Advertisement
Guest User

Untitled

a guest
Aug 30th, 2012
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2.  
  3. # This file is part of BAMT.
  4. #
  5. # BAMT is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # BAMT is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with BAMT. If not, see <http://www.gnu.org/licenses/>.
  17.  
  18. eval
  19. {
  20. require '/opt/bamt/common.pl';
  21. };
  22.  
  23. if ($@)
  24. {
  25. die "\n\n\nWe were unable to find or process a core BAMT library:\n\n" .
  26. $@ . "\n\n\nThe BAMT tools cannot function until the above error is corrected.\n\nMaybe this happened";
  27. }
  28.  
  29.  
  30. $SIG{__DIE__} = sub { &handleDeath(@_); };
  31.  
  32. use Proc::PID::File;
  33.  
  34. if (Proc::PID::File->running())
  35. {
  36. # one at a time, gentlemen
  37. lg("abort, another start_mining is running");
  38. exit(0);
  39. }
  40.  
  41.  
  42. my $arg = "go";
  43.  
  44. if (@ARGV) { $arg = $ARGV[0]; }
  45.  
  46. my @ps = `ps ax`;
  47. my $plymouth = 0;
  48.  
  49. foreach $l (@ps)
  50. {
  51. if ($l =~ /plymouthd/)
  52. {
  53. $plymouth = 1;
  54. }
  55. }
  56.  
  57.  
  58. if ($arg eq 'pre')
  59. {
  60. my $startedtime = time;
  61.  
  62. lg("pre mining tasks");
  63.  
  64. my $conf = &getConfig;
  65. %conf = %{$conf};
  66.  
  67.  
  68. setHostname();
  69.  
  70. if (! -e '/tmp/noMine')
  71. {
  72. my $delay = 15;
  73. my $maxwait = 120;
  74.  
  75. if (defined(${$conf{'settings'}}{'start_mining_init_delay'}))
  76. {
  77. $delay = ${$conf{'settings'}}{'start_mining_init_delay'};
  78. }
  79.  
  80. if (defined(${$conf{'settings'}}{'start_mining_max_wait'}))
  81. {
  82. $maxwait = ${$conf{'settings'}}{'start_mining_max_wait'};
  83. }
  84.  
  85.  
  86.  
  87. lg("wait $delay seconds for X to start...");
  88.  
  89. sleep $delay;
  90.  
  91. # wait for X to really be ready...
  92.  
  93. $xready = 0;
  94. $nodeal = 5;
  95.  
  96. $startedtime = time - $delay;
  97. while (!$xready && ( (time - $startedtime) < $maxwait ))
  98. {
  99. $plymouth = 0;
  100. my @ps = `ps ax`;
  101.  
  102. foreach $l (@ps)
  103. {
  104. # i guess
  105. if ($l =~ /pcmanfm\s\-\-desktop/)
  106. {
  107. $xready = 1;
  108. }
  109. elsif ($l =~ /plymouthd/)
  110. {
  111. $plymouth = 1;
  112. }
  113.  
  114. }
  115.  
  116. if (!$xready)
  117. {
  118. $nodeal++;
  119.  
  120. if ($nodeal > 5)
  121. {
  122. lg("still waiting for X after " . (time - $startedtime) . " seconds...");
  123. $nodeal = 0;
  124. }
  125. sleep 5;
  126. }
  127. }
  128.  
  129. if ($xready)
  130. {
  131.  
  132. # deal with pesky xauth crap
  133.  
  134. lg("X is ready, setup xauth...");
  135. `su user -c "DISPLAY=:0.0 xhost +"`;
  136. }
  137. else
  138. {
  139. lg("gave up on X after " . (time - $startedtime) . " seconds");
  140. }
  141.  
  142. }
  143.  
  144.  
  145. if (! -e '/live/image/BAMT/CONTROL/ACTIVE/noStatus')
  146. {
  147. gatherOfflineStatusPre();
  148. }
  149.  
  150.  
  151.  
  152. }
  153. elsif ($arg eq 'post')
  154. {
  155. my $conf = &getConfig;
  156. %conf = %{$conf};
  157.  
  158. lg("post mining tasks...");
  159.  
  160. if (! -e '/live/image/BAMT/CONTROL/ACTIVE/noStatus')
  161. {
  162. gatherOfflineStatusPost();
  163. }
  164.  
  165. if (defined(${$conf{'settings'}}{'do_mgpumon'}) && (${$conf{'settings'}}{'do_mgpumon'} == 1))
  166. {
  167. lg("starting background mgpumon");
  168. my $pid = fork();
  169.  
  170. if (not defined $pid)
  171. {
  172. die "out of resources? forking failed while starting mgpumon";
  173. }
  174. elsif ($pid == 0)
  175. {
  176. exec('mgpumon /etc/bamt/mgpumon.conf');
  177. }
  178. }
  179.  
  180.  
  181.  
  182. }
  183. else
  184. {
  185. # lets go!
  186. if (! -e '/tmp/noMine')
  187. {
  188. lg("starting mining processes");
  189. &startMining;
  190. }
  191. }
  192.  
  193.  
  194. sub lg
  195. {
  196. my ($msg) = @_;
  197.  
  198. &blog($msg);
  199.  
  200. if ($plymouth)
  201. {
  202. `/bin/plymouth message --text="start_mining: $msg"`;
  203. }
  204. else
  205. {
  206. print "start_mining: $msg\n";
  207. }
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement