Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fabric appears to start apache2 but doesn't

I'm using fabric to remotely start a micro aws server, install git and a git repository, adjust apache config and then restart the server.

If at any point, from the fabfile I issue either

sudo('service apache2 restart') or run('sudo service apache2 restart') or a stop and then a start, the command apparently runs, I get the response indicating apache has started, for example

[ec2-184-73-1-113.compute-1.amazonaws.com] sudo: service apache2 start
[ec2-184-73-1-113.compute-1.amazonaws.com] out:  * Starting web server apache2
[ec2-184-73-1-113.compute-1.amazonaws.com] out:    ...done.
[ec2-184-73-1-113.compute-1.amazonaws.com] out: 

However, if I try to connect, the connection is refused and if I ssh into the server and run sudo service apache2 status it says that "Apache is NOT running"

Whilst sshed in, if run sudo service apache start, the server is started and I can connect. Has anyone else experienced this? Or does anyone have any tips as to where I could look, in log files etc to work out what has happened. There is nothing in apache2/error.log, syslog or auth.log.

It's not that big a deal, I can work round it. I just don't like such silent failures.

like image 455
Dan Avatar asked Jun 16 '11 22:06

Dan


4 Answers

Which version of fabric are you running?

Have you tried to change the pty argument (try to change shell too, but it should not influence things)?

http://docs.fabfile.org/en/1.0.1/api/core/operations.html#fabric.operations.run

You can set the pty argument like this:

sudo('service apache2 restart', pty=False)
like image 71
GaretJax Avatar answered Nov 10 '22 02:11

GaretJax


Try this:

sudo('service apache2 restart',pty=False)

This worked for me after running into the same problem. I'm not sure why this happens.

like image 30
rupello Avatar answered Nov 10 '22 02:11

rupello


This is an instance of this issue and there is an entry in the FAQ that has the pty answer. Unfortunately on CentOS 6 doesn't support pty-less sudo commands and I didn't like the nohup solution since it killed output.

The final entry in the issue mentions using sudo('set -m; service servicename start'). This turns on Job Control and therefore background processes are put in their own process group. As a result they are not terminated when the command ends.

like image 4
Tim Ludwinski Avatar answered Nov 10 '22 03:11

Tim Ludwinski


When connecting to your remotes on behalf of a user granted enough privileges (such as root), you can manage system services as shown below:

from fabtools import service

service.restart('apache2')

https://fabtools.readthedocs.org/en/0.13.0/api/service.html

P.S. Its requires the installation of fabtools

pip install fabtools

like image 4
Thierry Marianne Avatar answered Nov 10 '22 01:11

Thierry Marianne