Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Foreman Cannot Start Nginx, But I Can Start it Manually. Why?

I am currently running Foreman on staging (Ubuntu) and once I get it working will switch to using upstart.

My Procfile.staging looks like this:

nginx: sudo service nginx start
unicorn: bundle exec unicorn -c ./config/unicorn.rb
redis: bundle exec redis-server
sidekiq: bundle exec sidekiq -v -C ./config/sidekiq.yml

I can successfully start nginx using:

$ sudo service nginx start

However when I run $ foreman start, whilst the other three processes start successfully, nginx does not:

11:15:46 nginx.1   | started with pid 15966
11:15:46 unicorn.1 | started with pid 15968
11:15:46 redis.1   | started with pid 15971
11:15:46 sidekiq.1 | started with pid 15974
11:15:46 nginx.1   | Starting nginx: nginx.
11:15:46 nginx.1   | exited with code 0
11:15:46 system    | sending SIGTERM to all processes
SIGTERM received
11:15:46 unicorn.1 | terminated by SIGTERM
11:15:46 redis.1   | terminated by SIGTERM
11:15:46 sidekiq.1 | terminated by SIGTERM

So why isn't nginx starting when started by Foreman?

like image 691
Undistraction Avatar asked Feb 01 '13 11:02

Undistraction


1 Answers

The is a problem in your Procfile.

The nginx command can't use sudo inside foreman, because it will always ask for a password and then it will fail. That's why you are not starting nginx and the logs are empty.

If you really need to use sudo inside a procfile you could use something like this:

sudo_app: echo "sudo_password" | sudo -S app_command
nginx: echo "sudo_password" | sudo -S service nginx start

which I really don't recommend. Other option is to call sudo foreman start

For more information check out this issue on github, it is precisely what you want to solve.

Keep me posted if it works for you.

like image 177
Nicos Karalis Avatar answered Oct 02 '22 17:10

Nicos Karalis