Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../lib/telegraf/scripts
File: init.sh
#! /usr/bin/env bash
[0] Fix | Delete
[1] Fix | Delete
# chkconfig: 2345 99 01
[2] Fix | Delete
# description: Telegraf daemon
[3] Fix | Delete
[4] Fix | Delete
### BEGIN INIT INFO
[5] Fix | Delete
# Provides: telegraf
[6] Fix | Delete
# Required-Start: $all
[7] Fix | Delete
# Required-Stop: $remote_fs $syslog
[8] Fix | Delete
# Default-Start: 2 3 4 5
[9] Fix | Delete
# Default-Stop: 0 1 6
[10] Fix | Delete
# Short-Description: Start telegraf at boot time
[11] Fix | Delete
### END INIT INFO
[12] Fix | Delete
[13] Fix | Delete
# this init script supports three different variations:
[14] Fix | Delete
# 1. New lsb that define start-stop-daemon
[15] Fix | Delete
# 2. Old lsb that don't have start-stop-daemon but define, log, pidofproc and killproc
[16] Fix | Delete
# 3. Centos installations without lsb-core installed
[17] Fix | Delete
#
[18] Fix | Delete
# In the third case we have to define our own functions which are very dumb
[19] Fix | Delete
# and expect the args to be positioned correctly.
[20] Fix | Delete
[21] Fix | Delete
# Command-line options that can be set in /etc/default/telegraf. These will override
[22] Fix | Delete
# any config file values.
[23] Fix | Delete
TELEGRAF_OPTS=
[24] Fix | Delete
[25] Fix | Delete
USER=telegraf
[26] Fix | Delete
GROUP=telegraf
[27] Fix | Delete
[28] Fix | Delete
if [ -r /lib/lsb/init-functions ]; then
[29] Fix | Delete
source /lib/lsb/init-functions
[30] Fix | Delete
fi
[31] Fix | Delete
[32] Fix | Delete
DEFAULT=/etc/default/telegraf
[33] Fix | Delete
[34] Fix | Delete
if [ -r $DEFAULT ]; then
[35] Fix | Delete
set -o allexport
[36] Fix | Delete
source $DEFAULT
[37] Fix | Delete
set +o allexport
[38] Fix | Delete
fi
[39] Fix | Delete
[40] Fix | Delete
if [ -z "$STDOUT" ]; then
[41] Fix | Delete
STDOUT=/dev/null
[42] Fix | Delete
fi
[43] Fix | Delete
if [ ! -f "$STDOUT" ]; then
[44] Fix | Delete
mkdir -p `dirname $STDOUT`
[45] Fix | Delete
fi
[46] Fix | Delete
[47] Fix | Delete
if [ -z "$STDERR" ]; then
[48] Fix | Delete
STDERR=/var/log/telegraf/telegraf.log
[49] Fix | Delete
fi
[50] Fix | Delete
if [ ! -f "$STDERR" ]; then
[51] Fix | Delete
mkdir -p `dirname $STDERR`
[52] Fix | Delete
fi
[53] Fix | Delete
[54] Fix | Delete
OPEN_FILE_LIMIT=65536
[55] Fix | Delete
[56] Fix | Delete
function pidofproc() {
[57] Fix | Delete
if [ $# -ne 3 ]; then
[58] Fix | Delete
echo "Expected three arguments, e.g. $0 -p pidfile daemon-name"
[59] Fix | Delete
fi
[60] Fix | Delete
[61] Fix | Delete
if [ ! -f "$2" ]; then
[62] Fix | Delete
return 1
[63] Fix | Delete
fi
[64] Fix | Delete
[65] Fix | Delete
local pidfile=`cat $2`
[66] Fix | Delete
[67] Fix | Delete
if [ "x$pidfile" == "x" ]; then
[68] Fix | Delete
return 1
[69] Fix | Delete
fi
[70] Fix | Delete
[71] Fix | Delete
if ps --pid "$pidfile" | grep -q $(basename $3); then
[72] Fix | Delete
return 0
[73] Fix | Delete
fi
[74] Fix | Delete
[75] Fix | Delete
return 1
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
function killproc() {
[79] Fix | Delete
if [ $# -ne 3 ]; then
[80] Fix | Delete
echo "Expected three arguments, e.g. $0 -p pidfile signal"
[81] Fix | Delete
fi
[82] Fix | Delete
[83] Fix | Delete
pid=`cat $2`
[84] Fix | Delete
[85] Fix | Delete
kill -s $3 $pid
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
function log_failure_msg() {
[89] Fix | Delete
echo "$@" "[ FAILED ]"
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
function log_success_msg() {
[93] Fix | Delete
echo "$@" "[ OK ]"
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
# Process name ( For display )
[97] Fix | Delete
name=telegraf
[98] Fix | Delete
[99] Fix | Delete
# Daemon name, where is the actual executable
[100] Fix | Delete
daemon=/usr/bin/telegraf
[101] Fix | Delete
[102] Fix | Delete
# pid file for the daemon
[103] Fix | Delete
pidfile=/var/run/telegraf/telegraf.pid
[104] Fix | Delete
piddir=`dirname $pidfile`
[105] Fix | Delete
[106] Fix | Delete
if [ ! -d "$piddir" ]; then
[107] Fix | Delete
mkdir -p $piddir
[108] Fix | Delete
chown $USER:$GROUP $piddir
[109] Fix | Delete
fi
[110] Fix | Delete
[111] Fix | Delete
# Configuration file
[112] Fix | Delete
config=/etc/telegraf/telegraf.conf
[113] Fix | Delete
confdir=/etc/telegraf/telegraf.d
[114] Fix | Delete
[115] Fix | Delete
# If the daemon is not there, then exit.
[116] Fix | Delete
[ -x $daemon ] || exit 5
[117] Fix | Delete
[118] Fix | Delete
case $1 in
[119] Fix | Delete
start)
[120] Fix | Delete
# Checked the PID file exists and check the actual status of process
[121] Fix | Delete
if [ -e "$pidfile" ]; then
[122] Fix | Delete
if pidofproc -p $pidfile $daemon > /dev/null; then
[123] Fix | Delete
log_failure_msg "$name process is running"
[124] Fix | Delete
else
[125] Fix | Delete
log_failure_msg "$name pidfile has no corresponding process; ensure $name is stopped and remove $pidfile"
[126] Fix | Delete
fi
[127] Fix | Delete
exit 0
[128] Fix | Delete
fi
[129] Fix | Delete
[130] Fix | Delete
# Bump the file limits, before launching the daemon. These will carry over to
[131] Fix | Delete
# launched processes.
[132] Fix | Delete
ulimit -n $OPEN_FILE_LIMIT
[133] Fix | Delete
if [ $? -ne 0 ]; then
[134] Fix | Delete
log_failure_msg "set open file limit to $OPEN_FILE_LIMIT"
[135] Fix | Delete
fi
[136] Fix | Delete
[137] Fix | Delete
log_success_msg "Starting the process" "$name"
[138] Fix | Delete
if command -v startproc >/dev/null; then
[139] Fix | Delete
startproc -u "$USER" -g "$GROUP" -p "$pidfile" -q -- "$daemon" -pidfile "$pidfile" -config "$config" -config-directory "$confdir" $TELEGRAF_OPTS
[140] Fix | Delete
elif which start-stop-daemon > /dev/null 2>&1; then
[141] Fix | Delete
start-stop-daemon --chuid $USER:$GROUP --start --quiet --pidfile $pidfile --exec $daemon -- -pidfile $pidfile -config $config -config-directory $confdir $TELEGRAF_OPTS >>$STDOUT 2>>$STDERR &
[142] Fix | Delete
else
[143] Fix | Delete
su -s /bin/sh -c "nohup $daemon -pidfile $pidfile -config $config -config-directory $confdir $TELEGRAF_OPTS >>$STDOUT 2>>$STDERR &" $USER
[144] Fix | Delete
fi
[145] Fix | Delete
log_success_msg "$name process was started"
[146] Fix | Delete
;;
[147] Fix | Delete
[148] Fix | Delete
stop)
[149] Fix | Delete
# Stop the daemon.
[150] Fix | Delete
if [ -e $pidfile ]; then
[151] Fix | Delete
if pidofproc -p $pidfile $daemon > /dev/null; then
[152] Fix | Delete
# periodically signal until process exists
[153] Fix | Delete
while true; do
[154] Fix | Delete
if ! pidofproc -p $pidfile $daemon > /dev/null; then
[155] Fix | Delete
break
[156] Fix | Delete
fi
[157] Fix | Delete
killproc -p $pidfile SIGTERM 2>&1 >/dev/null
[158] Fix | Delete
sleep 2
[159] Fix | Delete
done
[160] Fix | Delete
[161] Fix | Delete
log_success_msg "$name process was stopped"
[162] Fix | Delete
rm -f $pidfile
[163] Fix | Delete
fi
[164] Fix | Delete
else
[165] Fix | Delete
log_failure_msg "$name process is not running"
[166] Fix | Delete
fi
[167] Fix | Delete
;;
[168] Fix | Delete
[169] Fix | Delete
reload)
[170] Fix | Delete
# Reload the daemon.
[171] Fix | Delete
if [ -e $pidfile ]; then
[172] Fix | Delete
if pidofproc -p $pidfile $daemon > /dev/null; then
[173] Fix | Delete
if killproc -p $pidfile SIGHUP; then
[174] Fix | Delete
log_success_msg "$name process was reloaded"
[175] Fix | Delete
else
[176] Fix | Delete
log_failure_msg "$name failed to reload service"
[177] Fix | Delete
fi
[178] Fix | Delete
fi
[179] Fix | Delete
else
[180] Fix | Delete
log_failure_msg "$name process is not running"
[181] Fix | Delete
fi
[182] Fix | Delete
;;
[183] Fix | Delete
[184] Fix | Delete
restart)
[185] Fix | Delete
# Restart the daemon.
[186] Fix | Delete
$0 stop && sleep 2 && $0 start
[187] Fix | Delete
;;
[188] Fix | Delete
[189] Fix | Delete
status)
[190] Fix | Delete
# Check the status of the process.
[191] Fix | Delete
if [ -e $pidfile ]; then
[192] Fix | Delete
if pidofproc -p $pidfile $daemon > /dev/null; then
[193] Fix | Delete
log_success_msg "$name Process is running"
[194] Fix | Delete
exit 0
[195] Fix | Delete
else
[196] Fix | Delete
log_failure_msg "$name Process is not running"
[197] Fix | Delete
exit 1
[198] Fix | Delete
fi
[199] Fix | Delete
else
[200] Fix | Delete
log_failure_msg "$name Process is not running"
[201] Fix | Delete
exit 3
[202] Fix | Delete
fi
[203] Fix | Delete
;;
[204] Fix | Delete
[205] Fix | Delete
version)
[206] Fix | Delete
$daemon version
[207] Fix | Delete
;;
[208] Fix | Delete
[209] Fix | Delete
*)
[210] Fix | Delete
# For invalid arguments, print the usage message.
[211] Fix | Delete
echo "Usage: $0 {start|stop|restart|status|version}"
[212] Fix | Delete
exit 2
[213] Fix | Delete
;;
[214] Fix | Delete
esac
[215] Fix | Delete
[216] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function