Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Lumberjack - init.d and config files. Copy the init.d script to /etc/init.d/lumberjack and add execute permissions. Copy the config file lumberjack to /etc/default/lumberjack file.
# Create Key
openssl genrsa -des3 -out logstash.key 1024
sudo openssl genrsa -des3 -out logstash.key 1024
# Create CSR
openssl req -new -key logstash.key -out logstash.csr
sudo openssl req -new -key logstash.key -out logstash.csr
# Remove password from key
sudo openssl rsa -in logstash.key.org -out logstash.key
# Create certificate
sudo openssl x509 -req -days 365 -in logstash.csr -signkey server.key -out logstash.crt
sudo openssl x509 -req -days 365 -in logstash.csr -signkey logstash.key -out logstash.crt
LUMBERJACK_OPTIONS="--field origin=dev --host 10.0.0.1 --port 5555 --ssl-ca-path /etc/ssl/logstash.crt /opt/apps/docs/shared/log/logstash_devutility.log"
#! /bin/sh
# BEGIN INIT INFO
# Provides: lumberjack
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
. /lib/lsb/init-functions
name="lumberjack"
# Read configuration variable file if it is present
[ -r /etc/default/$name ] && . /etc/default/$name
LUMBERJACK_BIN="/opt/lumberjack/bin/lumberjack"
test -x $LUMBERJACK_BIN || exit 5
PID_FILE="/var/run/$name.pid"
LOG_FILE="/var/log/$name"
CONFIG_FILE=/etc/default/$name
cwd=`pwd`
LD_LIBRARY_PATH="/opt/lumberjack/lib/"
export LD_LIBRARY_PATH
# Check for missing binaries
LUMBERJACK_BIN="/opt/lumberjack/bin/lumberjack"
test -x $LUMBERJACK_BIN || { echo "$LUMBERJACK_BIN not installed";
if [ "$1" = "stop" ]; then exit 0;
else exit 5; fi; }
# Check for existence of needed config file and read it
test -r $CONFIG_FILE || { echo "$CONFIG_FILE not existing";
if [ "$1" = "stop" ]; then exit 0;
else exit 6; fi; }
# Read config
. $CONFIG_FILE
# Load the rc.status script for this service.
. /etc/rc.status
# Reset status of this service
rc_reset
case $1 in
start)
echo -n "Starting $name: "
## Start daemon with startproc(8). If this fails
## the return value is set appropriately by startproc.
pid=$(startproc -v -p $PID_FILE -l $LOG_FILE $LUMBERJACK_BIN $LUMBERJACK_OPTIONS)
# Remember status and be verbose
rc_status -v
if [[ "$pid" =~ ^[0-9]+$ ]]; then
echo $pid > $PID_FILE
else
exit 1
fi
;;
stop)
echo -n "Stopping $name: "
## Stop daemon with killproc(8) and if this fails
## killproc sets the return value according to LSB.
killproc -p $PID_FILE -TERM $LUMBERJACK_BIN
# Remember status and be verbose
rc_status -v
;;
restart)
echo -n "Restarting $name: "
## Stop the service and regardless of whether it was
## running or not, start it again.
$0 stop
$0 start
# Remember status and be quiet
rc_status
;;
status)
## Check status with checkproc(8), if process is running
## checkproc will return with exit status 0.
# Status has a slightly different for the status command:
# 0 - service running
# 1 - service dead, but /var/run/ pid file exists
# 2 - service dead, but /var/lock/ lock file exists
# 3 - service not running
# NOTE: checkproc returns LSB compliant status values.
checkproc -p $PID_FILE $LUMBERJACK_BIN
# NOTE: rc_status knows that we called this init script with
# "status" option and adapts its messages accordingly.
rc_status -v
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0
#! /bin/sh
# BEGIN INIT INFO
# Provides: lumberjack-nginx
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
. /lib/lsb/init-functions
name="lumberjack-nginx"
# Read configuration variable file if it is present
[ -r /etc/default/$name ] && . /etc/default/$name
lumberjack_bin="/opt/lumberjack/bin/lumberjack.sh"
pid_file="/var/run/$name.pid"
cwd=`pwd`
start () {
command="${lumberjack_bin}"
if start-stop-daemon --start --quiet --oknodo --pidfile "$pid_file" -b -m -N 19 --exec $command -- $LUMBERJACK_OPTIONS; then
log_end_msg 0
else
log_end_msg 1
fi
}
stop () {
start-stop-daemon --stop --quiet --oknodo --pidfile "$pid_file"
}
status () {
status_of_proc -p $pid_file "" "$name"
}
case $1 in
start)
if status; then exit 0; fi
echo -n "Starting $name: "
start
echo "$name."
;;
stop)
echo -n "Stopping $name: "
stop
echo "$name."
;;
restart)
echo -n "Restarting $name: "
stop
sleep 1
start
echo "$name."
;;
status)
status && exit 0 || exit $?
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment