l00k
May 6, 2021, 5:19am
1
Phala UPS guard
Check: https://github.com/l00k/phala-ups-guard
This tools monitors UPS state.
If something is wrong with line power and UPS is switched to battery power supply - tool starts procedure.
NOTE:
Currently Phala uses mining rounds mechanism. It may change in future according to:
I don’t want to admit but actually we would add the support of this if we have solved a problem. The state “MiningStopping” doesn’t contain the starting height. So whenever we switch to the stopping state, the starting height is dropped in the blockchain state. We cannot recover to “Mining(startHeight)” later.
This is not so hard to fix, but we see some very basic problems in the overall round design. And it turned out it’s very likely that we may abandone the round design completely. In other …
Requirements
HID compatible UPS
apcupsd package
node.js v12+
Additional for remote deployment
Usage
There are 2 ways of using this tool
You can copy few files and manually configure everything
or you can use deployer to configure everything
Manual
Copy file dist/main.js
to <dest>/main.js
Configure nodes and accounts in <dest>/config.json
(check configuration section)
Run with node ./main.js
Using deployer
Install dependencies
git clone https://github.com/l00k/phala-ups-guard.git
cd phala-ups-guard
composer install
npm ci
Configure nodes and accounts in (...)/phala-ups-guard/config.json
Configure host in (...)/phala-ups-guard/hosts.yaml
Deploy - my-ups-guard
is hostname from hosts.yaml
php ./vendor/bin/dep guard:deploy my-ups-guard
Configuration
Guard configuration (config.json)
You can use config.dist.json
as a template.
{
"nodes": [
{ "url": "wss://poc4.phala.network/ws" },
{ "url": "http://127.0.0.1:9933" }
],
"accounts": [
{
"name": "Miner 01",
"privateKey": "abc def ghi abc def ghi abc def ghi abc def ghi"
},
{
"name": "Miner 02",
"privateKey": "abc def ghi abc def ghi abc def ghi abc def ghi"
}
]
}
nodes
- list of Phala nodes
nodes[idx].url
- node URL - it can WebSocket or RPC HTTP server
accounts
- list of managed accounts
accounts[idx].name
- account name for logging purpose
accounts[idx].privateKey
- mnemonic / private key of account
Hosts for deployment (hosts.yaml)
You can use hosts.dist.yaml
as a template.
my-ups-guard:
hostname: 123.45.67.89
port: 22
user: root
deploy_path: '/srv/guard'
my-ups-guard
- deployer host identifier
<host>.hostname
- IP address of your node
<host>.port
- self explanatory
<host>.user
- root or other user which has access to sudo
command (without password - google “visudo nopasswd”)
<host>.deploy_path
- directory where all scripts will be placed
zzz
August 11, 2021, 12:52pm
2
这个是什么问题
phala@phala-NUC10i3FNH:~/phala-ups-guard-master$ sudo php ./vendor/bin/dep guard:deploy
➤ Executing task guard:deploy
Build script
Deploying to main
Clearing build directory (local)
Genereting scripts (local)
templates/rc-script.sh
templates/main.sh
dist/main.js
config.json
Uploading scripts
[email protected] ’s password:
rc-script.sh
[email protected] ’s password:
In Process.php line 257:
The command “rsync -azP -e ‘ssh -A’ ‘/home/phala/phala-ups-guard-master/build/main/templates/rc-script.sh’ ‘[email protected] :/srv/guard/rc-script.sh’”
failed.
Exit Code: 23(Unknown error)
Working directory: /home/phala/phala-ups-guard-master
Output:
sending incremental file list
rc-script.sh
926 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=0/1)
Error Output:
rsync: mkstemp “/srv/guard/.rc-script.sh.EyvyTQ” failed: Permission denied (13)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1207) [sender=3.1.3]
guard:deploy [-p|–parallel] [-l|–limit LIMIT] [–no-hooks] [–log LOG] [–roles ROLES] [–hosts HOSTS] [-o|–option OPTION] [–] []
l00k
August 11, 2021, 1:18pm
4
you probably don’t have ssh server on localhost (which is normal).
You can also build with npm run build
and copy dist/main.js
to some place and configure it to run by CRON.
zzz
August 11, 2021, 2:26pm
7
我怎么检查我的ups已经正确的驱动了?
lsusb:
Bus 001 Device 002: ID 051d:0002 American Power Conversion Uninterruptible Power Supply
我已经安装了apcupsd,
phala@phala-NUC10i3FNH:~/phala-ups-guard-master$ sudo service apcupsd status
● apcupsd.service
Loaded: loaded (/etc/init.d/apcupsd; generated)
Active: active (running) since Wed 2021-08-11 20:06:26 CST; 2h 19min ago
Docs: man:systemd-sysv-generator(8)
Tasks: 3 (limit: 18801)
Memory: 408.0K
CGroup: /system.slice/apcupsd.service
└─56860 /sbin/apcupsd
8月 11 20:06:26 phala-NUC10i3FNH systemd[1]: Starting apcupsd.service…
8月 11 20:06:26 phala-NUC10i3FNH apcupsd[56860]: apcupsd 3.14.14 (31 May 2016) debian startup succeeded
8月 11 20:06:26 phala-NUC10i3FNH apcupsd[56856]: Starting APC UPS power management: apcupsd.
8月 11 20:06:26 phala-NUC10i3FNH systemd[1]: Started apcupsd.service.
8月 11 20:06:39 phala-NUC10i3FNH apcupsd[56860]: NIS server startup succeeded
服务已经启动了,那现在的状态是不是已经正常了。
zzz
August 11, 2021, 2:48pm
9
phala@phala-NUC10i3FNH:~/phala-ups-guard-master$ apcaccess
APC : 001,036,0863
DATE : 2021-08-11 22:47:57 +0800
HOSTNAME : zzz18
VERSION : 3.14.14 (31 May 2016) debian
UPSNAME : phala-NUC10i3FNH
CABLE : USB Cable
DRIVER : USB UPS Driver
UPSMODE : Stand Alone
STARTTIME: 2021-08-11 20:06:26 +0800
MODEL : Back-UPS RS 1500G
STATUS : ONLINE
LINEV : 232.0 Volts
LOADPCT : 26.0 Percent
BCHARGE : 100.0 Percent
TIMELEFT : 24.3 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME : 0 Seconds
SENSE : Medium
LOTRANS : 176.0 Volts
HITRANS : 294.0 Volts
ALARMDEL : No alarm
BATTV : 27.0 Volts
LASTXFER : Low line voltage
NUMXFERS : 0
TONBATT : 0 Seconds
CUMONBATT: 0 Seconds
XOFFBATT : N/A
SELFTEST : NO
STATFLAG : 0x05000008
SERIALNO : 4B2003P33010
BATTDATE : 2020-01-21
NOMINV : 230 Volts
NOMBATTV : 24.0 Volts
NOMPOWER : 865 Watts
FIRMWARE : 878.L5 .I USB FW:L5
END APC : 2021-08-11 22:48:08 +0800
is ok?
zzz
August 11, 2021, 2:51pm
10
{
“nodes”: [
{ “url”: “wss://poc4.phala.network/ws” },
{ “url”: “http://127.0.0.1:9933 ” }
],
在config文件中, { “url”: “wss://poc4.phala.network/ws” }, 这个是必须的吗,还是只保留 { “url”: “http://127.0.0.1:9933 ” } 这个就可以了。
zzz
August 11, 2021, 2:53pm
11
phala@phala-NUC10i3FNH:~/phala-ups-guard-master$ sudo node dist/main.js
2021-08-11 22:52:51 Could not connect to node wss://poc4.phala.network/ws undefined
l00k
August 11, 2021, 2:55pm
12
Try to run local node ;) and remove first entry
zzz
August 11, 2021, 11:28pm
13
phala@phala-NUC10i3FNH:~/phala-ups-guard-master$ sudo node dist/main.js
phala@phala-NUC10i3FNH:~/phala-ups-guard-master$
it is running?我怎么才能看到运行的日志?
zzz
August 12, 2021, 1:04am
14
DO you have wechat or qq ?