gpt4 book ai didi

python - 在 fabric 中作为 sudo 执行

转载 作者:太空狗 更新时间:2023-10-30 01:23:37 25 4
gpt4 key购买 nike

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

我使用了 sudo(service app start-demo)sudo(sudo service app start-demo) 但我还是得到了

警告:sudo() 在执行“sudo service app start-demo”时遇到错误(返回代码 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

最佳答案

这与 faq 中的提及密切相关,而且如果命令不返回 0(所有好的 unix 标准),除非您告诉它仅发出警告,否则它将快速失败。

关于python - 在 fabric 中作为 sudo 执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11353840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com