├── README.md ├── LICENSE └── lifecycle.yml /README.md: -------------------------------------------------------------------------------- 1 | # aws 2 | AWS scripts and utilities. Inside: 3 | 4 | ## lifecycle.yml 5 | 6 | SSM Document Template for Amazon Data Lifecycle Manager Pre/Post script feature for InterSystems IRIS. Run InterSystems IRIS Database freeze/thaw commands. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 InterSystems Developer Community 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /lifecycle.yml: -------------------------------------------------------------------------------- 1 | ###===============================================================================### 2 | # MIT License 3 | # 4 | # Copyright (c) 2024 InterSystems 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | ###===============================================================================### 24 | schemaVersion: '2.2' 25 | description: SSM Document Template for Amazon Data Lifecycle Manager Pre/Post script feature for InterSystems IRIS. 26 | parameters: 27 | executionId: 28 | type: String 29 | default: None 30 | description: Specifies the unique identifier associated with a pre and/or post execution 31 | allowedPattern: ^(None|[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})$ 32 | command: 33 | type: String 34 | # Data Lifecycle Manager will trigger the pre-script and post-script actions. You can also use this SSM document with 'dry-run' for manual testing purposes. 35 | default: 'dry-run' 36 | description: (Required) Specifies whether pre-script and/or post-script should be executed. 37 | #The following allowedValues will allow Data Lifecycle Manager to successfully trigger pre and post script actions. 38 | allowedValues: 39 | - pre-script 40 | - post-script 41 | - dry-run 42 | 43 | mainSteps: 44 | - action: aws:runShellScript 45 | description: Run InterSystems IRIS Database freeze/thaw commands 46 | name: run_pre_post_scripts 47 | precondition: 48 | StringEquals: 49 | - platformType 50 | - Linux 51 | inputs: 52 | runCommand: 53 | - | 54 | #!/bin/bash 55 | ###===============================================================================### 56 | ### Global variables 57 | ###===============================================================================### 58 | DOCKER_NAME=iris 59 | LOGDIR=./ 60 | EXIT_CODE=0 61 | OPERATION={{ command }} 62 | START=$(date +%s) 63 | 64 | # Check if Docker is installed 65 | # By default if Docker is present, script assumes that InterSystems IRIS is running in Docker 66 | # Leave only the else block DOCKER_EXEC line, if you run InterSystems IRIS non-containerised (and Docker is present). 67 | # Script assumes irissys user has OS auth enabled, change the OS user or supply login/password depending on your configuration. 68 | if command -v docker &> /dev/null 69 | then 70 | DOCKER_EXEC="docker exec $DOCKER_NAME" 71 | else 72 | DOCKER_EXEC="sudo -i -u irissys" 73 | fi 74 | 75 | 76 | # Add all pre-script actions to be performed within the function below 77 | execute_pre_script() { 78 | echo "INFO: Start execution of pre-script" 79 | 80 | # find all iris running instances 81 | iris_instances=$($DOCKER_EXEC iris qall 2>/dev/null | tail -n +3 | grep '^up' | cut -c5- | awk '{print $1}') 82 | echo "`date`: Running iris instances $iris_instances" 83 | 84 | # Only for running instances 85 | for INST in $iris_instances; do 86 | 87 | echo "`date`: Attempting to freeze $INST" 88 | 89 | # Detailed instances specific log 90 | LOGFILE=$LOGDIR/$INST-pre_post.log 91 | 92 | #check Freeze status before starting 93 | $DOCKER_EXEC irissession $INST -U '%SYS' "##Class(Backup.General).IsWDSuspendedExt()" 94 | freeze_status=$? 95 | if [ $freeze_status -eq 5 ]; then 96 | echo "`date`: ERROR: $INST IS already FROZEN" 97 | EXIT_CODE=204 98 | else 99 | echo "`date`: $INST is not frozen" 100 | # Freeze 101 | # Docs: https://docs.intersystems.com/irislatest/csp/documatic/%25CSP.Documatic.cls?LIBRARY=%25SYS&CLASSNAME=Backup.General#ExternalFreeze 102 | $DOCKER_EXEC irissession $INST -U '%SYS' "##Class(Backup.General).ExternalFreeze(\"$LOGFILE\",,,,,,600,,,300)" 103 | status=$? 104 | 105 | case $status in 106 | 5) echo "`date`: $INST IS FROZEN" 107 | ;; 108 | 3) echo "`date`: $INST FREEZE FAILED" 109 | EXIT_CODE=201 110 | ;; 111 | *) echo "`date`: ERROR: Unknown status code: $status" 112 | EXIT_CODE=201 113 | ;; 114 | esac 115 | echo "`date`: Completed freeze of $INST" 116 | fi 117 | done 118 | echo "`date`: Pre freeze script finished" 119 | } 120 | 121 | # Add all post-script actions to be performed within the function below 122 | execute_post_script() { 123 | echo "INFO: Start execution of post-script" 124 | 125 | # find all iris running instances 126 | iris_instances=$($DOCKER_EXEC iris qall 2>/dev/null | tail -n +3 | grep '^up' | cut -c5- | awk '{print $1}') 127 | echo "`date`: Running iris instances $iris_instances" 128 | 129 | # Only for running instances 130 | for INST in $iris_instances; do 131 | 132 | echo "`date`: Attempting to thaw $INST" 133 | 134 | # Detailed instances specific log 135 | LOGFILE=$LOGDIR/$INST-pre_post.log 136 | 137 | #check Freeze status befor starting 138 | $DOCKER_EXEC irissession $INST -U '%SYS' "##Class(Backup.General).IsWDSuspendedExt()" 139 | freeze_status=$? 140 | if [ $freeze_status -eq 5 ]; then 141 | echo "`date`: $INST is in frozen state" 142 | # Thaw 143 | # Docs: https://docs.intersystems.com/irislatest/csp/documatic/%25CSP.Documatic.cls?LIBRARY=%25SYS&CLASSNAME=Backup.General#ExternalFreeze 144 | $DOCKER_EXEC irissession $INST -U%SYS "##Class(Backup.General).ExternalThaw(\"$LOGFILE\")" 145 | status=$? 146 | 147 | case $status in 148 | 5) echo "`date`: $INST IS THAWED" 149 | $DOCKER_EXEC irissession $INST -U%SYS "##Class(Backup.General).ExternalSetHistory(\"$LOGFILE\")" 150 | ;; 151 | 3) echo "`date`: $INST THAW FAILED" 152 | EXIT_CODE=202 153 | ;; 154 | *) echo "`date`: ERROR: Unknown status code: $status" 155 | EXIT_CODE=202 156 | ;; 157 | esac 158 | echo "`date`: Completed thaw of $INST" 159 | else 160 | echo "`date`: ERROR: $INST IS already THAWED" 161 | EXIT_CODE=205 162 | fi 163 | done 164 | echo "`date`: Post thaw script finished" 165 | } 166 | 167 | # Debug logging for parameters passed to the SSM document 168 | echo "INFO: ${OPERATION} starting at $(date) with executionId: ${EXECUTION_ID}" 169 | 170 | # Based on the command parameter value execute the function that supports 171 | # pre-script/post-script operation 172 | case ${OPERATION} in 173 | pre-script) 174 | execute_pre_script 175 | ;; 176 | post-script) 177 | execute_post_script 178 | ;; 179 | dry-run) 180 | echo "INFO: dry-run option invoked - taking no action" 181 | ;; 182 | *) 183 | echo "ERROR: Invalid command parameter passed. Please use either pre-script, post-script, dry-run." 184 | # return failure 185 | EXIT_CODE=1 186 | ;; 187 | esac 188 | 189 | END=$(date +%s) 190 | # Debug Log for profiling the script time 191 | echo "INFO: ${OPERATION} completed at $(date). Total runtime: $((${END} - ${START})) seconds." 192 | exit $EXIT_CODE 193 | --------------------------------------------------------------------------------