NullReferenceException after Moving Octopus Server

I followed the procedure described in http://docs.octopusdeploy.com/display/OD/Move+the+Octopus+Home+folder to move the home folder of Octopus. Unfortunately Octopus Server does not run anymore after that.
Opening the Dashboard gives me a: 404 - File or directory not found.
When I start the Octopus Manager, I get the following Exception:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Octopus.Tools.OctopusConfiguration.OctopusManagerModel.Reload(ApplicationInstanceRecord applicationInstance) in y:\work\refs\heads\master\source\Octopus.Tools\OctopusConfiguration\OctopusManagerModel.cs:line 173
   at Octopus.Tools.OctopusConfiguration.OctopusManagerView.<Refresh>b__0() in y:\work\refs\heads\master\source\Octopus.Tools\OctopusConfiguration\OctopusManagerView.xaml.cs:line 104
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

Before you ask, yes, I did make a backup before I started.
What I tried to do was move the folder C:\Octopus to E:\Octopus.

What do I need to do to fix this?
Thank you
Torsten

I also noticed the following error in the OctopusServer.txt logfile:

2014-10-21 12:37:35.5260  ERROR  Encrypted stream is not correctly salted with the document key.
System.IO.IOException: Encrypted stream is not correctly salted with the document key. ---> System.IO.InvalidDataException: The encrypted stream's salt was different than the expected salt.
   at Raven.Bundles.Encryption.CodecSaltExtensions.ReadSalt(Stream stream, String key) in c:\Builds\RavenDB-Stable\Raven.Database\Bundles\Encryption\Codec.cs:line 196
   --- End of inner exception stack trace ---
   at Raven.Bundles.Encryption.CodecSaltExtensions.ReadSalt(Stream stream, String key) in c:\Builds\RavenDB-Stable\Raven.Database\Bundles\Encryption\Codec.cs:line 203
   at Raven.Bundles.Encryption.Codec.Decode(String key, Stream dataStream) in c:\Builds\RavenDB-Stable\Raven.Database\Bundles\Encryption\Codec.cs:line 97
   at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable`1 source, TAccumulate seed, Func`3 func)
   at Raven.Storage.Esent.StorageActions.DocumentStorageActions.ReadDocumentData(String key, Etag existingEtag, RavenJObject metadata) in c:\Builds\RavenDB-Stable\Raven.Database\Storage\Esent\StorageActions\Documents.cs:line 100
   at Raven.Storage.Esent.StorageActions.DocumentStorageActions.<DocumentByKey>b__1(JsonDocumentMetadata metadata, Func`4 createDocument) in c:\Builds\RavenDB-Stable\Raven.Database\Storage\Esent\StorageActions\Documents.cs:line 39
   at Raven.Storage.Esent.StorageActions.DocumentStorageActions.DocumentByKeyInternal[T](String key, TransactionInformation transactionInformation, Func`3 createResult) in c:\Builds\RavenDB-Stable\Raven.Database\Storage\Esent\StorageActions\Documents.cs:line 70
   at Raven.Storage.Esent.StorageActions.DocumentStorageActions.DocumentByKey(String key, TransactionInformation transactionInformation) in c:\Builds\RavenDB-Stable\Raven.Database\Storage\Esent\StorageActions\Documents.cs:line 36
   at Raven.Database.DocumentDatabase.<>c__DisplayClass36.<Get>b__34(IStorageActionsAccessor actions) in c:\Builds\RavenDB-Stable\Raven.Database\DocumentDatabase.cs:line 714
   at Raven.Storage.Esent.TransactionalStorage.ExecuteBatch(Action`1 action, EsentTransactionContext transactionContext) in c:\Builds\RavenDB-Stable\Raven.Database\Storage\Esent\TransactionalStorage.cs:line 666
   at Raven.Storage.Esent.TransactionalStorage.Batch(Action`1 action) in c:\Builds\RavenDB-Stable\Raven.Database\Storage\Esent\TransactionalStorage.cs:line 617
   at Raven.Database.DocumentDatabase.Get(String key, TransactionInformation transactionInformation) in c:\Builds\RavenDB-Stable\Raven.Database\DocumentDatabase.cs:line 716
   at Raven.Bundles.Encryption.Settings.EncryptionSettingsManager.VerifyEncryptionKey(DocumentDatabase database, EncryptionSettings settings) in c:\Builds\RavenDB-Stable\Raven.Database\Bundles\Encryption\Settings\EncryptionSettingsManager.cs:line 93
   at Raven.Database.Extensions.EnumerableExtensions.Apply[T](IEnumerable`1 self, Action`1 action) in c:\Builds\RavenDB-Stable\Raven.Database\Extensions\EnumerableExtensions.cs:line 18
   at Raven.Database.DocumentDatabase..ctor(InMemoryRavenConfiguration configuration, TransportState transportState) in c:\Builds\RavenDB-Stable\Raven.Database\DocumentDatabase.cs:line 252
   at Raven.Client.Embedded.EmbeddableDocumentStore.InitializeInternal() in c:\Builds\RavenDB-Stable\Raven.Client.Embedded\EmbeddableDocumentStore.cs:line 218
   at Raven.Client.Document.DocumentStore.Initialize() in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Document\DocumentStore.cs:line 459
   at Octopus.Server.Storage.StorageEngine.InitializeStore() in y:\work\refs\heads\master\source\Octopus.Server\Storage\StorageEngine.cs:line 148
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at Octopus.Server.Storage.StorageEngine.Start() in y:\work\refs\heads\master\source\Octopus.Server\Storage\StorageEngine.cs:line 44
   at Octopus.Server.OctopusServerEngine.Start() in y:\work\refs\heads\master\source\Octopus.Server\OctopusServerEngine.cs:line 51
   at Octopus.Server.Commands.RunCommand.Start() in y:\work\refs\heads\master\source\Octopus.Server\Commands\RunCommand.cs:line 21
   at Octopus.Shared.Startup.AbstractCommand.Octopus.Shared.Startup.ICommand.Start(String[] commandLineArguments, ICommandRuntime commandRuntime, OptionSet commonOptions) in y:\work\refs\heads\master\source\Octopus.Shared\Startup\AbstractCommand.cs:line 55
   at Octopus.Shared.Startup.WindowsServiceHost.<>c__DisplayClass2.<Run>b__0() in y:\work\refs\heads\master\source\Octopus.Shared\Startup\WindowsServiceHost.cs:line 19
   at Octopus.Shared.Startup.WindowsServiceAdapter.RunService() in y:\work\refs\heads\master\source\Octopus.Shared\Startup\WindowsServiceAdapter.cs:line 44

I forgot to mention that I am using the latest and greatest version of Octopus 2.5.10.

I tried reversing the script to move Octopus back to where it was. The script executed successfully, but the error messages remain the same when I try to open the Dashboard or the Octopus Manager.

Hi Torsten,

Thanks for getting in touch! Really sorry about the troubles that you are having.
We are really confused about those errors and how they could have come about.
To even try to dig we would need a copy of your logs from C:\Octopus\Logs (if that is where it all ended up!).

Did anything happen to prompt the move? Did you see any errors in the move itself? Could someone have changed the config file or it been corrupted?
It’s one of those things we haven’t seen before and would love to get to the bottom of.

As you took a backup, and you can’t get into the Octopus Manager, we would almost suggest a re-install and restore from backup. Do you have the master key?

Thanks!

Hi Vanessa

I did a Remove of Octopus Server with the installation program.
Then I installed Octoups Server again. When it tries to open the Octopus Manager, I get the same message:
System.NullReferenceException: Object reference not set to an instance of an object.
at Octopus.Tools.OctopusConfiguration.OctopusManagerModel.Reload(ApplicationInstanceRecord applicationInstance) in y:\work\refs\heads\master\source\Octopus.Tools\OctopusConfiguration\OctopusManagerModel.cs:line 173
at Octopus.Tools.OctopusConfiguration.OctopusManagerView.b__0() in y:\work\refs\heads\master\source\Octopus.Tools\OctopusConfiguration\OctopusManagerView.xaml.cs:line 104
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

Any other ideas?
Torsten

Hi Vanessa

Please find attached the log files.
The reason to move was that we ran out of disk space on the build controller that happens to be the home of our Octopus Server.
No, there were no errors during the move.
The config file does not look corrupted. I did not change it and I am the only one dealing with Octopus Deployments and it’s configuration.

I thought I have the Master Key until I saw the message in the OctopusServer.txt:
2014-10-21 13:26:03.0422 INFO Generating a new Master Key for this Octopus Server…

It looks like it generated a new Master Key as part of the move. I have to old master key, but not the newly generated one.
2014-10-21 13:26:03.7157 INFO Master Key saved; use the Octopus Administration tool to back the key up.
Since I could not start the Administration tool after the move, it was impossible for me to back up the key – at least with the tools and knowledge at my disposal at this time.

Actually, I take this back. I found the Master Key in the OctopusDeploy.config.

I will try to reinstall and restore the backup.

Thank you for your help.
Torsten

OctopusServer.txt (265 Bytes)

OctopusTentacle.txt (1 MB)

Hi Vanessa

I removed the Octopus folder from C:\Program Files and renamed the E:\Octopus folder.
And this is what I was afraid of. The Master Key from the config file is probably encrypted too.
I get the following messages when I do a restore:

Restoring Octopus Deploy Server from backup

Error: The provided Master Key is the wrong byte length

Full error details are available in the log files.
See: http://g.octopushq.com/LogFiles
Error: The previous command returned a non-zero exit code of: 1
Error: The command that failed was: “C:\Program Files\Octopus Deploy\Octopus\Octopus.Server.exe” restore --instance “OctopusServer” --file “E:\Octopus.Old\Octopus\Octopus\Octopus\Backups\20141021-115551.octobak” --master-key “AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAATBHMj1C8SUWhQOaAAiCO/wQAAAACAAAAAAADZgAAwAAAABAAAAAJhES4vAMwMqa83FtTDj2lAAAAAASAAACgAAAAEAAAAMdAuCVKxcV51B1NYjQqQoggAAAA6WhfkHXvQRKmrmrpuq/z3ANSI15jUWPBnZfyptQ+UbUUAAAAQuilMxN4LXlAxiqQ3XTdi75mQb4=”

In the log file there is this entry:
2014-10-21 16:37:30.7520 FATAL System.ArgumentException: The provided Master Key is the wrong byte length
at Octopus.Server.Commands.RestoreCommand.DecodeKey() in y:\work\refs\heads\master\source\Octopus.Server\Commands\RestoreCommand.cs:line 102
at Octopus.Server.Commands.RestoreCommand.Start() in y:\work\refs\heads\master\source\Octopus.Server\Commands\RestoreCommand.cs:line 65
at Octopus.Shared.Startup.AbstractCommand.Octopus.Shared.Startup.ICommand.Start(String[] commandLineArguments, ICommandRuntime commandRuntime, OptionSet commonOptions) in y:\work\refs\heads\master\source\Octopus.Shared\Startup\AbstractCommand.cs:line 55
at Octopus.Shared.Startup.ConsoleHost.Run(Action`1 start, Action shutdown) in y:\work\refs\heads\master\source\Octopus.Shared\Startup\ConsoleHost.cs:line 36

Can something be done with this encrypted Master Key from the config file?

Regards
Torsten

Hi Torsten,

I think we are okay and can get this back up and running. When it does a new install like you did, it does generate a new master key - but that is only related to the new database it creates. The OLD backup you have uses the OLD master key you have. So doing a restore of that old database with your old master key will work and overwrite your new master key.
You cannot grab the master key from the config as it is encrypted, but that new one would not have worked on your backup anyway.

Vanessa

Hi Vanessa

The key I saved does not work. I get the following message:
Service stopped
Restoring Octopus Deploy Server from backup

Error: The provided Master Key was not valid. Please ensure you have pasted your Master Key, and not an API key or certificate thumbprint. You can learn more about your master key here: http://g.octopushq.com/SaveMyMasterKey. Invalid length for a Base-64 char array or string.

Full error details are available in the log files.
See: http://g.octopushq.com/LogFiles
Error: The previous command returned a non-zero exit code of: 1
Error: The command that failed was: “C:\Program Files\Octopus Deploy\Octopus\Octopus.Server.exe” restore --instance “OctopusServer” --file “E:\Octopus.Old\Octopus\Octopus\Octopus\Backups\20141021-115551.octobak” --master-key “AOiJVShI/Hx2kIW3MUNfA==”

Either I must have screwed up by saving it wrong or the Master Key has changed without my knowledge and I did not save it again. But since the length is not ok, the first is more likely.
So is it all lost now?

Regards
Torsten

Hi Torsten,

It’s pretty hard to change the master key, how long ago did you save it ? Did you grab it from the Octopus Manager when you did?

Vanessa

I did it way back in February 28th 2014.
The key is from the Octopus Manger, but “grab” is the wrong expression.
I typed it into a password manager. I know now that I should have grabbed it.
Even though I tried to be very careful when I did it, I must have still messed up.
Please don’t ask me why I did it that way. I wonder myself why.

What we are trying to do is to restore a backup from the system to the
C:\Octopus folder from before the move.
My hope that I will be able to access the data again, but I could not try it yet, since
the IT guys are working on it for hours.

Is there anything I should consider to make the System-Octopus restore working?

Thank you
Torsten

Hi Torsten,

It is so very encrypted by that master key. If you can get any valid restore from backup from your IT guys working, you can get the master key and restore from your most recent db backup and you will be back in action. That master key is unfortunately the key to it all.
Let me know if you progress and I have a call with Paul tomorrow and we will discuss if there are just anyways to get the master key out for you.

Vanessa

Hi Vanessa

It worked. YES it worked. :slight_smile:
What I did is to copy the restored Octopus data directory to the C: and the E: drive.
Since Octopus was currently configured to look in E:, I thought it might look there first.
But the restored data directory used to be on C:.
When I started Tools.exe (Octopus Manager), the Home directory points to C:\Octopus.
Now I was able to retrieve the MasterKey. There was just a letter missing somewhere.
But that letter caused so much trouble. Now I did what you said. I grabbed it and saved it in multiple places.
Both Octopus Server and Tentacle are starting up again.

Thank you so much for your help. To have this solved made my day and saved the week.
Torsten

Hi Torsten,

I am just really sorry that all of this has occurred and has been so painful for you.
But when I started my day knowing your system was back up that was excellent news!!

So where do you stand? Are you still stuck on C:?
Also can you tell me what OS your Octopus Server is running on, I would like to see if I can get the move home directory steps tested on that to see what might have caused your original issue.

Vanessa

Good morning Vanessa

I went through the same steps to move the Octopus Data to Drive E. Only this time I did one command at a time and left out the actual move because I already had the same data on C and E. There was no error message. But it failed in exactly the same way. I had to deinstall Octopus and delete the directories from Program Files and rename the Octopus Data directory. Then I could reinstall and restore the backup – YEAH – with the right MasterKey.
So now I have what I wanted. Octopus Server is up and running and it’s data is on the E drive.

The operating system is Windows Server 2008 R2 Datacenter with SP 1.
Since it happened here twice it should be easy to reproduce.

I am happy I got my data back and did not have to redo everything. It was a valuable lesson on the importance of having a working backup strategy (and the real MasterKey). I will inform my colleagues who use Octopus about it too.

When you repro this problem, you may want to look into why neither Repair nor Deinstall/Install would fix the problem without the extra steps I mentioned once the Octopus Server is messed up. If that does not work, it should be documented so people will know the work around.

Thank you and your team for your support.
Torsten