Page 1 of 1

Start up script in sudo

Posted: Thu Jun 19, 2014 4:45 pm
by dannuge
Currently to run my program....
1. I power on my pi
2. log in(with password)
3. "cd dirName"
4. "sudo -s"
5. "mavproxy.py" plus args and stuff (its in the system path)

*a password is not required when I use sudo. Not sure why. Maybe because my current user has sudo privileges. Don't fully understand logging in and user privileges. Like what types of things can be run when no user is logged in, i.e. startup???

I want to automate this process. So when I power on my pi, this all occurs without any user intervention. In the end it just needs to run mavproxy.py as a super user. The documentation says to use sudo -s. Not sure why it is necessary. The program runs its own type of terminal environment when it is started, so that may be why.

A nice feature would be able to run all this in a "screen", so then I could ssh into the pi and interact with the program. But that is not necessary.

One last thing. Does the pi have the ability to connect to a lan network(ethernet) after startup? Could I have it run its start routine and then plug in the ethernet later on and ssh into the device?

I have to tried to accomplish this with rc.local but couldn't figure it out. Any suggestions?

Thanks,
Daniel

Re: Start up script in sudo

Posted: Thu Jun 19, 2014 4:51 pm
by DougieLawson
sudo nano /etc/rc.local

Add
/usr/local/bin/mavproxy.py parms and stuff here &

somewhere before the exit 0 line.

Save and mavproxy.py will get auto started (running with root privileges) when you boot.


BTW, sudo doesn't need a password on Raspbian because someone (who built the distro) decided to update the sudoers file and remove the need to authenticate use of sudo. It may or may not be a good idea, it certainly isn't good for security.

Re: Start up script in sudo

Posted: Thu Jun 19, 2014 5:03 pm
by dannuge
Thanks for the quick reply!
I run the program in a specific directory because the program references files in that directory when it runs, so should I change it to

/usr/local/bin/dirName/ mavproxy.py <args>&

??
Otherwise I'll see if I can make the program reference an absolute path.

Luckily this is robotic application so security isn't an issue.

I have seen examples of a screen being run in rc.local like this:

/usr/local/bin/dirName/ screen -d -m -s mavproxy.py <args>&

Any comment on that? I couldn't accurately test it because I wasn't able to successfully launch mavproxy.

Thanks,
Daniel

Re: Start up script in sudo

Posted: Thu Jun 19, 2014 5:06 pm
by dannuge
I meant couldn't launch mavproxy on my initial attempt. I haven't had a chance to use your proposed method. I dont have access to my pi right now.

Re: Start up script in sudo

Posted: Sat Jun 21, 2014 2:36 pm
by plugwash
DougieLawson wrote: BTW, sudo doesn't need a password on Raspbian because someone (who built the distro) decided to update the sudoers file and remove the need to authenticate use of sudo. It may or may not be a good idea, it certainly isn't good for security.
Just to clarify the enabling of sudo without password is a characteristic of the raspberry pi foundation raspbian image, not of raspbian in general.