Last active
July 26, 2016 10:36
-
-
Save factorin-j/02c2f799de92196de45d1ec9cab30168 to your computer and use it in GitHub Desktop.
/etc/init.d/fluentd service file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin | |
| NAME="fluentd" | |
| DAEMON="/usr/local/bin/${NAME}" | |
| PID_FILE="/var/run/${NAME}.pid" | |
| LOG_FILE="/var/log/${NAME}.log" | |
| SCRIPT_NAME="/etc/init.d/${NAME}" | |
| DAEMON_ARGS="-d ${PID_FILE} -o ${LOG_FILE}" | |
| usage() { | |
| echo "Usage: $SCRIPT_NAME {start|stop|restart}" >&2 | |
| exit 3 | |
| } | |
| error() { | |
| echo "$1" && exit 1 | |
| } | |
| start() { | |
| [[ -f "${PID_FILE}" ]] && error "${NAME}: instance already running." | |
| echo -n "Starting service ${NAME}.. " | |
| ${DAEMON} ${DAEMON_ARGS} >> ${LOG_FILE} | |
| [ $? -eq 0 ] && echo "(ok)" || error "(failed)" | |
| } | |
| stop() { | |
| [[ ! -f "${PID_FILE}" ]] && error "${NAME}: no active instance found." | |
| local PID=$(cat ${PID_FILE}) | |
| echo -n "Stopping service ${NAME}.. " | |
| pkill -F ${PID_FILE} | |
| [ $? -ne 0 ] && error "(failed)" | |
| while test -d "/proc/${PID}"; do sleep .1; done | |
| rm /tmp/SERVERENGINE_SOCKETMANAGER_*_$(cat ${PID_FILE}) | |
| rm ${PID_FILE} | |
| echo "(ok)" | |
| } | |
| restart() { | |
| stop && start | |
| } | |
| case "$1" in | |
| restart) restart;; | |
| start) start;; | |
| stop) stop;; | |
| *) usage;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment