Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- # This file is part of BAMT.
- #
- # BAMT is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # BAMT is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with BAMT. If not, see <http://www.gnu.org/licenses/>.
- eval
- {
- require '/opt/bamt/common.pl';
- };
- if ($@)
- {
- die "\n\n\nWe were unable to find or process a core BAMT library:\n\n" .
- $@ . "\n\n\nThe BAMT tools cannot function until the above error is corrected.\n\nMaybe this happened";
- }
- $SIG{__DIE__} = sub { &handleDeath(@_); };
- use Proc::PID::File;
- if (Proc::PID::File->running())
- {
- # one at a time, gentlemen
- lg("abort, another start_mining is running");
- exit(0);
- }
- my $arg = "go";
- if (@ARGV) { $arg = $ARGV[0]; }
- my @ps = `ps ax`;
- my $plymouth = 0;
- foreach $l (@ps)
- {
- if ($l =~ /plymouthd/)
- {
- $plymouth = 1;
- }
- }
- if ($arg eq 'pre')
- {
- my $startedtime = time;
- lg("pre mining tasks");
- my $conf = &getConfig;
- %conf = %{$conf};
- setHostname();
- if (! -e '/tmp/noMine')
- {
- my $delay = 15;
- my $maxwait = 120;
- if (defined(${$conf{'settings'}}{'start_mining_init_delay'}))
- {
- $delay = ${$conf{'settings'}}{'start_mining_init_delay'};
- }
- if (defined(${$conf{'settings'}}{'start_mining_max_wait'}))
- {
- $maxwait = ${$conf{'settings'}}{'start_mining_max_wait'};
- }
- lg("wait $delay seconds for X to start...");
- sleep $delay;
- # wait for X to really be ready...
- $xready = 0;
- $nodeal = 5;
- $startedtime = time - $delay;
- while (!$xready && ( (time - $startedtime) < $maxwait ))
- {
- $plymouth = 0;
- my @ps = `ps ax`;
- foreach $l (@ps)
- {
- # i guess
- if ($l =~ /pcmanfm\s\-\-desktop/)
- {
- $xready = 1;
- }
- elsif ($l =~ /plymouthd/)
- {
- $plymouth = 1;
- }
- }
- if (!$xready)
- {
- $nodeal++;
- if ($nodeal > 5)
- {
- lg("still waiting for X after " . (time - $startedtime) . " seconds...");
- $nodeal = 0;
- }
- sleep 5;
- }
- }
- if ($xready)
- {
- # deal with pesky xauth crap
- lg("X is ready, setup xauth...");
- `su user -c "DISPLAY=:0.0 xhost +"`;
- }
- else
- {
- lg("gave up on X after " . (time - $startedtime) . " seconds");
- }
- }
- if (! -e '/live/image/BAMT/CONTROL/ACTIVE/noStatus')
- {
- gatherOfflineStatusPre();
- }
- }
- elsif ($arg eq 'post')
- {
- my $conf = &getConfig;
- %conf = %{$conf};
- lg("post mining tasks...");
- if (! -e '/live/image/BAMT/CONTROL/ACTIVE/noStatus')
- {
- gatherOfflineStatusPost();
- }
- if (defined(${$conf{'settings'}}{'do_mgpumon'}) && (${$conf{'settings'}}{'do_mgpumon'} == 1))
- {
- lg("starting background mgpumon");
- my $pid = fork();
- if (not defined $pid)
- {
- die "out of resources? forking failed while starting mgpumon";
- }
- elsif ($pid == 0)
- {
- exec('mgpumon /etc/bamt/mgpumon.conf');
- }
- }
- }
- else
- {
- # lets go!
- if (! -e '/tmp/noMine')
- {
- lg("starting mining processes");
- &startMining;
- }
- }
- sub lg
- {
- my ($msg) = @_;
- &blog($msg);
- if ($plymouth)
- {
- `/bin/plymouth message --text="start_mining: $msg"`;
- }
- else
- {
- print "start_mining: $msg\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement