Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added option to configure smokeping as a slave rather than master #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions smokeping.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#===============================================================================

set -o nounset # Treat unset variables as an error
slave=false

### gmail: Configure ssmtp for gmail
# Arguments:
Expand Down Expand Up @@ -46,6 +47,18 @@ AuthPass='"$pass"'
s|^#*\(FromLineOverride=\).*|\1YES|' $conf
}

### slave: configure this instance as a slave
# Arguments:
# master) master server to use
# secret) secret word
slave() { local master="$1" name="$2" secret="$3"
echo $secret > /etc/smokeping/secret.txt
chown smokeping:smokeping /etc/smokeping/secret.txt
chmod 0600 /etc/smokeping/secret.txt
MASTER=$master
NAME=$name
}

### email: Configure owners email address
# Arguments:
# email) your email address
Expand Down Expand Up @@ -141,6 +154,11 @@ Options (fields in '[]' are optional, '<>' are required):
required arg: \"<user>\" - your gmail username
required arg: \"<pass>\" - your gmail password of app password
These are only set in your docker container
-s \"<masterurl;slavename;secret>\" Configure smokeping as slave
required arg: \"<masterurl>\" - master URL to use
required arg: \"<slavename>\" - slave's name to send
required arg: \"<secret>\" - secret to authenticate this slave
These are only set in your docker container
-t \"<site;name;target>[;alert]\" Configure smokeping targets
required arg: \"<site>\" - name for site of tests
required arg: \"<name>\" - name for check
Expand All @@ -156,10 +174,11 @@ The 'command' (if provided and valid) will be run instead of smokeping
exit $RC
}

while getopts ":hg:e:o:t:T:w" opt; do
while getopts ":hg:e:s:o:t:T:w" opt; do
case "$opt" in
h) usage ;;
g) eval gmail $(sed 's/^\|$/"/g; s/;/" "/g' <<< $OPTARG) ;;
s) slave=true && eval slave $(sed 's/^\|$/"/g; s/;/" "/g' <<< $OPTARG) ;;
e) email "$OPTARG" ;;
o) owner "$OPTARG" ;;
t) eval target $(sed 's/^\|$/"/g; s/;/" "/g' <<< $OPTARG) ;;
Expand All @@ -177,6 +196,7 @@ shift $(( OPTIND - 1 ))
[[ "${EMAIL:-""}" ]] && email "$EMAIL"
[[ "${OWNER:-""}" ]] && owner "$OWNER"
[[ "${TARGET:-""}" ]] && eval target $(sed 's/^\|$/"/g; s/;/" "/g' <<< $TARGET)
[[ "${SLAVE:-""}" ]] && slave=true && eval slave $(sed 's/^\|$/"/g; s/;/" "/g' <<< $SLAVE)
[[ "${TZ:-""}" ]] && timezone "$TZ"
[[ "${USERID:-""}" =~ ^[0-9]+$ ]] && usermod -u $USERID -o smokeping
[[ "${GROUPID:-""}" =~ ^[0-9]+$ ]] && groupmod -g $GROUPID -o smokeping
Expand All @@ -190,6 +210,10 @@ chmod -R g+ws /var/cache/smokeping /var/lib/smokeping /run/smokeping 2>&1 |

if [[ $# -ge 1 && -x $(which $1 2>&-) ]]; then
exec "$@"
elif [ $slave == true ]; then
echo "Running as slave instance for ${MASTER}"
su -l ${SPUSER:-smokeping} -s /bin/bash -c \
"exec /usr/sbin/smokeping --nodaemon --logfile=/tmp/log ${DEBUG:+--debug} --master-url=${MASTER} --slave-name=${NAME} --shared-secret=/etc/smokeping/secret.txt --cache-dir=/var/cache/smokeping"
elif [[ $# -ge 1 ]]; then
echo "ERROR: command not found: $1"
exit 13
Expand All @@ -200,4 +224,4 @@ else
su -l ${SPUSER:-smokeping} -s /bin/bash -c \
"exec /usr/sbin/smokeping --logfile=/tmp/log ${DEBUG:+--debug}"
exec lighttpd -D -f /etc/lighttpd/lighttpd.conf
fi
fi