blob: b349b5e789af9d7178d86b5dc623e8927132d33b [file] [log] [blame]
#!/bin/sh
#
### BEGIN INIT INFO
# Provides: gfiber-loguploader
# Required-Start: $syslog $remote_fs
# Required-Stop: $syslog $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: GFiber loguploader client
### END INIT INFO
[ -x /usr/bin/upload-logs ] || exit 0
. /lib/lsb/init-functions
atomic_stdin() {
rm -f "$1" "$1.new"
cat >"$1.new"
mv "$1.new" "$1"
}
case "$1" in
start)
log_daemon_msg "Starting GFiber log uploader" "upload-logs"
if ! [ -e /etc/ssl/certs/device.pem -a \
-e /etc/ssl/private/device.key ]; then
echo >&2
echo "Cert missing: /etc/ssl/certs/device.pem and /etc/ssl/private/device.key." >&2
echo >&2
log_end_msg 1
exit 1
fi
rm -f /tmp/ssl
ln -sf /etc/ssl/. /tmp/ssl
uname -r | sed 's/ /-/g' | atomic_stdin /etc/version
uname | atomic_stdin /tmp/platform
# Our hostnames are something like hostname.cluster.whatever.com.
# We want the hostname.cluster part to be part of the certname, but
# sadly the name field in our certs isn't super happy about that, so
# let's use _ instead of dot, where relevant.
hostname -f |
sed -e 's/\([^.]*\.[^.]*\).*/\1/' \
-e 's/\./_/g' |
atomic_stdin /tmp/serial
cd /
upload-logs-loop </dev/null &
log_end_msg 0
exit 0
;;
stop)
log_daemon_msg "Stopping GFiber log uploader" "upload-logs"
pkill upload-logs-loop
pkill upload-logs
pkill -f prefix-logs
log_end_msg 0
exit 0
;;
reload|force-reload|restart)
$0 stop; $0 start
;;
status)
pgrep upload-logs >/dev/null
exit $?
;;
*)
echo "Usage: $0 {start|stop|restart|reload|force-reload|status}"
exit 1
esac