0

I have a Django 2.0 application hosted on VPS and is run by running command in SSH terminal

/root/.local/bin/pipenv run /home/user/.local/share/virtualenvs/example.com-IuTkL8w_/bin/gunicorn myapp.wsgi:application --timeout 300 --workers 1 --log-level=DEBUG &

Till few hours of running the application server using above command, Ajax requests works fine but after few hours it constantly fails.

There are many processes running behind that Ajax request but could not figure out where the request is breaking, since logs displays in console until SSH is live after running the above command. And there is no mean to check for console log after terminating SSH and logging again.

Killing all running process and restarting serving using above command again starts working fine for few hours.

1. What could be the reason for this ghost issue?
2. Is there some way to view console log in between anytime after SSH login?
3. If not, how can I set the server to restart automatically periodically (since, it is working again after restarting the server)?

Edit 2

I see in browser's network console, it is giving

 [Errno 5] Input/output error

on print() statement.

I have bunch of print() statements to see output in console like

print('----check_url')
print(check_url)
print('----product_id')
print(product_id)

Edit 3

I have following line in the code

with open(joined_path_with_file, 'wb') as f:
    f.write(r.content)

Is the issue with this?

Anuj TBE
  • 9,198
  • 27
  • 136
  • 285
  • Do you see incoming requests in the Django logs? In other words, is this an issue with the part that redirects the request to your Django server, or the Django server itself? – Willem Van Onsem Jul 09 '18 at 09:51
  • see `Edit 2`. The error is with `print()` statement. – Anuj TBE Jul 09 '18 at 09:58
  • Do you perhaps open file handlers with your server that you forget to close? Typically if an application keeps opening resources, without closing them. The operating system will eventually deny more resources. – Willem Van Onsem Jul 09 '18 at 09:59
  • No there is no file handlers used in the app – Anuj TBE Jul 09 '18 at 10:00
  • 1
    Use a process manager such as supervisord. And configure some logging. There's a bunch of optiions for logging. Django uses the stdlib python logging. Also for production use, a service like Sentry is really useful. – Håken Lid Jul 09 '18 at 10:01
  • @AnujTBE: nor other resources? Network connections, printers? It is also possible that you for example have handlers with a `FileField`, etc. The error seems to suggest that either the disk gets fully used, or you allocate too much resources. – Willem Van Onsem Jul 09 '18 at 10:01
  • is the issue related to `Edit 3`? Also there are lots of `requests.get` in the code. Does this require to be closed too? – Anuj TBE Jul 09 '18 at 10:02
  • @AnujTBE: I think that can be the case, how large is `r.content`? Do you have enough diskspace for this? – Willem Van Onsem Jul 09 '18 at 10:04
  • `r.content` size is in bytes and there are enough space in GBs in the server. – Anuj TBE Jul 09 '18 at 10:05
  • Is the parent process a ssh shell? That's very brittle, since ssh needs a constant tcp connection open or it will terminate. https://stackoverflow.com/questions/13654688/what-is-the-correct-way-to-leave-gunicorn-running – Håken Lid Jul 09 '18 at 10:06
  • yes, it is `SSH` but website works even after closing terminal only error is with Input/Out stdout – Anuj TBE Jul 09 '18 at 10:21

0 Answers0