41 lines
669 B
Bash
41 lines
669 B
Bash
|
#!/usr/bin/env bash
|
||
|
|
||
|
action="${1}";
|
||
|
|
||
|
show_help() {
|
||
|
echo "Usage:" >&2;
|
||
|
echo " run.sh <start|reload>" >&2;
|
||
|
}
|
||
|
|
||
|
log_msg() {
|
||
|
echo "[ ${SECONDS} ] >>> mosquitto:run.sh: $*" >&2;
|
||
|
}
|
||
|
|
||
|
if [[ -z "${action}" ]]; then
|
||
|
show_help;
|
||
|
return 0;
|
||
|
fi
|
||
|
|
||
|
log_msg "Running ${action} action";
|
||
|
|
||
|
|
||
|
case "${action}" in
|
||
|
start )
|
||
|
log_msg "Starting mosquitto";
|
||
|
if [[ ! -e "/srv/mosquitto.conf" ]]; then
|
||
|
log_msg "Warning: No configuration file found at /srv/mosquitto.conf";
|
||
|
fi
|
||
|
exec mosquitto --config-file /srv/mosquitto.conf;
|
||
|
;;
|
||
|
|
||
|
reload )
|
||
|
pid="$(pgrep mosquitto)";
|
||
|
log_msg "Reloading by sending SIGHUP to PID ${pid}";
|
||
|
kill -s HUP "${pid}";
|
||
|
;;
|
||
|
|
||
|
* )
|
||
|
show_help;
|
||
|
;;
|
||
|
esac
|