English | French
Objective
Use, from an Asustor NAS, a "slave" inverter (UPS) which is connected via USB (therefore as master) on a Synology NAS with DSM 7.1.x, therefore as master on the Synology.
Note
The following commands mostly need to be run as root in a terminal, remember to do:sudo -i
Warning
Attention, for the Asustor to properly receive the instructions from the UPS server, it is obvious that any transmission chain is placed on the inverter: the Synology NAS which acts as the UPS server, any switch to which the NAS is connected , and Asustor NAS.
Topic on forum-nas.fr:
Note
The following has been used successfully with the following NAS:
- Asustor AS6704T below ADM 4.2.0.RE71
- Synology DS920+ below DSM 7.1.1-42962 Update 4
- I. Configuring the UPS as a slave in ADM
- II. Configuring UPS as master in DSM
- III. SSH configuration of the UPS as a slave in the configuration files on the Asustor
- IV. Inspiration for this tutorial
Begin by adding a connection to a UPS server in ADM. For that, you have to go to "External Devices", and configure as follows:
- Check the box "Enable network UPS Support";
- Choose "Network UPS Slave";
- Enter the IP address of the Synology NAS to which the inverter (UPS) is connected via USB;
It is possible to choose one of these two options:
I chose to use the "Safe-Mode" 5 minutes because it leaves 5 minutes before the NAS shuts down, because if it's on "Shutdown", the NAS will start the shutdown procedure as soon as it receives the information of the power failure.
This is what Asustor's online help says:
Once the settings are made/chosen, you should get something like this:
It should be noted that we do not obtain information neither on the % of battery of the inverter, nor on the remaining duration. And even after you finish following the tutorial it will still be like this. I did not manage to get this information in ADM... They are still visible in DSM on the Synology.
It is recommended not to activate the "EuP Mode":
I prefer to let the NAS return to its pre-power outage state as soon as the power is restored. So, if the NAS was on, when the power returns, it will restart.
In DSM, you must configure the UPS server as master for the inverter connected via USB. Follow the instructions in the following screenshot:
The Asustor will now be able to access the connected UPS on the Synology.
Note
It will also be necessary for the NAS firewall to authorize the connection from the asustor's IP to the UPS service. If necessary, create a dedicated rule.
Here we attack the somewhat painful part, because you have to connect in SSH to the Asustor NAS.
Here I use my administrator account User-Admin
to connect to the asustor whose IP is 192.168.2.203
on the custom port 1234
(these values are to be changed by yours!):
ssh User-Admin@192.168.2.203 -p 1234
The file to modify is /etc/ups/upsmon.conf
. And this file is reset each time the NAS is rebooted!
It will therefore be necessary to use a script that will be launched after each start of the NAS to modify this file, and to launch the few commands so that these modifications are taken into account.
It is therefore necessary to create a script in a shared folder. I chose to place my various scripts in the /share/docker/_scripts/
folder. If you use another location, you will have to modify this access path accordingly.
The script is called partage-UPS-Synology-avec-NAS-Asustor.sh
, it will have to be placed in the chosen folder, via ADM for example.
(It is possible to use a command line editor like vi, or nano (to be installed with opkg, after installing the Entware package)).
The script: partage-UPS-Synology-avec-NAS-Asustor.sh
Click here to view the script
#!/bin/sh
# Script de modification du fichier /etc/ups/upsmon.conf avec backup des fichiers contenus dans /etc/ups
# Faire un:
# chmod +x partage-UPS-Synology-avec-NAS-Asustor.sh
# Pour que les modifications soient effectuées à chaque redémarrage, il faut faire un lien dans /usr/local/etc/init.d/
#
# ln -s /share/docker/_scripts/partage-UPS-Synology-avec-NAS-Asustor.sh /usr/local/etc/init.d/S84UPSpartageAvecSYNOLOGY
#
# init.d colle l'option 'start' à tout ce qui se nomme Sxxxx et 'stop' à tout ce qui se nomme 'Kxxx'
#####################################################
## Variables
NOM_UPS_Syno="ups"
IP_Syno_UPS="192.168.2.200"
USER_UPS="monuser"
USER_MDP_UPS="secret"
DEST_BACKUP=/home/User-Admin/UPS-CONF-Backup
##
#####################################################
UPS_CONF_PATH=/etc/ups
CHAINE_FINALE="MONITOR $NOM_UPS_Syno@$IP_Syno_UPS 1 $USER_UPS $USER_MDP_UPS slave"
# # DEBUT DEBUG:
# UPS_CONF_PATH=/home/User-Admin
# printf "\nChaine finale = "
# echo $CHAINE_FINALE
printf "\n--- Début du fichier upsmon.conf non modifié ---\n"
cat $UPS_CONF_PATH/upsmon.conf
printf "\n--- Fin du fichier upsmon.conf non modifié ---\n"
# # FIN DEBUG
# Copie backup des fichiers du dossier UPS_CONF_PATH
mkdir -p $DEST_BACKUP
sudo cp "$UPS_CONF_PATH"/* "$DEST_BACKUP"
# Modification du fichier upsmon.conf pour utiliser en slave l'UPS branché en USB sur le Synology
sudo sed -i "2s/.*/${CHAINE_FINALE}/" $UPS_CONF_PATH/upsmon.conf
# DEBUT DEBUG:
printf "\n--- Début du fichier upsmon.conf MODIFIÉ ---\n"
cat $UPS_CONF_PATH/upsmon.conf
printf "\n--- Fin du fichier upsmon.conf MODIFIÉ ---\n"
# FIN DEBUG
# Commands to restart the upsmon daemon:
upsmon -c stop
upsmon
You will need to modify the following variables to match your configuration. Normally for a Synology NAS, only the IP_Syno_UPS
and DEST_BACKUP
variables will need to be modified.
#####################################################
## Variables
NOM_UPS_Syno="ups"
IP_Syno_UPS="192.168.2.200"
USER_UPS="monuser"
USER_MDP_UPS="secret"
DEST_BACKUP=/home/User-Admin/UPS-CONF-Backup
##
#####################################################
-
The script will build, using the variables set previously, the correct line that will allow the Asustor NAS to communicate with the UPS server on the Synology NAS.
-
The script will display the contents of the file that will be modified
/etc/ups/upsmon.conf
. -
Then, if necessary, it will create the destination folder for the
DEST_BACKUP
backup, then copy the contents of the/etc/ups/
folder into thisDEST_BACKUP
folder. -
Then, with the
sed
command, it will modify only the second line of the/etc/ups/upsmon.conf
file to change from:MONITOR asustor@192.168.2.200 1 admin 1111 slave
to:
MONITOR ups@192.168.2.200 1 monuser secret slave
The IP addresses will certainly be different.
-
Then, it again displays the
upsmon.conf
file which has just been modified. -
And finally, with the commands
upsmon -c stop
andupsmon
, it will stop then restart theupsmon
daemon in order to take into account the modifications made in theupsmon.conf
file.
We will manually launch the script to be sure that it correctly modifies the configuration file.
We therefore place ourselves in the folder containing it, and we make sure that it can be executed:
chmod +x Share_Synology_UPS_with_Asustor.sh
Then we run it:
./Share_Synology_UPS_with_Asustor.sh
We should see the contents of the file before the modification, then after the modification, then this:
Network UPS Tools upsmon 2.7.2
kill: No such process
UPS: ups@192.168.2.200 (slave) (power value 1)
Using power down flag file /etc/killpower
This indicates that upsmon
has been successfully connected to the synology UPS server in slave mode.
You can then do a crash test: cut off the power supply to the inverter connected to the Synology.
Warning
Attention, for the Asustor to receive the instructions from the UPS server, it is obvious that any transmission chain is placed on the inverter: the Synology NAS which acts as the UPS server, the possible switch to which the ) NAS, and the Asustor NAS.
If everything went well, you should be able to observe this kind of event in the logs visible in "System Information":
Reminder: the script is placed in the folder chosen in §-III.1., for me it is: /share/docker/_scripts/
.
You must make a symbolic link to /usr/local/etc/init.d/
so that the script is launched each time the NAS is started.
Important
The name of the link is very important, since if it begins withSxxx
it will be launched at startup, with thestart
option as a parameter (option which we will not use, and therefore not tested in the script) . If the link starts withKxxx
it will be launched at shutdown of the NAS, with thestop
option, and we do not need a script that launches at shutdown for the UPS.
It is therefore necessary to launch the following command (remember to adapt the access path of the script /share/docker/_scripts/partage-UPS-Synology-avec-NAS-Asustor.sh
:
ln -s /share/docker/_scripts/partage-UPS-Synology-avec-NAS-Asustor.sh /usr/local/etc/init.d/S84UPSpartageAvecSYNOLOGY
Here, the link is made, it only remains to reboot the NAS to see if the file is modified after the reboot.
Use the following command to check if the file has been modified:
cat /etc/ups/upsmon.conf