-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsmcontrol
More file actions
executable file
·127 lines (109 loc) · 3.61 KB
/
smcontrol
File metadata and controls
executable file
·127 lines (109 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/perl
# This file is part of IFMI PoolManager.
#
# PoolManager 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.
use warnings;
use strict;
use File::Copy;
my $login = (getpwuid $>);
die "must run as root" if ($login ne 'root');
die "no arguments" if ($ARGV[0] eq "");
require '/opt/ifmi/sm-common.pl';
my $conf = &getConfig;
my %conf = %{$conf};
my $currentm = $conf{settings}{current_mconf};
my $minerpath = $conf{miners}{$currentm}{mpath};
if ($ARGV[0] eq "start") {
my $mcheck = `ps -eo command | grep -Ec ^$minerpath`;
if ($mcheck > 0) {
die "another mining process is running."
}
&startCGMiner();
&blog("starting miner") if (defined(${$conf}{settings}{verbose}));
}
if ($ARGV[0] eq "stop") {
&stopCGMiner();
&blog("stopping miner") if (defined(${$conf}{settings}{verbose}));
}
if ($ARGV[0] eq "restart") {
&stopCGMiner();
&blog("stopping miner") if (defined(${$conf}{settings}{verbose}));
sleep 10;
my $mcheck = `ps -eo command | grep -Ec ^$minerpath`;
if ($mcheck > 0) {
die "another mining process is running."
}
&startCGMiner();
&blog("starting miner") if (defined(${$conf}{settings}{verbose}));
sleep 10;
&resetPoolSuperPri;
}
if ($ARGV[0] eq "boot") {
my $bootcmd;
if (-e "/sbin/coldreboot") {
$bootcmd = "/sbin/coldreboot"
} else {
$bootcmd = "/sbin/reboot"
}
`$bootcmd`;
&blog("booting miner with $bootcmd") if (defined(${$conf}{settings}{verbose}));
}
if ($ARGV[0] eq "boot") {
my $bootcmd;
if (-e "/sbin/coldreboot") {
$bootcmd = "/sbin/coldreboot"
} else {
$bootcmd = "/sbin/reboot"
}
`$bootcmd`;
&blog("booting miner with $bootcmd") if (defined(${$conf}{settings}{verbose}));
}
if ($ARGV[0] eq "cleargraphs") {
system('/bin/rm /opt/ifmi/rrdtool/*.rrd');
system('/bin/rm /var/www/IFMI/graphs/*.png');
`/opt/ifmi/pmgraph.pl`;
}
if ($ARGV[0] eq "installht") {
if (-e "/var/htpasswd") {
`/usr/bin/htpasswd -b /var/htpasswd poolmanager live`;
} else {
`/usr/bin/htpasswd -bc /var/htpasswd poolmanager live`;
}
`chown www-data /var/htpasswd`;
if (! `grep AuthUserFile /etc/apache2/sites-available/default-ssl`) {
copy "/etc/apache2/sites-available/default-ssl", "/etc/apache2/sites-available/default-ssl.pre-ifmi"
if (!-f "/etc/apache2/sites-available/default-ssl.pre-ifmi");
open my $din, '<', "/etc/apache2/sites-available/default-ssl";
open my $dout, '>', "/etc/apache2/sites-available/default-ssl.out";
while (<$din>) {
print $dout $_;
last if /Directory \/>/;
}
print $dout "\n AuthType Basic\n AuthName \"Authentication Required\"\n";
print $dout " AuthUserFile /var/htpasswd\n";
print $dout "# Comment out the line below to disable password protection\n";
print $dout " Require valid-user\n\n";
while (<$din>) {
print $dout $_;
}
close $dout;
move "/etc/apache2/sites-available/default-ssl.out", "/etc/apache2/sites-available/default-ssl";
`/usr/sbin/service apache2 graceful`;
}
if (! `grep -E /usr/bin/htpasswd /etc/sudoers`) {
my $fin = "/etc/sudoers";
open my $sin, '<', $fin;
open my $sout, '>', "$fin.out";
while (<$sin>) {
s/\/opt\/ifmi\/mcontrol/\/opt\/ifmi\/mcontrol,\/usr\/bin\/htpasswd/;
print $sout $_;
}
close $sin; close $sout;
rename $fin, "$fin.back";
rename "$fin.out", $fin;
`chmod 0440 /etc/sudoers`;
}
}