You can add the following line to the sudoers file (/ etc / sudoers)
rails_user ALL=(root) NOPASSWD:/usr/sbin/service
Basically, this will allow the user rails_user to execute a utility command as sudo, and the system will not ask you to enter a password.
rails_user should be replaced by any user you work with in the rails process. And you must also make sure that
Defaults requiretty
not in your / etc / sudoers. If not, you cannot use sudo from the script.
source share