在Fabric中执行sudo

时间:2012-07-05 23:18:55

标签: python fabric

我有一个命令service app start-demo要求我在命令行中键入sudo service app start-demo

我使用了sudo(service app start-demo)sudo(sudo service app start-demo),但我仍然使用

警告:执行'sudo service app start-demo'时sudo()遇到错误(返回码1)

我在终端中执行它作为命令行没有问题。

我不确定SADeprecationWarning:是否算作结构失败?

感谢。


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.

代码

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

sudo命令将失败。


/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

1 个答案:

答案 0 :(得分:3)

这与faq中的这一提及有很大关系,但如果命令没有返回0(所有商品的unix标准),除非你告诉它只发出警告,否则它将失败。 / p>