Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my remote host return a error code -1 when I use fabric reboot()?

Local Host Environment: CentOS 7, Python 3.5.1, Fabric3 (1.11.1.post1)
Remote Host Environment: CentOS 7

fibfile:

def fuc():
    reboot()

bash:

fab -f fibfile.py -H host -u root -p password

The remote host did reboot but returns a fatalError:

sudo() received nonzero return code -1 while executing 'reboot'!

Now I use warn_only to prevent failure:

fabfile:

def test():
    with settings(warn_only=True):
        reboot()
like image 987
Jon Stark Avatar asked May 23 '16 07:05

Jon Stark


3 Answers

I started having this problem with some new virtual machines. I think they do shut down too fast, as Jon Stark said.

To fix it, I ignore the error and the warning, like this.

with settings(hide('warnings'),
              warn_only=True,
             ):
    sudo("shutdown -r now")
like image 192
Christian Long Avatar answered Nov 02 '22 05:11

Christian Long


I find a similar question when use ansible: link

I think the top answer is right:

reboot is shutting down the server so quickly that the server is tearing down the SSH connection.

shutdown -r now return the same fatal error:

sudo() received nonzero return code -1 while executing 'shutdown -r now'!

shutdown -r +1 return success:

out: Shutdown scheduled for Mon 2016-05-23 14:16:48 UTC, use 'shutdown -c' to cancel.

But shutdown can only delay at least one minute. So we can only choose to wait for a minute or ignore the error.

like image 39
Jon Stark Avatar answered Nov 02 '22 04:11

Jon Stark


You can put a shell session into the background which sleeps for 1 second then executes the reboot command. Must be done without the use of nohup command because of the nohup issue. I use tmux...

reboot(command='tmux new-session -d "sleep 1; reboot;"')
like image 43
Adam Terrey Avatar answered Nov 02 '22 06:11

Adam Terrey