Upgrade fails due to permissions issue

I understand what has happened here, I’m just hoping there’s an easy fix for it. When NZBDrone attempted to do the latest update it failed.

14-10-28 01:10:50.8|Debug|ProcessProvider|Starting mono /opt/NzbDrone/NzbDrone.exe --nobrowser
14-10-28 01:10:50.8|Fatal|UpdateApp|An error has occurred while applying update package.

System.UnauthorizedAccessException: Access to the path "/opt/NzbDrone/NzbDrone.Update/Exceptron.Client.dll" is denied.
  at System.IO.File.Delete (System.String path) [0x00000] in <filename unknown>:0
  at System.IO.FileInfo.CopyTo (System.String destFileName, Boolean overwrite) [0x00000] in <filename unknown>:0
  at (wrapper remoting-invoke-with-check) System.IO.FileInfo:CopyTo (string,bool)
  at NzbDrone.Common.Disk.DiskProviderBase.TransferFolder (System.String source, System.String target, TransferAction transferAction) [0x00000] in <filename unknown>:0
  at NzbDrone.Common.Disk.DiskProviderBase.TransferFolder (System.String source, System.String target, TransferAction transferAction) [0x00000] in <filename unknown>:0
  at NzbDrone.Common.Disk.DiskProviderBase.CopyFolder (System.String source, System.String destination) [0x00000] in <filename unknown>:0
  at NzbDrone.Update.UpdateEngine.BackupAndRestore.Restore (System.String target) [0x00000] in <filename unknown>:0
  at NzbDrone.Update.UpdateEngine.InstallUpdateService.Start (System.String installationFolder, Int32 processId) [0x00000] in <filename unknown>:0
  at NzbDrone.Update.UpdateApp.Start (System.String[] args) [0x00000] in <filename unknown>:0
  at NzbDrone.Update.UpdateApp.Main (System.String[] args) [0x00000] in <filename unknown>:0

When I checked the directories the NzbDrone.Update directory was owned by root. I run NzbDrone under the user media just like the rest of my apps (plex, CouchPotato, Sabnzb) so that there are no permissions issues between them. I believe this is the source of the update issue. Is there any way to make the update process run under the same user as the application service?

This is already how it operates.

Let me guess, running on Ubuntu with Upstart controlling the starting/stopping of sonnar (drone)? If so, the auto update mechanism doesn’t work, because the update process starts, which causes NzbDrone.exe to terminate, which in turn causes Upstart to restart it, which prevents the update process from updating any files, so it fails. Since upstart requires root/sudo to stop/start we can’t easily work around this issue, except for a custom update script that would have permissions to stop/start, not sure how feasible that is.

If the respawn is the issue, why not remove respawn from the upstart config?
I know that’s only part of the issue. CouchPotato and SABNZB pull it off easily enough, I wonder how they make it happen?

EDIT: And to answer the question, yes it is Ubuntu with Upstart.

I’ve created the file /etc/sudoers.d/nzbdrone_media and added the following line:

media ALL = (root) NOPASSWD: /sbin/start nzbdrone, /sbin/stop nzbdrone, /sbin/restart nzbdrone, /sbin/status nzbdrone

This should give my user (media) the ability to control the upstart script for my service (nzbdrone) without a password prompt so that the necessary start stop and restart tasks can be taken care of. It can even use status to get pid information and such, if needed.

Removing respawn would be worth testing.

CP does use forks when the app starts to run as a daemon, but thats not support on Windows or in .net, so we can’t do something similar, they may also do updates via git pull. SAB has never had auto update, have they?

isn’t it service stop nzbdrone?

You can now have a script that performs the update, which can be set on the general settings page, the script will have to take care of stopping/copying/starting. The built in update won’t handle this automatically.

You might be right about sab. I never really thought about it, but I think I’m just using the Ubuntu package native to apt.

I see what you’re saying. It’s hard for me to wrap my head around Windows programs sometimes. I suppose, if I were to write a script to do the update I would need to know where to get the updated files. Is there a repository that the current update process looks at to get the necessary packages(s)?

It’s actually service nzbdrone stop but in that file it’s just telling the sudoers daemon (the program controls who or what can claim super user permissions and what for) that the user “media” should be allowed to access the programs start, stop, restart and status (which are actually links to initctl) located in the /sbin directory. Clear as mud?

3 arguments are passed to the script:

  1. PID
  2. Path to the update files (wrapped in quotes if it contains spaces, but not likely), this is the update package that has been unzipped
  3. Executing exe (this can be ignored in this case)

Yes, I’m just going to pretend I understand. :smile:

Is there an API so I can get an idea of the structure? Any recommendations on how to trigger an update for testing purposes?

Also I just noticed that Ubuntu installed an update as well. So under Ubuntu at least, if it’s installed from the package manager you shouldn’t need to run updates I guess.

Yeah, you could just cron apt-get update && apt-get install nzbdrone

There isn’t an API, sonarr will call that script when there is a new update to install (instead of its own update application).

The actual account would be something like: /path/to/scrip.sh 12345 /tmp/NzbDrone.Update/ /opt/NzbDrone/NzbDrone.exe

The only way you can trigger one is to have an update available and click install, easiest way to test is just pass the parameters via command line.

so is there a fix for the ubuntu installation for upgrading nzbdrone from inside the web interface?

Depends what the issue is, but first make sure respawn is disabled in the upstart config, per the installation instructions on the wiki and permissions are properly set on /opt/NzbDrone/ (user running Sonarr has write access).

cool. Yes, I see some things have changed on the wiki since I first did the installation. Or I missed them in the first place… anyhow, I’m making those changes now.
I did not see any instructions on the wiki for setting permissions.


At the moment, that folder and all files inside are root:root, but the mono>nzbdrone runs as user drew. Should I change only the folder to 777, or all the files in there, or chown -R it all to user drew. ?

I got the /etc/apt/sources.list fixed with ‘deb https://apt.sonarr.tv/ master main’ and got the upgrade done using apt-get upgrade.

Thanks again for the speedy responses!

776 is enough (only gives read/write to others), fine to leave the owner as root:root.