UPS guard tool

Phala UPS guard

Check: GitHub - 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:

Requirements

  • HID compatible UPS
  • apcupsd package
  • node.js v12+

Additional for remote deployment

  • PHP >= 7.2
  • Composer

Usage

There are 2 ways of using this tool

  1. You can copy few files and manually configure everything
  2. or you can use deployer to configure everything

Manual

  1. Copy file dist/main.js to <dest>/main.js
  2. Configure nodes and accounts in <dest>/config.json (check configuration section)
  3. Run with node ./main.js

Using deployer

  1. Install dependencies
git clone https://github.com/l00k/phala-ups-guard.git
cd phala-ups-guard
composer install
npm ci
  1. Configure nodes and accounts in (...)/phala-ups-guard/config.json
  2. Configure host in (...)/phala-ups-guard/hosts.yaml
  3. 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

这个是什么问题

[email protected]:~/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] [–] []

我只想在本机部署这个服务。怎么操作。

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.

我怎么检查我的ups已经正确的驱动了?
lsusb:
Bus 001 Device 002: ID 051d:0002 American Power Conversion Uninterruptible Power Supply
我已经安装了apcupsd,
[email protected]:~/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
服务已经启动了,那现在的状态是不是已经正常了。

apcaccess

[email protected]:~/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?

{
“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” } 这个就可以了。

[email protected]:~/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

Try to run local node ;) and remove first entry

[email protected]:~/phala-ups-guard-master$ sudo node dist/main.js
[email protected]:~/phala-ups-guard-master$
it is running?我怎么才能看到运行的日志?

DO you have wechat or qq ?