# multiple instances of apcupsd

## gr0x0rd

I'm currently working on a UPS management project in order to shut down all our servers gracefully in the case of a power failure. I've got apcupsd happily installed and configured on the gentoo network management server and connected to a standalone UPS via USB so it will be the last server standing and can delegate to the others.

The remaining UPSes have smart cards installed and are connected via ethernet, so the next step is to set them up with additional instances of apcupsd over snmp. Portage tells me 

```
 * Since version 3.14.0 you can use multiple apcupsd instances to

 * control more than one UPS in a single box.

 * To do this, create a link between /etc/init.d/apcupsd to a new

 * /etc/init.d/apcupsd.something, and it will then load the

 * configuration file at /etc/apcupsd/something.conf.
```

Great! So I 

```
 ln -s /etc/init.d/apcupsd /etc/init.d/apcupsd.UPS03
```

and create a new conf file, /etc/apcupsd/UPS03.conf. However, 

```
/etc/init.d/apcupsd restart
```

 still only restarts the original instance. I can easily run the second instance using 

```
/usr/sbin/apcupsd -f /etc/apcupsd/UPS03.conf
```

, so I could add this to startup manually, but I'd like to do it more elegantly (the gentoo way!) if possible. I've also tried changing the conf file to /etc/apcupsd/apcupsd.UPS03.conf, saw that after googling, but I suppose that will depend on what the devs have set up in the init script.

Is this a bug or am I missing something here?

Thanks,

----------

## Hu

 *gr0x0rd wrote:*   

> The remaining UPSes have smart cards installed and are connected via ethernet, so the next step is to set them up with additional instances of apcupsd over snmp.

 Why not have the single instance on the main Gentoo system control the slave instances?  There seems to be no need to polyinstantiate apcupsd on any single system for your situation.

 *gr0x0rd wrote:*   

> 
> 
> ```
>  * Since version 3.14.0 you can use multiple apcupsd instances to
> 
> ...

 You are missing something.  Each instance of apcupsd created in this way is intended to be wholly independent, so restarting the original apcupsd is not supposed to affect any of the other instances.  If you want to restart one of the secondary instances, use its init script directly: /etc/init.d/apcupsd.UPS03 restart.

----------

## gr0x0rd

Thanks, that's got it! Well, except for the fact that my second UPS isn't responding over snmp, despite being fully accessible via telnet and a browser.   :Mad: 

Not sure I follow you, from what I've read apcupsd can only support one UPS per instance. I have around 15 servers, some of them virtualization base systems running multiple VMs, connected to a number of different UPS devices. What I'm trying to achieve is, in the event of a power failure, if machine a,b and c is connected to UPS x and it's battery level reaches z, the shutdown procedure begins for all machines connected to UPS x based on the order I've predetermined. Can't see how I'd be able to accomplish this with only a single instance of apcupsd unless all servers were connected to a single UPS...

----------

## Hu

 *gr0x0rd wrote:*   

> What I'm trying to achieve is, in the event of a power failure, if machine a,b and c is connected to UPS x and it's battery level reaches z, the shutdown procedure begins for all machines connected to UPS x based on the order I've predetermined. Can't see how I'd be able to accomplish this with only a single instance of apcupsd unless all servers were connected to a single UPS...

 We need to distinguish between multiple instances of apcupsd running on a single Linux system versus multiple Linux systems each running a single instance of apcupsd.  You appear to be trying to do the former.  I suggested doing the latter, where there is one apcupsd on machine A and machine A is connected to the UPS by way of a serial cable or USB cable.  Machines B and C run apcupsd slaves that receive commands from machine A via a TCP connection.  Alternatively, you could run the apcupsd only on machine A, and have part of its powerfailure procedure be to run ssh B /sbin/shutdown -h now.  It would need an ssh key preconfigured so that it could authenticate without human assistance.

----------

