{"id":2548,"date":"2025-03-10T20:37:29","date_gmt":"2025-03-10T20:37:29","guid":{"rendered":"https:\/\/cdblog.cdstealer.com\/?p=2548"},"modified":"2025-03-22T14:51:03","modified_gmt":"2025-03-22T14:51:03","slug":"2-ups-1-server","status":"publish","type":"post","link":"https:\/\/cdblog.cdstealer.com\/?p=2548","title":{"rendered":"2 UPS 1 Server"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">So I found myself in a situation where I had to run 2 UPS's due to larger plugs not being able to fit if the adjacent socket was occupied.  Obviously having 2 UPS's with the ability to control the server is a bad idea and typically the driver only accounts for one UPS at any one time.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-rounded\"><img loading=\"lazy\" decoding=\"async\" width=\"771\" height=\"1024\" src=\"https:\/\/cdblog.cdstealer.com\/wp-content\/uploads\/PXL_20250309_191758914.RAW-01.COVER_-771x1024.jpg\" alt=\"\" class=\"wp-image-2553\" srcset=\"https:\/\/cdblog.cdstealer.com\/wp-content\/uploads\/PXL_20250309_191758914.RAW-01.COVER_-771x1024.jpg 771w, https:\/\/cdblog.cdstealer.com\/wp-content\/uploads\/PXL_20250309_191758914.RAW-01.COVER_-226x300.jpg 226w, https:\/\/cdblog.cdstealer.com\/wp-content\/uploads\/PXL_20250309_191758914.RAW-01.COVER_-113x150.jpg 113w, https:\/\/cdblog.cdstealer.com\/wp-content\/uploads\/PXL_20250309_191758914.RAW-01.COVER_-1157x1536.jpg 1157w, https:\/\/cdblog.cdstealer.com\/wp-content\/uploads\/PXL_20250309_191758914.RAW-01.COVER_-1542x2048.jpg 1542w, https:\/\/cdblog.cdstealer.com\/wp-content\/uploads\/PXL_20250309_191758914.RAW-01.COVER_-scaled.jpg 1928w\" sizes=\"auto, (max-width: 771px) 100vw, 771px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">This takes about 5-10 mins to setup and seems to work as expected.<br>Both UPS's are APC, a 1050VA and a 700ES.  Both are connected to the server via USB.  The driver is apcupsd.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Make sure both UPS's are powered on and connected via USB.<br>Make a note of the Bus \/ Device.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># lsusb<br>...<br>Bus 001 Device 004: ID 051d:0002 American Power Conversion Uninterruptible Power Supply<br>Bus 001 Device 005: ID 051d:0002 American Power Conversion Uninterruptible Power Supply<br>...<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Let's make sure udev sees them.<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\"># udevadm info --attribute-walk --name=\/dev\/bus\/usb\/001\/004 | egrep 'manufacturer|product|serial'<br>ATTR{manufacturer}==\"APC\"<br>ATTR{product}==\"Back-UPS ES 700G FW:871.O3 .I USB FW:O3 \"<br>ATTR{serial}==\"#########1  \"<br>ATTRS{manufacturer}==\"Linux 6.12.17-gentoo xhci-hcd\"<br>ATTRS{product}==\"xHCI Host Controller\"<br>ATTRS{serial}==\"0000:00:14.0\"<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"># udevadm info --attribute-walk --name=\/dev\/bus\/usb\/001\/005 | egrep 'manufacturer|product|serial'<br>ATTR{manufacturer}==\"American Power Conversion\"<br>ATTR{product}==\"Back-UPS BE1050G2 FW:497200G -497300G \"<br>ATTR{serial}==\"##########2\"<br>ATTRS{manufacturer}==\"Linux 6.12.17-gentoo xhci-hcd\"<br>ATTRS{product}==\"xHCI Host Controller\"<br>ATTRS{serial}==\"0000:00:14.0\"<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Let's create a rule.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># vim \/etc\/udev\/rules.d\/ups.rules<br><br># Main UPS<br>SUBSYSTEM==\"usb\", ATTR{manufacturer}==\"American Power Conversion\", ATTR{serial}==\"########1  \", OWNER=\"root\", SYMLINK+=\"ups-server\"<br># Secondary UPS<br>SUBSYSTEM==\"usb\", ATTR{manufacturer}==\"APC\", ATTR{serial}==\"#######2\", OWNER=\"root\", SYMLINK+=\"ups-devices\"<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Note: The older of the 2 had spaces at the end of the serial number, so I kept them'<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Reload Udev<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># udevadm control --reload<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now let's check them udev rules.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># udevadm trigger -v -attr-match=serial=\"########1  \"<br># udevadm trigger -v -attr-match=serial=\"########2\"<br># ls -l \/dev<br><br>You should see:<br><br>\/dev\/ups-devices -&gt; bus\/usb\/001\/004<br>\/dev\/ups-server -&gt; bus\/usb\/001\/005<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Install the driver.<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\"># emerge -av apcupsd<br># systemctl stop apcupsd<br># systemctl disable apcupsd<br># cd \/etc\/apcupsd\/<br># mkdir apcupsd-devices<br># mkdir apcupsd-server<br># cp apcupsd.conf apcupsd-devices.conf apcupsd-server.conf<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Modify as required:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">apcupsd-server.conf<br><br>UPSNAME <mark style=\"background-color:#24890d\" class=\"has-inline-color has-white-color\">1050VA<\/mark><br>UPSCABLE usb<br>UPSTYPE usb <mark style=\"background-color:#24890d\" class=\"has-inline-color has-white-color\">\/dev\/ups-server<\/mark><br>DEVICE<br>POLLTIME 60<br>LOCKFILE \/run\/apcupsd\/<br>SCRIPTDIR <mark style=\"background-color:#24890d\" class=\"has-inline-color has-white-color\">\/etc\/apcupsd\/apcupsd-server<\/mark><br>PWRFAILDIR <mark style=\"background-color:#24890d\" class=\"has-inline-color has-white-color\">\/etc\/apcupsd\/apcupsd-server<\/mark><br>NOLOGINDIR \/etc<br>ONBATTERYDELAY 6<br>BATTERYLEVEL 5<br>MINUTES 3<br>TIMEOUT 0<br>ANNOY 300<br>ANNOYDELAY 60<br>NOLOGON disable<br>KILLDELAY 0<br>NETSERVER on<br>NISIP 127.0.0.1<br>NISPORT 3551<br>EVENTSFILE <mark style=\"background-color:#24890d\" class=\"has-inline-color has-white-color\">\/var\/log\/apcupsd-server.events<\/mark><br>EVENTSFILEMAX 10<br>UPSCLASS standalone<br>UPSMODE disable<br>STATTIME 0<br>STATFILE <mark style=\"background-color:#24890d\" class=\"has-inline-color has-white-color\">\/var\/log\/apcupsd-server.status<\/mark><br>LOGSTATS off<br>DATATIME 0<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">apcupsd-devices.conf<br><br>UPSNAME <mark style=\"background-color:#24890d\" class=\"has-inline-color has-white-color\">700ES<\/mark><br>UPSCABLE usb<br>UPSTYPE usb <mark style=\"background-color:#24890d\" class=\"has-inline-color has-white-color\">\/dev\/ups-devices<\/mark><br>POLLTIME 60<br>SCRIPTDIR <mark style=\"background-color:#24890d\" class=\"has-inline-color has-white-color\">\/etc\/apcupsd\/apcupsd-devices<\/mark><br>PWRFAILDIR <mark style=\"background-color:#24890d\" class=\"has-inline-color has-white-color\">\/etc\/apcupsd\/apcupsd-devices<\/mark><br>ONBATTERYDELAY 6<br>BATTERYLEVEL <mark style=\"background-color:#24890d\" class=\"has-inline-color has-white-color\">-1<\/mark><br>MINUTES <mark style=\"background-color:#24890d\" class=\"has-inline-color has-white-color\">-1<\/mark><br>TIMEOUT <mark style=\"background-color:#24890d\" class=\"has-inline-color has-white-color\">0<\/mark><br>ANNOY <mark style=\"background-color:#24890d\" class=\"has-inline-color has-white-color\">0<\/mark><br>ANNOYDELAY 0<br>NOLOGON disable<br>KILLDELAY 0<br>NETSERVER on<br>NISIP 127.0.0.1<br>NISPORT <mark style=\"background-color:#24890d\" class=\"has-inline-color has-white-color\">3552<\/mark><br>EVENTSFILE <mark style=\"background-color:#24890d\" class=\"has-inline-color has-white-color\">\/var\/log\/apcupsd-devices.events<\/mark><br>EVENTSFILEMAX 10<br>UPSCLASS standalone<br>UPSMODE disable<br>STATTIME 0<br>STATFILE <mark style=\"background-color:#24890d\" class=\"has-inline-color has-white-color\">\/var\/log\/apcupsd-devices.status<\/mark><br>LOGSTATS off<br>DATATIME 0<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">There needs to be 2 versions of the daemon running on different ports. The devices config does not allow for server control. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Copy the following scripts into the script directory specified in the configs.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">apccontrol<br>changeme<br>commfailure<br>commok<br>offbattery<br>onbattery<br>safe.apccontrol<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Startup Daemon (systemd)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Copy the systemd unit file for each daemon.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># cp \/usr\/lib\/systemd\/system\/apcupsd.service \/usr\/lib\/systemd\/system\/apcupsd-server.service<br><br># cp \/usr\/lib\/systemd\/system\/apcupsd.service \/usr\/lib\/systemd\/system\/apcupsd-devices.service<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Adjust each unit file accordingly:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[Service]<br>ExecStart=\/sbin\/apcupsd -b -f \/etc\/apcupsd\/apcupsd-server.conf -P \/run\/apcupsd\/apcupsd-server.pid<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">[Service]<br>ExecStart=\/sbin\/apcupsd -b -f \/etc\/apcupsd\/apcupsd-devices.conf -P \/run\/apcupsd\/apcupsd-devices.pid<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Enable and start the services.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># systemctl --now enable apcupsd-server<br># systemctl --now enable apcupsd-devices<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If all went to plan, you should now see both daemons running.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># systemctl status apcupsd-server<br>\u25cf apcupsd-server.service - APC UPS Monitor<br>Loaded: loaded (\/usr\/lib\/systemd\/system\/apcupsd-server.service; enabled; preset: disabled)<br>Active: active (running) since Sun 2025-03-09 20:58:55 GMT; 23h ago<br>Invocation: bea2f2a029de4384ba3b9fdb62dccc27<br>Main PID: 18929 (apcupsd)<br>Tasks: 3 (limit: 38270)<br>Memory: 2M (peak: 6.6M)<br>CPU: 2.669s<br>CGroup: \/system.slice\/apcupsd-server.service<br>\u2514\u250018929 \/sbin\/apcupsd -b -f \/etc\/apcupsd\/apcupsd-server.conf -P \/run\/apcupsd\/apcupsd-server.pid<br>Mar 09 20:58:55 hostname systemd[1]: Started APC UPS Monitor.<br>Mar 09 20:58:55 hostname apcupsd[18929]: apcupsd 3.14.14 (31 May 2016) gentoo startup succeeded<br>Mar 09 20:58:55 hostname apcupsd[18929]: NIS server startup succeeded<br>Mar 09 21:02:13 hostname apcupsd[18929]: Communications with UPS restored.<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"># systemctl status apcupsd-devices<br>\u25cf apcupsd-devices.service - APC UPS Monitor<br>Loaded: loaded (\/usr\/lib\/systemd\/system\/apcupsd-devices.service; enabled; preset: disabled)<br>Active: active (running) since Sun 2025-03-09 20:58:48 GMT; 23h ago<br>Invocation: 6079648a84d74eda9d48aa43e31aaf14<br>Main PID: 18820 (apcupsd)<br>Tasks: 3 (limit: 38270)<br>Memory: 408K (peak: 4.8M)<br>CPU: 2.662s<br>CGroup: \/system.slice\/apcupsd-devices.service<br>\u2514\u250018820 \/sbin\/apcupsd -b -f \/etc\/apcupsd\/apcupsd-devices.conf -P \/run\/apcupsd\/apcupsd-devices.pid<br>Mar 09 20:58:48 hostname systemd[1]: Started APC UPS Monitor.<br>Mar 09 20:58:48 hostname apcupsd[18820]: apcupsd 3.14.14 (31 May 2016) gentoo startup succeeded<br>Mar 09 20:58:48 hostname apcupsd[18820]: NIS server startup succeeded<br>Mar 09 21:02:13 hostname apcupsd[18820]: Communications with UPS restored.<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">With this setup, I get an email should there be any interruption on either UPS or when the battery requires replacing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Go on, give them a test and cut the power ;)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So I found myself in a situation where I had to run 2 UPS's due to larger plugs not being able to fit if the adjacent socket was occupied. Obviously having 2 UPS's with the ability to control the server is a bad idea and typically the driver only accounts for one UPS at any &hellip; <a href=\"https:\/\/cdblog.cdstealer.com\/?p=2548\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">2 UPS 1 Server<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[351,352,350],"class_list":["post-2548","post","type-post","status-publish","format-standard","hentry","category-gentoo","tag-apc","tag-multiple","tag-ups"],"_links":{"self":[{"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/posts\/2548","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2548"}],"version-history":[{"count":8,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/posts\/2548\/revisions"}],"predecessor-version":[{"id":2568,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/posts\/2548\/revisions\/2568"}],"wp:attachment":[{"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}