Skip to content

Instantly share code, notes, and snippets.

@hajowieland
Last active April 8, 2020 13:38
Show Gist options
  • Save hajowieland/201c54c9ceec65bdc42092abb7cc7dc6 to your computer and use it in GitHub Desktop.
Save hajowieland/201c54c9ceec65bdc42092abb7cc7dc6 to your computer and use it in GitHub Desktop.
Install and configure journald-cloudwatch-logs on EC2
# https://github.com/saymedia/journald-cloudwatch-logs
function install_journald_cloudwatch_logs() {
cd /tmp/ || return
wget https://github.com/saymedia/journald-cloudwatch-logs/releases/download/v0.0.1/journald-cloudwatch-logs-linux.zip
unzip journald-cloudwatch-logs-linux.zip
mv journald-cloudwatch-logs/journald-cloudwatch-logs /usr/local/bin/journald-cloudwatch-logs
mkdir -p /var/lib/journald-cloudwatch-logs
touch /var/lib/journald-cloudwatch-logs/state
chown ec2-user:ec2-user /var/lib/journald-cloudwatch-logs/state
}
function create_journald_cloudwatch_logs_conf() {
cat << 'EOF' > /usr/local/etc/journald-cloudwatch-logs.conf
log_group = "${log_group_name}"
state_file = "/var/lib/journald-cloudwatch-logs/state"
EOF
chown ec2-user:ec2-user /usr/local/etc/journald-cloudwatch-logs.conf
}
function create_journald_cloudwatch_logs_systemd() {
cat << 'EOF' > /etc/systemd/system/journald-cloudwatch.service
[Unit]
Description=journald-cloudwatch-logs
Wants=basic.target
After=basic.target network.target
[Service]
User=ec2-user
Group=ec2-user
ExecStart=/usr/local/bin/journald-cloudwatch-logs /usr/local/etc/journald-cloudwatch-logs.conf
KillMode=process
Restart=on-failure
RestartSec=42s
EOF
}
function start_journald_cloudwatch_logs() {
echo "Install journald-cloudwatch"
install_journald_cloudwatch_logs
echo "Creating journald-cloudwatch-logs.conf"
create_journald_cloudwatch_logs_conf
echo "Creating journald-cloudwatch-logs systemd unit file"
create_journald_cloudwatch_logs_systemd
echo "Enable journald-cloudwatch at boot via systemd"
systemctl daemon-reload
systemctl enable journald-cloudwatch
echo "Starting journald-cloudwatch"
systemctl start journald-cloudwatch
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment