Skip to content
Snippets Groups Projects
Commit 42f1e881 authored by Erick Hitter's avatar Erick Hitter
Browse files

Init script and updated readme

parent d1f0c83b
No related branches found
No related tags found
1 merge request!1Convert to Golang
Pipeline #
......@@ -3,15 +3,20 @@ Log Alerting
Pipe logs to Mattermost (or Slack) webhooks
# Requirements
## Requirements
* Go 1.8.3
# Installation
1. TBD
<!-- 1. `git clone https://git.ethitter.com/debian/eth-log-alerting.git /usr/local/eth-log-alerting`
2. `cp /usr/local/eth-log-alerting/systemd.service /etc/systemd/system/eth_log_alerting.service`
3. `cp /usr/local/eth-log-alerting/defaults /etc/default/eth_log_alerting`
4. Edit `/etc/default/eth_log_alerting`
5. `systemctl daemon-reload`
6. `systemctl enable eth_log_alerting.service`
6. `systemctl start eth_log_alerting.service` -->
## Installation
1. `git clone https://git.ethitter.com/debian/eth-log-alerting.git /usr/local/bin/eth-log-alerting`
1. `cd /usr/local/bin/eth-log-alerting`
1. `go build eth-log-alerting.go`
1. `cp /usr/local/bin/eth-log-alerting/init.sh /etc/init.d/eth-log-alerting`
1. `chmod +x /etc/init.d/eth-log-alerting`
1. `cp /usr/local/bin/eth-log-alerting/config-sample.json /usr/local/bin/eth-log-alerting/config.json`
1. Edit `/usr/local/bin/eth-log-alerting/config.json`
1. `cp /usr/local/bin/eth-log-alerting/defaults /etc/default/eth_log_alerting`
1. Edit `/etc/default/eth_log_alerting`
1. `update-rc.d eth-log-alerting defaults`
1. `/etc/init.d/eth-log-alerting start`
# DAEMON="/usr/local/bin/eth-log-alerting/eth-log-alerting"
# DAEMON_ARGS="-config /usr/local/bin/eth-log-alerting/config.json"
# USER="www-data"
init.sh 0 → 100755
#!/bin/sh
### BEGIN INIT INFO
# Provides: eth-log-alerting
# Required-Start: $network $local_fs
# Required-Stop: $network $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Log alerting via Mattermost
# Description: Pipe myriad logs to Mattermost webhooks
### END INIT INFO
. /lib/lsb/init-functions
NAME=eth-log-alerting
USER=root
DAEMON="/usr/local/bin/${NAME}/${NAME}"
DAEMON_ARGS="-config /usr/local/bin/${NAME}/config.json"
PIDFILE="/var/run/${NAME}.pid"
# Overrides
[ -f "/etc/default/$NAME" ] && . /etc/default/$NAME
# If the daemon is not there, then exit.
test -x $DAEMON || exit 5
case $1 in
start)
# Checked the PID file exists and check the actual status of process
if [ -e $PIDFILE ]; then
status_of_proc -p $PIDFILE $DAEMON "$NAME process" && status="0" || status="$?"
# If the status is SUCCESS then don't need to start again.
if [ $status = "0" ]; then
exit # Exit
fi
fi
# Start the daemon.
log_daemon_msg "Starting the process" "$NAME"
# Start the daemon with the help of start-stop-daemon
# Log the message appropriately
if start-stop-daemon --start --chuid $USER --background --oknodo --pidfile $PIDFILE --make-pidfile --exec $DAEMON -- "$DAEMON_ARGS"; then
log_end_msg 0
else
log_end_msg 1
fi
;;
stop)
# Stop the daemon.
if [ -e $PIDFILE ]; then
status_of_proc -p $PIDFILE $DAEMON "Stoppping the $NAME process" && status="0" || status="$?"
if [ "$status" = 0 ]; then
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
/bin/rm -rf $PIDFILE
fi
else
log_daemon_msg "$NAME process is not running"
log_end_msg 0
fi
;;
restart)
# Restart the daemon.
$0 stop && sleep 2 && $0 start
;;
status)
# Check the status of the process.
if [ -e $PIDFILE ]; then
status_of_proc -p $PIDFILE $DAEMON "$NAME process" && exit 0 || exit $?
else
log_daemon_msg "$NAME Process is not running"
log_end_msg 0
fi
;;
reload)
# Reload the process. Basically sending some signal to a daemon to reload
# it configurations.
if [ -e $PIDFILE ]; then
start-stop-daemon --stop --signal USR1 --quiet --pidfile $PIDFILE --name $NAME
log_success_msg "$NAME process reloaded successfully"
else
log_failure_msg "$PIDFILE does not exists"
fi
;;
*)
# For invalid arguments, print the usage message.
echo "Usage: $0 {start|stop|restart|reload|status}"
exit 2
;;
esac
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment