Comments (4)
from apcupsd.
So here's the start.sh I'm using for my container builds ATM. I still haven't incorporated the code for modifying hosts.conf at container start, but I'll post what I'm doing in the apcupsd-cgi container so you can see what it looks like:
#! /bin/bash
# Config file moves transferred from Dockerfile to support
# binding /etc/apcupsd to user-specified host directory
cp /opt/apcupsd/apcupsd /etc/default/apcupsd
# Check if /etc/apcupsd files exist, and copy them from /opt/apcupsd if they don't
files=( apcupsd.conf hosts.conf doshutdown apccontrol changeme commfailure commok killpower multimon.conf offbattery onbattery ups-monitor )
for i in "${files[@]}"
do
if [ ! -f /etc/apcupsd/$i ]; then
cp /opt/apcupsd/$i /etc/apcupsd/$i \
&& echo "No existing $i found"
else
echo "Existing $i found, and will be used"
fi
done
# Check if UPSNAME environment variable is set, and if so update apcupsd.conf
if [ ! -z $UPSNAME ]; then
sed -i 's|^UPSNAME.*|UPSNAME '"$UPSNAME"'|' /etc/apcupsd/apcupsd.conf \
&& echo "UPSNAME set to: \"$UPSNAME\""
fi
# Check if UPSCABLE environment variable is set, and if so update apcupsd.conf
if [ ! -z $UPSCABLE ]; then
sed -i 's|^UPSCABLE.*|UPSCABLE '"$UPSCABLE"'|' /etc/apcupsd/apcupsd.conf \
&& echo "UPSCABLE set to: \"$UPSCABLE\""
fi
# Check if UPSTYPE environment variable is set, and if so update apcupsd.conf
if [ ! -z $UPSTYPE ]; then
sed -i 's|^UPSTYPE.*|UPSTYPE '"$UPSTYPE"'|' /etc/apcupsd/apcupsd.conf \
&& echo "UPSTYPE set to: \"$UPSTYPE\""
fi
# Check if DEVICE environment variable is set, and if so update apcupsd.conf
if [ ! -z $DEVICE ]; then
sed -i 's|^DEVICE.*|DEVICE '"$DEVICE"'|' /etc/apcupsd/apcupsd.conf \
&& sed -i 's|^#DEVICE /dev/ttyS0.*|DEVICE '"$DEVICE"'|' /etc/apcupsd/apcupsd.conf \
&& echo "DEVICE set to: \"$DEVICE\""
fi
# Check if POLLTIME environment variable is set, and if so update apcupsd.conf
if [ ! -z $POLLTIME ]; then
sed -i 's|^POLLTIME.*|POLLTIME '"$POLLTIME"'|' /etc/apcupsd/apcupsd.conf \
&& sed -i 's|^#POLLTIME 60.*|POLLTIME '"$POLLTIME"'|' /etc/apcupsd/apcupsd.conf \
&& echo "POLLTIME set to: \"$POLLTIME\""
fi
# Check if NETSERVER environment variable is set, and if so update apcupsd.conf
if [ ! -z $NETSERVER ]; then
sed -i 's|^NETSERVER.*|NETSERVER '"$NETSERVER"'|' /etc/apcupsd/apcupsd.conf \
&& echo "NETSERVER set to: \"$NETSERVER\""
fi
# Check if NISIP environment variable is set, and if so update apcupsd.conf
if [ ! -z $NISIP ]; then
sed -i 's|^NISIP.*|NISIP '"$NISIP"'|' /etc/apcupsd/apcupsd.conf \
&& echo "NISIP set to: \"$NISIP\""
fi
# Check if NISPORT environment variable is set, and if so update apcupsd.conf
if [ ! -z $NISPORT ]; then
sed -i 's|^NISPORT.*|NISPORT '"$NISPORT"'|' /etc/apcupsd/apcupsd.conf \
&& echo "NISPORT set to: \"$NISPORT\""
fi
# Check if NONBATTERYDELAYISPORT environment variable is set, and if so update apcupsd.conf
if [ ! -z $ONBATTERYDELAY ]; then
sed -i 's|^ONBATTERYDELAY.*|ONBATTERYDELAY '"$ONBATTERYDELAY"'|' /etc/apcupsd/apcupsd.conf \
&& echo "ONBATTERYDELAY set to: \"$ONBATTERYDELAY\""
fi
# Check if BATTERYLEVEL environment variable is set, and if so update apcupsd.conf
if [ ! -z $BATTERYLEVEL ]; then
sed -i 's|^BATTERYLEVEL.*|BATTERYLEVEL '"$BATTERYLEVEL"'|' /etc/apcupsd/apcupsd.conf \
&& echo "BATTERYLEVEL set to: \"$BATTERYLEVEL\""
fi
# Check if MINUTES environment variable is set, and if so update apcupsd.conf
if [ ! -z $MINUTES ]; then
sed -i 's|^MINUTES.*|MINUTES '"$MINUTES"'|' /etc/apcupsd/apcupsd.conf \
&& echo "MINUTES set to: \"$MINUTES\""
fi
# Check if TIMEOUT environment variable is set, and if so update apcupsd.conf
if [ ! -z $TIMEOUT ]; then
sed -i 's|^TIMEOUT.*|TIMEOUT '"$TIMEOUT"'|' /etc/apcupsd/apcupsd.conf \
&& echo "TIMEOUT set to: \"$TIMEOUT\""
fi
# Check if SELFTEST environment variable is set, and if so update apcupsd.conf
if [ ! -z $SELFTEST ]; then
sed -i 's|^SELFTEST.*|SELFTEST '"$SELFTEST"'|' /etc/apcupsd/apcupsd.conf \
&& sed -i 's|^#SELFTEST 336.*|SELFTEST '"$SELFTEST"'|' /etc/apcupsd/apcupsd.conf \
&& echo "SELFTEST set to: \"$SELFTEST\""
fi
/sbin/apcupsd -b
I'm planning to replace all the environment variable checks with an array as well.
Here's the array I'm using to update hosts.conf in the apcupsd-cgi container. No reason to add that functionality to this container BTW, as only one instance is required for an entire network, whereas I'll have dozens of instances of the apcupsd container running before I'm done. :-)
I've only defined one environment variable "array" so far in apcupsd, but two are needed for this approach, one for hostnames/IPs and one for UPS/Slave names:
# populate two arrays with host and UPS names
HOSTS=( $UPSHOSTS )
NAMES=( $UPSNAMES )
# add monitors to hosts.conf for each host and UPS name combo
for ((i=0;i<${#HOSTS[@]};i++))
do
echo "MONITOR ${HOSTS[$i]} \"${NAMES[$i]}\"" >> /etc/apcupsd/hosts.conf
echo "MONITOR ${HOSTS[$i]} \"${NAMES[$i]}\""
done
from apcupsd.
from apcupsd.
seems like a duplicate by now. and our conversation is on the other related thread.
from apcupsd.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apcupsd.