I am trying to send log files to S3 before instance termination. I created .service file in
/lib/systemd/system-shutdown/upload-backup.service, which is this.
Description=Testing Before=shutdown.target reboot.target halt.target Requires=network-online.target network.target DefaultDependencies=no [Service] ExecStart=/bin/true ExecStop=/home/ubuntu/upload_log_to_s3.sh RemainAfterExit=yes Type=oneshot [Install] WantedBy=multi-user.target
upload_log_to_s3 being the script present in home and copies the file. This is working independently, so has no issues.
I have also created a soft link for this file in
/etc/systemd/system/shutdown.target.wants/ and also enabled systemctl.
But the script is not running while shutdown or reboot. Please explain the mistake and where I am wrong.