Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permission denied on log files without sudo #12

Open
ovidiubuligan opened this issue Jul 14, 2015 · 3 comments
Open

Permission denied on log files without sudo #12

ovidiubuligan opened this issue Jul 14, 2015 · 3 comments

Comments

@ovidiubuligan
Copy link

I am writing my first autostartup init.d script with a fresh instance of ubuntu amazon EC2 and I can't run it without sudo .

ubuntu@ip-172-31-XX-XXX:~$ /etc/init.d/codebox start                                                                                                    
Starting codebox
/etc/init.d/codebox: 44: /etc/init.d/codebox: nvm: not found
/etc/init.d/codebox: 50: /etc/init.d/codebox: cannot create /var/run/codebox.pid: Permission denied
/etc/init.d/codebox: 46: /etc/init.d/codebox: cannot create /var/log/codebox.log: Permission denied
Unable to start, see /var/log/codebox.log and /var/log/codebox.err 

If I run it with sudo it ill work but I don't konw how safe it is.
(Side question. If i edit the script and add just after cd "$dir" nvm use 0.12.7 nvm command is not found. Are there restrictions in what you can put inside an init.d script )

@vilpalu
Copy link

vilpalu commented Jul 15, 2015

this command solves permissions problem:
sudo update-rc.d /etc/init.d/RunMyProgram defaults

@ovidiubuligan
Copy link
Author

Well, i already did that and it gives me System start/stop links for /etc/init.d/codebox already exist..
I will try with different means.and if I don't get anywhere I will post the solution here.
It really needs to run as ubuntu user because there seams to be extra enviromnent variable configuration in ubuntuuser which is not present in the root user in order to run node which was installed with nvm . maybe I will try upstart (haven't used that either).
If someone knows how can I run a command in init.d as if I was running it normally from the user terminal I would be very appreciative.

@jesusvazquez
Copy link

I would say that you should change permissions on files that the init.d script is using and also the script permissions. First give read and write to /var/log/file and /var/run/file because you're writing pid/logs and and eventually reading them too.

Then change permissions to the init.d script so ubuntu can execute it. Basically try to execute every command within the script with the ubuntu user first and then you can safely add all of them to the script.

You're probably going to find a problem here, deleting the pidfile when stoping the service means you will have to create another one, that can simply be done with touch but you will have to add permissions and for that you need root privileges. Maybe creating a folder inside /var/run is a solution for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants