I want to copy log files (project log files) when system goes down or shutdown in Ubuntu server. I have using aws Autoscaling for one server. so my case when cpu load is less than 50% then scale down one instance. I want to take this instance log files before going down.
Create a script and put it in
Immediately before executing the actual system halt/poweroff/reboot/kexec systemd-shutdown will run all executables in /usr/lib/systemd/system-shutdown/ and pass one arguments to them: either "halt", "poweroff", "reboot" or "kexec", depending on the chosen action. All executables in this directory are executed in parallel, and execution of the action is not continued before all executables finished.
Other way to achieve same thing is to create unit file and use ExecStop.
Edit: Because Filipe wanted example here is one:
[Unit] Description=Backup example RequiresMountsFor=/mnt/backup /home/backup [Service] ExecStop=/etc/systemd/system/backup.sh Type=oneshot RemainAfterExit=yes [Install] WantedBy=multi-user.target