How to upload Janus video recordings to AWS S3 with Ubuntu systemd service

Add following files

[Unit]
Description=Upload Janus recordings to AWS S3
After=network.target

[Service]
Type=oneshot
User=ubuntu
WorkingDirectory=/home/ubuntu/janus_recordings
ExecStart=/bin/bash /usr/local/bin/upload_videos

[Install]
WantedBy=multi-user.target
/etc/systemd/system/janus_s3_upload.service
[Unit]
Description=Janus S3 Upload timer

[Timer]
OnCalendar=*:0/1
OnBootSec=5min

[Install]
WantedBy=timers.target
/etc/systemd/system/janus_s3_upload.timer
#!/bin/bash
sh /usr/local/bin/mux_all
for f in $(find -name \*.webm | sed "s|^\./||"); do
    /usr/local/bin/s3_move "$f"
    echo "Upload webm: $f done"
done

for f in $(find -name \*.opus | sed "s|^\./||"); do
    /usr/local/bin/s3_move "$f"
    echo "Upload opus: $f done"
done
/usr/local/bin/upload_videos
#!/bin/bash

for f in $(find -name \*-video.mjr | sed "s|^\./||"); do
    /usr/local/bin/mux "${f%-video.*}"
done
/usr/local/bin/mux_all
#!/bin/bash
if [ -z "$1" ] || [ ! -z "$2" ]; then
	echo Usage: ./mux \<basename\>
	exit
fi
ffmpegParams="-preset veryfast"
PP=/opt/janus/bin/janus-pp-rec
FFMPEG=/usr/bin/ffmpeg
RM=/bin/rm
AUDIOSIZE=$(wc -c <${1}-audio.mjr)
VIDEOSIZE=$(wc -c <${1}-video.mjr)

if  [ ! -f "${1}-video.mjr" ]; then
  echo "No mjr file found with passed <basename>, exiting"
  exit 0
fi

mv ${1}-video.mjr ${1}-video-processing.mjr
mv ${1}-audio.mjr ${1}-audio-processing.mjr

$PP ${1}-audio-processing.mjr ${1}-audio.opus
if [ -f "${1}-audio.opus" ] || [ $AUDIOSIZE -lt 100 ]; then
  $RM ${1}-audio-processing.mjr
fi
$PP ${1}-video-processing.mjr ${1}-video.webm
if [ -f "${1}-video.webm" ] || [ $VIDEOSIZE -lt 100 ]; then
  $RM ${1}-video-processing.mjr
fi
$FFMPEG -i ${1}-video.webm -i ${1}-audio.opus $ffmpegParams ${1}.mp4
if [ "$?" = "0" ] && [ -f "${1}.mp4" ]; then
  $RM -f ${1}-{audio,video}.{opus,webm}
fi
/usr/local/bin/mux
#!/bin/bash
S3CMD=/usr/local/bin/s3cmd
OPTIONS="-P --rr"
BUCKET=aplomb-input-bucket
PREFIX=
if [ -z "$1" ]; then
	echo Usage: ./upload_video \<filename\>
	exit
fi
if $S3CMD $OPTIONS put "$1" s3://$BUCKET/$PREFIX; then
	rm -f "$1"
else
	echo Upload failed
fi

echo "Upload successfully"
/usr/local/bin/s3_move

Run following command in terminal

sudo apt-get install python-pip
sudo pip install s3cmd

#configure
s3cmd --configure

To start the service

sudo systemctl start janus_s3_upload.timer

Check logs at

tail -f /var/log/syslog