Reputation: 13748
I have a bash script named ssadmin.sh
, it manages another script sscounter.sh
.
I am using fabric to excute ssadmin.sh
.
Without pty=False
:
def ts1():
with settings(warn_only=True):
run("chmod 775 %s" % 'ssadmin.sh')
run("%s start" % 'ssadmin.sh')
sscounter.sh
even can not start, but cmd would not be hanged:
root@ubuntu-1404:~# /mithril/scripts/ss-bash/ssadmin.sh status
ssserver not running
sscounter.sh not running
with pty=False
:
def ts1():
with settings(warn_only=True):
run("chmod 775 %s" % 'ssadmin.sh')
run("%s start" % 'ssadmin.sh', pty=False)
root@ubuntu-1404:~# /mithril/scripts/ss-bash/ssadmin.sh status
ssserver not running
10670 ? S 0:00 /bin/bash /mithril/scripts/ss-bash/sscounter.sh
sscounter.sh is running
sscounter.sh started, but cmd hangs:
E:\[Sync]\project\walbk\fab>fab ts1
[192.168.1.181] Executing task 'ts1'
[192.168.1.181] run: chmod 775 /mithril/scripts/ss-bash/ssadmin.sh
[192.168.1.181] run: /mithril/scripts/ss-bash/ssadmin.sh start
[192.168.1.181] out: stdin: is not a tty
[192.168.1.181] out: 9915 ? S 0:00 /bin/bash /mithril/scripts/ss-bash/sscounter.sh
[192.168.1.181] out: sscounter.sh鍚姩涓?..
[192.168.1.181] out: 10670 ? S 0:00 /bin/bash /mithril/scripts/ss-bash/sscounter.sh
[192.168.1.181] out: sscounter.sh宸插惎鍔?
[192.168.1.181] out: (hang at here)
1.why fabric hangs?
2.fabric pty description
:
http://docs.fabfile.org/en/latest/usage/interactivity.html#echoes
pty is present to echo a user’s stdin
, why sscounter.sh
wouldn't start when pty=True
?
Upvotes: 0
Views: 1291
Reputation: 7255
I have a glance of your code, since you don't need to print out anything in sscounter.sh
, there is one quick solution for the hanging issue: changing ( $DIR/sscounter.sh ) &
to ( $DIR/sscounter.sh ) >/dev/null 2>&1 &
.
When you did not redirect the stdout, fabric will wait for it and since your sscounter.sh
will not exit fabric seems hanging.
If you run ssadmin.sh
(the version without stdout redirected) remotely like this: ssh user@remote-host 'bash ssadmin.sh'
, it will hang too for same reason. Otherwise if you are using ssh -t user@remote-host 'bash ssadmin.sh'
, it will not hang.
I think use fabric with pty=True
and pty=False
is just like using ssh
with and without -t
option.
Upvotes: 1