|
| 1 | +################################################################################################### |
| 2 | +#### Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | +#### |
| 4 | +#### Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file |
| 5 | +#### except in compliance with the License. A copy of the License is located at |
| 6 | +#### |
| 7 | +#### http://aws.amazon.com/apache2.0/ |
| 8 | +#### |
| 9 | +#### or in the "license" file accompanying this file. This file is distributed on an "AS IS" |
| 10 | +#### BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 11 | +#### License for the specific language governing permissions and limitations under the License. |
| 12 | +################################################################################################### |
| 13 | + |
| 14 | +### |
| 15 | +# This is an example ebextension for using scheduled tasks |
| 16 | +# to ensure a computer restart occurs late during first boot, |
| 17 | +# such as to apply a computer rename or domain join. |
| 18 | +# This avoids restarting too early and interrupting |
| 19 | +# the first time Elastic Beanstalk bootstrapping. |
| 20 | +# |
| 21 | +# Note this example is provided as-is, and it is up to |
| 22 | +# the customer to test and modify on their own to fit |
| 23 | +# their needs before trying in production. |
| 24 | +### |
| 25 | + |
| 26 | +files: |
| 27 | + "C:\\Program Files\\Amazon\\ElasticBeanstalk\\hooks\\appdeploy\\post\\9999999_reboot_workaround.ps1": |
| 28 | + content: | |
| 29 | + Function Reboot-Computer { |
| 30 | + Unregister-ScheduledTask -TaskName systemReboot -Confirm:$false |
| 31 | + $action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument 'Restart-Computer -Force' |
| 32 | + $trigger = New-JobTrigger -At (get-date).AddMinutes(5) -Once |
| 33 | + $principal = New-ScheduledTaskPrincipal -UserId SYSTEM -LogonType ServiceAccount -RunLevel Highest |
| 34 | + $definition = New-ScheduledTask -Action $action -Principal $principal -Trigger $trigger -Description "Run systemReboot at startup" |
| 35 | + Register-ScheduledTask -TaskName systemReboot -InputObject $definition |
| 36 | + } |
| 37 | + |
| 38 | + #Example computer rename |
| 39 | + Rename-Computer -NewName eb-new-name |
| 40 | + Reboot-Computer |
| 41 | + |
| 42 | +commands: |
| 43 | + 01_remove_bak_files: |
| 44 | + command: "del /F \"C:\\Program Files\\Amazon\\ElasticBeanstalk\\hooks\\appdeploy\\post\\*.bak\"" |
| 45 | + ignoreErrors: true |
0 commit comments