Skip to content

Commit

Permalink
fix snapshot upload escapes bash (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
LesnyRumcajs authored Oct 12, 2023
1 parent 2d9ddad commit 3181d25
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions terraform/modules/daily_snapshot/service/daily_snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ def latest_snapshot_date(chain_name = 'calibnet')
date_before_export = latest_snapshot_date(CHAIN_NAME)

# conditionally add timestamps to logs without timestamps
add_timestamps_cmd = "awk '{ if ($0 !~ /^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{6}Z/) print strftime(\"[%Y-%m-%d %H:%M:%S]\"), $0; else print $0; fflush(); }'"
add_timestamps_cmd = %q[awk '{ if ($0 !~ /^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6}Z/) print strftime("[%Y-%m-%d %H:%M:%S]"), $0; else print $0; fflush(); }']
upload_cmd = "set -o pipefail && \
timeout --signal=KILL 8h ./upload_snapshot.sh #{CHAIN_NAME} #{LOG_EXPORT_DAEMON} #{LOG_EXPORT_METRICS} | #{add_timestamps_cmd}"

# Sync and export snapshot
snapshot_uploaded = system("bash -c 'timeout --signal=KILL 8h ./upload_snapshot.sh #{CHAIN_NAME} #{LOG_EXPORT_DAEMON} #{LOG_EXPORT_METRICS} | #{add_timestamps_cmd} > #{LOG_EXPORT_SCRIPT_RUN} 2>&1'")
# The command needs to be run indirectly to avoid syntax errors in the shell.
snapshot_uploaded = system('bash', '-c', upload_cmd, %i[out err] => LOG_EXPORT_SCRIPT_RUN)

if snapshot_uploaded
date_after_export = latest_snapshot_date(CHAIN_NAME)
Expand Down

0 comments on commit 3181d25

Please sign in to comment.