Is there any way to use Linux 'sudo' within an install hook?

I need to make a backup and then alter a file owned by ‘root’ when installing my app in a site.

I have tried running …

sudo bench --site  install-app myApp

… but I get a PermissionError just the same.

I know that this is possible:

except PermissionError:
   shutil.os.system('sudo cp "{}" "{}"'.format(file1,destination))

I’m just wondering if there’s something better…

Cool! Thanks!

Posting a question often leads me to think differently about the root problem.

The file I need to alter is within NGinx. Running NGinx as root is a security hole!!

So, just now, I created an nginx non-privileged (non-sudo) user and group, added my ERPNext user to that group and enabled group write privileges on the parent directory, and … IT DID NOT WORK!!!

Then after being a moron for 10 minutes I logged out and back in again … and then it did work.

End result … no need for sudo in my install hook.


If I had a dollar for every time I forgot to logout+login after adding a user to a group…

…I would have lots and lots of dollars. :smile:

1 Like

if you don’t wish to logout then use newgrp command.


newgrp nginx
1 Like

Sounds like the basis for an alt-coin project … interested? :smiley:

1 Like