github.com/Finschia/finschia-sdk@v0.48.1/docs/migrations/pre-upgrade.md (about) 1 # Pre-Upgrade Handling 2 3 Cosmovisor supports custom pre-upgrade handling. Use pre-upgrade handling when you need to implement application config changes that are required in the newer version before you perform the upgrade. 4 5 Using Cosmovisor pre-upgrade handling is optional. If pre-upgrade handling is not implemented, the upgrade continues. 6 7 For example, make the required new-version changes to `app.toml` settings during the pre-upgrade handling. The pre-upgrade handling process means that the file does not have to be manually updated after the upgrade. 8 9 Before the application binary is upgraded, Cosmovisor calls a `pre-upgrade` command that can be implemented by the application. 10 11 The `pre-upgrade` command does not take in any command-line arguments and is expected to terminate with the following exit codes: 12 13 | Exit status code | How it is handled in Cosmosvisor | 14 |------------------|---------------------------------------------------------------------------------------------------------------------| 15 | `0` | Assumes `pre-upgrade` command executed successfully and continues the upgrade. | 16 | `1` | Default exit code when `pre-upgrade` command has not been implemented. | 17 | `30` | `pre-upgrade` command was executed but failed. This fails the entire upgrade. | 18 | `31` | `pre-upgrade` command was executed but failed. But the command is retried until exit code `1` or `30` are returned. | 19 20 ## Sample 21 22 Here is a sample structure of the `pre-upgrade` command: 23 24 ```go 25 func preUpgradeCommand() *cobra.Command { 26 cmd := &cobra.Command{ 27 Use: "pre-upgrade", 28 Short: "Pre-upgrade command", 29 Long: "Pre-upgrade command to implement custom pre-upgrade handling", 30 Run: func(cmd *cobra.Command, args []string) { 31 32 err := HandlePreUpgrade() 33 34 if err != nil { 35 os.Exit(30) 36 } 37 38 os.Exit(0) 39 40 }, 41 } 42 43 return cmd 44 } 45 ``` 46 47 Ensure that the pre-upgrade command has been registered in the application: 48 49 ```go 50 rootCmd.AddCommand( 51 // .. 52 preUpgradeCommand(), 53 // .. 54 ) 55 ```