oranie's blog

旧:iをgに変えると・・・なんだっけ・・・

fabricでinitスクリプトが動かない場合の対処法

fabricで例えばapacheを起動したい場合に

sudo("/etc/init.d/apache2 restart")

と当然書くじゃないですか。で確認するとちゃんとプロセス起動しない訳じゃないですか。
で、どうすれば良いかと言うと公式docに書いてあった。http://docs.fabfile.org/en/1.8/faq.html

Init-style start/stop/restart scripts (e.g. /etc/init.d/apache2 start) sometimes don’t like Fabric’s allocation of a pseudo-tty, which is active by default. In almost all cases, explicitly calling the command in question with pty=False works correctly:

sudo("/etc/init.d/apache2 restart", pty=False)

If you have no need for interactive behavior and run into this problem frequently, you may want to deactivate pty allocation globally by setting env.always_use_pty to False.

だってさ。なので

sudo("/etc/init.d/apache2 restart", pty=False)

と書けばいい訳ね。行き当たりばったりな使い方をせずにちゃんとドキュメントを読んでから使わなければいけない。