Last active
February 23, 2021 09:03
-
-
Save begleynk/973322494a72ce33da36 to your computer and use it in GitHub Desktop.
Setup Papertrail for Elastic Beanstalk
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
# This is an example .ebextensions config for setting up Papertrail with AWS Elastic Beanstalk, with the ability | |
# to access environment variables within the created config files. | |
# This is done by not directly creating /etc/log_files.yml, but by having a shell script create it for us: | |
# | |
# /home/ec2-user/create_log_file.sh (created in the "files" block) | |
# - Creates /etc/log_files.yml | |
# - Can include environment variables from the host | |
# | |
# The first container command (00_create_log_file_yml) will execute the script. | |
# | |
# Most of this config was taken from https://gist.github.com/leonsodhi/8eb28e06b2c35c136bf8#file-01papertrail-config | |
sources: | |
/home/ec2-user: https://github.com/papertrail/remote_syslog2/releases/download/<REMOTE SYSLOG VERSION>/remote_syslog_linux_amd64.tar.gz | |
files: | |
"/home/ec2-user/create_log_file.sh": | |
mode: "000755" | |
owner: root | |
group: root | |
encoding: plain | |
content: | | |
#!/bin/bash | |
file=/etc/log_files.yml | |
touch $file | |
chown root:root $file | |
chmod 644 $file | |
cat > $file <<EOF | |
files: | |
- /path/to/$YOUR_ENV_VARIABLE.log | |
hostname: $HOSTNAME | |
destination: | |
host: <YOUR PAPERTRAIL HOST> | |
port: <YOUR PAPERTRAIL PORT> | |
protocol: tls | |
EOF | |
"/etc/init.d/remote_syslog": | |
mode: "00555" | |
owner: root | |
group: root | |
encoding: plain | |
content: | | |
#!/bin/bash | |
# | |
# remote_syslog This shell script takes care of starting and stopping | |
# remote_syslog daemon | |
# | |
# chkconfig: - 58 74 | |
# description: papertrail/remote_syslog \ | |
# https://github.com/papertrail/remote_syslog2/blob/master/examples/remote_syslog.init.d | |
### BEGIN INIT INFO | |
# Provides: remote_syslog | |
# Required-Start: $network $local_fs $remote_fs | |
# Required-Stop: $network $local_fs $remote_fs | |
# Should-Start: $syslog $named ntpdate | |
# Should-Stop: $syslog $named | |
# Short-Description: start and stop remote_errolog | |
# Description: papertrail/remote_syslog2 | |
# https://github.com/papertrail/remote_syslog2/blob/master/examples/remote_syslog.init.d | |
### END INIT INFO | |
# Source function library. | |
. /etc/init.d/functions | |
# Source networking configuration. | |
. /etc/sysconfig/network | |
prog="/usr/local/bin/remote_syslog" | |
config="/etc/log_files.yml" | |
pid_dir="/var/run" | |
EXTRAOPTIONS="" | |
pid_file="$pid_dir/remote_syslog.pid" | |
PATH=/sbin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin | |
RETVAL=0 | |
is_running(){ | |
# Do we have PID-file? | |
if [ -f "$pid_file" ]; then | |
# Check if proc is running | |
pid=`cat "$pid_file" 2> /dev/null` | |
if [[ $pid != "" ]]; then | |
exepath=`readlink /proc/"$pid"/exe 2> /dev/null` | |
exe=`basename "$exepath"` | |
if [[ $exe == "remote_syslog" ]]; then | |
# Process is running | |
return 0 | |
fi | |
fi | |
fi | |
return 1 | |
} | |
start(){ | |
echo -n $"Starting $prog: " | |
unset HOME MAIL USER USERNAME | |
$prog -c $config --pid-file=$pid_file $EXTRAOPTIONS | |
RETVAL=$? | |
echo | |
return $RETVAL | |
} | |
stop(){ | |
echo -n $"Stopping $prog: " | |
if (is_running); then | |
kill `cat $pid_file` | |
RETVAL=$? | |
echo | |
return $RETVAL | |
else | |
echo "$pid_file not found" | |
fi | |
} | |
status(){ | |
echo -n $"Checking for $pid_file: " | |
if (is_running); then | |
echo "found" | |
else | |
echo "not found" | |
fi | |
} | |
reload(){ | |
restart | |
} | |
restart(){ | |
stop | |
start | |
} | |
condrestart(){ | |
is_running && restart | |
return 0 | |
} | |
# See how we were called. | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
status) | |
status | |
;; | |
restart) | |
restart | |
;; | |
reload) | |
reload | |
;; | |
condrestart) | |
condrestart | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}" | |
RETVAL=1 | |
esac | |
exit $RETVAL | |
container_commands: | |
00_create_log_file_yml: | |
command: "/home/ec2-user/create_log_file.sh" | |
01_stop_service: | |
command: "/sbin/service remote_syslog stop" | |
ignoreErrors: true | |
02_install_remote_syslog_binary: | |
command: "cp /home/ec2-user/remote_syslog/remote_syslog /usr/local/bin" | |
03_enable_service: | |
command: "/sbin/chkconfig remote_syslog on" | |
04_start_service: | |
command: "/sbin/service remote_syslog restart" | |
ignoreErrors: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perfect, it's working fine. Thanks. (got difficulties with official script)