5

I have a command service app start-demo requires me to type sudo service app start-demo in the command line.

I used sudo(service app start-demo) and sudo(sudo service app start-demo) but I still get

Warning: sudo() encountered an error (return code 1) while executing 'sudo service app start-demo'

I have no problem executing that as a command line in a terminal.

I am not sure if SADeprecationWarning: counts as a failure to fabric?

Thanks.


user@box:/var/lib/app$ fab kickstart
You are installing prereqs..........
### Install Prereqs for Populate ###
No hosts found. Please specify (single) host string for connection: localhost
[localhost] Login password: 

### I am starting demo ###
[localhost] sudo: sudo service app start-demo
[localhost] out: Starting demo

Fatal error: sudo() encountered an error (return code 1) while executing 'sudo service app start-demo'

Aborting.
Disconnecting from localhost... done.

the code

def pserve():
    print '### I am starting demo ###'
    #with settings(warn_only=True):
    sudo('sudo service app start-demo')
    #sudo('service app start-demo')

either sudo command will fail.


/etc/sudoers

# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
#

Defaults    env_reset

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL) ALL

# Allow members of group sudo to execute any command after they have
# provided their password
# (Note that later entries override this, so you might need to move
# it further down)
%sudo ALL=(ALL) ALL
#
#includedir /etc/sudoers.d

# Members of the admin group may gain root privileges
%admin ALL=(ALL) NOPASSWD:ALL
user423455
  • 773
  • 2
  • 9
  • 19
  • Does your `sudo` configuration require you to type a password at the terminal? – sarnold Jul 05 '12 at 23:21
  • Did you put the command in quotes? It should be `sudo("service app start-demo")`. – mayhewr Jul 06 '12 at 00:02
  • @sarnold It doesn't. When I do `sudo` on terminal, it won't ask. I ran as fab it didn't ask either. – user423455 Jul 06 '12 at 01:48
  • @mayhewr Oh yes. MY bad. I do. Otherwise, it would complain as syntactic error. :)) – user423455 Jul 06 '12 at 01:49
  • SADeprecationWarning should not be the problem. Even if it were, the service would still start (since it certainly knows it's just a warning), but fabric could report it as a failure. If the service doesn't start, the problem must be somewhere else. If you're still having the problem, post a more complete traceback/output. – mayhewr Jul 06 '12 at 17:06
  • @mayhewr Thanks. I've updated with a complete log. Is that what you need? If not, please let me know. – user423455 Jul 06 '12 at 17:13
  • @user423455: so you have configured whatever you want to run in `/etc/sudoers` as `NOPASSWD`? Because the cached password you gave in your own shell for a test run of the command with `sudo` *may* not actually be useful to the command you're trying to run here. – 0xC0000022L Jul 06 '12 at 17:15
  • @0xC0000022L Hi there. Thanks. Shouldn't `fab` uses the current user as the sudo account, and asks for access? Or is that not so? I believe I did. I am posting the file in just a bit. – user423455 Jul 06 '12 at 17:26

1 Answers1

3

This is prolly related to this mention in the faq, but also if the command doesn't return 0 (unix standard for all good) it'll fail-fast unless you tell it to warn only.

Morgan
  • 4,143
  • 27
  • 35
  • Thansk! That's a very good finding :) Now.. one more thing... fab doesn't return. It just waits there. Why is that? – user423455 Jul 06 '12 at 18:10
  • Most likely due to some nohup or backgrounding stuff, also [mentioned in the FAQ](http://docs.fabfile.org/en/1.4.2/faq.html#why-can-t-i-run-programs-in-the-background-with-it-makes-fabric-hang) – Morgan Jul 09 '12 at 15:18