# IMPORTANT: this example is potentially out of date. The latest version can be found here: https://github.com/papertrail/remote_syslog2/blob/master/examples/remote_syslog.ebextensions.config | |
# See http://help.papertrailapp.com/kb/hosting-services/aws-elastic-beanstalk/ | |
# Usage: | |
# - replace <VERSION> with the version of remote_syslog2 you want to use. Example: .../download/v0.14/remote_syslog_linux_amd64.tar.gz | |
# - replace <YOUR-TRACKED-FILES> with the files you want to monitor for new log lines. Example: - /var/log/httpd/access_log | |
# - replace <YOUR-APP-NAME> with the name of the application | |
# - replace <YOUR-LOG-DESTINATION> and <YOUR-PORT-NUMBER> with the values shown under log destinations: https://papertrailapp.com/account/destinations | |
sources: | |
/home/ec2-user: https://github.com/papertrail/remote_syslog2/releases/download/<VERSION>/remote_syslog_linux_amd64.tar.gz | |
files: | |
"/etc/log_files.yml": | |
mode: "00644" | |
owner: root | |
group: root | |
encoding: plain | |
content: | | |
files: | |
- <YOUR-TRACKED-FILES> | |
hostname: <YOUR-APP-NAME> | |
destination: | |
host: <YOUR-LOG-DESTINATION> | |
port: <YOUR-PORT-NUMBER> | |
protocol: tls | |
"/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 | |
commands: | |
00_stop_service: | |
command: "/sbin/service remote_syslog stop" | |
ignoreErrors: true | |
01_install_remote_syslog_binary: | |
command: "cp /home/ec2-user/remote_syslog/remote_syslog /usr/local/bin" | |
02_enable_service: | |
command: "/sbin/chkconfig remote_syslog on" | |
03_start_service: | |
command: "/sbin/service remote_syslog restart" | |
ignoreErrors: true |
This comment has been minimized.
This comment has been minimized.
Thanks, @gbleu. I've added it into the config. |
This comment has been minimized.
This comment has been minimized.
@leonsodhi, Is there a way I could use this config file to cover different environments? For example I'd like to be able to use something like this:
This way I will be able to distinguish papertrail log entries based on different hostnames. |
This comment has been minimized.
This comment has been minimized.
@chirillc I need exactly the same thing. Did you figure it out somehow? |
This comment has been minimized.
This comment has been minimized.
@chirillc, @xaralis, an update is coming that will allow you to set an environment name. If you'd like to get an early release and make a few changes yourself, fire a mail into |
This comment has been minimized.
This comment has been minimized.
I'm in the same boat |
This comment has been minimized.
This comment has been minimized.
This comment chain is really old, but this gist is linked from Papertrail's official docs so I'm sure other's still read this. This is what I did to get app/host specific names in a script: eval export PAPERTRAIL_HOSTNAME=$PAPERTRAIL_HOSTNAME # can expand $HOSTNAME
sed -i "s/.*hostname:.*/hostname: $PAPERTRAIL_HOSTNAME/" /etc/log_files.yml I'm using container_commands to retrieve GUI's Environment Properties as env vars. So if I set PAPERTRAIL_HOSTNAME as nextkillerapp-$HOSTNAME, it will expand to nextkillerapp-ip-10-1-2-3 in the papertrail config. I did this for all of the env vars, but here's an an example ebextension for the hostname: https://gist.github.com/u2mejc/f9187e2a15c7e85a5135 If enough people find it useful, I can rework it so that all of the vars are exposed in the gui. |
This comment has been minimized.
This comment has been minimized.
@leonsodhi - any news on the release of env support? |
This comment has been minimized.
This comment has been minimized.
@dsshap none yet, I'm afraid. If you'd like a copy of what I have ATM, shoot a mail into I still haven't had a chance to test it myself so I don't want to replace this gist just yet. |
This comment has been minimized.
This comment has been minimized.
For others who want to use environmental variables in this script, check out Referencing env variables from Elastic Beanstalk .ebextensions config files and While variables are available to the ebextensions script (which, in Ruby, would be the Details: Linux server configuration sections |
This comment has been minimized.
This comment has been minimized.
I don't get it. Where am I supposed to know what version I want? The newest? What is it? |
This comment has been minimized.
This comment has been minimized.
@aop I think it's just abstracting the version out to avoid having this go out of date too quickly. I chose to put in |
This comment has been minimized.
This comment has been minimized.
This config now lives in the remote_syslog2 examples directory. |
This comment has been minimized.
The first time went fine, but then I started receiving errors like :
[ERROR] Command 01_install_remote_syslog_binary (cp /home/ec2-user/remote_syslog/remote_syslog /usr/local/bin) failed
[DEBUG] Command 01_install_remote_syslog_binary output: cp: cannot create regular file ‘/usr/local/bin/remote_syslog’: Text file busy
Adding this command fixed it :
00_stop_service:
command: "/sbin/service remote_syslog stop"
ignoreErrors: true