Django on Heroku. No web processes running - django

I have a Django app which works when I run it locally heroku local. When I push my code to heroku git push heroku main it pushes without any problem, but when I opening my site it showes an 503 error in console
1 GET https://XXX.herokuapp.com/ 503 (Service Unavailable)
inside my logs I get this
at=error code=H14 desc="No web processes running" method=GET path="/" host=omylibrary.herokuapp.com request_id=lotofnumbers fwd="somenumbers" dyno= connect= service= status=503 bytes= protocol=https
from this question I assume that the problem is in ProcFile if more precisely in web. My Procfile looks like this
web: gunicorn --chdir ./Lib library.wsgi --log-file -
I also tried this
heroku ps:scale web=1
from previous answer. What Is wrong here ?
also heroku ps returns No dynos on mysite

The problem was that I named ProcFile instead of Procfile I found the solution here I have checked logs of heroku while pushing my app by terminal and I got
remote: Procfile declares types -> (none)
so if you don't have web process running probably it's because of procfile or the code inside it

Related

Docker Image works with docker-compose up but not on Amazon ECS or Heroku

I am trying to host a Django project with a Postgres database in a Docker container. The project is a practice e-commerce site with a database for product info. I was able to get it working with docker-compose up and accessed the site running in the container at localhost:8000 but when I tried hosting it on AWS it didn't work. I uploaded the image to ECR and started a cluster. When I tried running a task with the image, it showed PENDING but as soon as I tried to refresh, the task was gone. I tried setting up cloudwatch logs but they were empty since the task was stopping immediately after starting. After that I tried hosting on Heroku. I was able to deploy the image but when I tried to open the app it showed an error (shown below).
It feels like the image is just failing immediately whenever I try hosting it anywhere, but it works fine when I use docker-compose up. I think I'm making a very basic mistake (I'm a total beginner at all this) but not sure what it is. Thanks for taking the time to help.
I'll also add my Dockerfile and docker-compose.yml
Error Message from Heroku
2022-11-25T05:13:31.719689+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=hk-comic-app.herokuapp.com request_id=ea683b1d-e869-4ea9-98aa-2b9ed08f7219 fwd="98.116.68.242" dyno= connect= service= status=503 bytes= protocol=https
2022-11-25T05:22:36.083750+00:00 app[api]: Scaled to app#1:Free by user
2022-11-25T05:22:39.300239+00:00 heroku[app.1]: Starting process with command `python3`
2022-11-25T05:22:39.895200+00:00 heroku[app.1]: State changed from starting to up
2022-11-25T05:22:40.178736+00:00 heroku[app.1]: Process exited with status 0
2022-11-25T05:22:40.228638+00:00 heroku[app.1]: State changed from up to crashed
2022-11-25T05:22:40.232742+00:00 heroku[app.1]: State changed from crashed to starting
2022-11-25T05:22:43.937389+00:00 heroku[app.1]: Starting process with command `python3`
2022-11-25T05:22:44.610097+00:00 heroku[app.1]: State changed from starting to up
2022-11-25T05:22:45.130636+00:00 heroku[app.1]: Process exited with status 0
2022-11-25T05:22:45.180808+00:00 heroku[app.1]: State changed from up to crashed
2022-11-25T05:23:09.462805+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=hk-comic-app.herokuapp.com request_id=f4cc3e04-0257-4336-94b3-7e48094cabd4 fwd="98.116.68.242" dyno= connect= service= status=503 bytes= protocol=https
Dockerfile
FROM python:3.9-slim-buster
ENV PYTHONUNBUFFERED=1
WORKDIR /django
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
docker-compose.yml
version: "3"
services:
app:
build: .
volumes:
- .:/django
- ./wait-for-it.sh:/wait-for-it.sh
ports:
- 8000:8000
image: app:django
container_name: django_container
command: /wait-for-it.sh db:5432 -- python3 manage.py runserver 0.0.0.0:8000
depends_on:
- db
db:
image: postgres
volumes:
- ./data/db:/var/lib/postgresql/data
environment:
- POSTGRES_DB=comic_db
- POSTGRES_USER=comic_user
- POSTGRES_PASSWORD=password
container_name: postgres_db
Heroku doesn't use docker-compose.yml. You'll need to make a few changes:
Update your Dockerfile to include a command that should be used to run your application, e.g.
CMD gunicorn project_name.wsgi
This shouldn't impact your development environment since your docker-compose.yml overrides the command. You'll need to make sure Gunicorn (or whatever WSGI server you choose to use) is declared as a dependency.
Update your Django application to get its PostgreSQL connection string from the DATABASE_URL environment variable that Heroku provides. A common way to do that is by adding a dependency on dj-database-url and then changing your DATABASES setting accordingly:
DATABASES["default"] = dj_database_url.config()
I suggest you read the documentation for that library as there's more than one way to use it.
For example, you can optionally set a default connection for development via a default argument here. Or, if you prefer, you could set your own DATABASE_URL environment variable in your docker-compose.yml.
Provision a PostgreSQL database for your application. Make sure to do the first step to check whether you already have a database.
Then redeploy.

Application error on deployed django rest framework app on heroku

I'm trying to deploy my django rest framework app on Heroku. I read many other similar questions but I'm confused. My app structure is not right or I'm missing something.
This is my structure on git:
.gitignore
requirements.txt
src
|
--authorization
--core
--static
--staticfiles
--Procfile
--manage.py
--suacm
|
---asgi.py
---settings.py
---urls.py
---wsgi.py
authorization and core are apps under my django project. there wasn't static or staticfiles before heroku deploy. But it automatically created staticfiles. Then I also created static and followed instructions to make it work via changes in settings.py. It'd be awesome if someone help me figure out my problem on heroku and why it doesn't work.
This is Procfile:
web: gunicorn suacm.wsgi
web: gunicorn suacm:app
When I run app with this command my app works fine and run locally:
gunicorn suacm.wsgi:application
But I couldn't solve the error in deployed app.
With
heroku logs --tail
I receive errors starts like below:
2021-05-21T14:32:20.000000+00:00 app[api]: Build succeeded
2021-05-21T14:32:26.505788+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=suacm.herokuapp.com request_id=dfeba2ff-fa7d-4dfb-9337-706f50d286dc fwd="82.222.237.15" dyno= connect= service= status=503 bytes= protocol=https
2021-05-21T14:32:26.882608+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=suacm.herokuapp.com request_id=292525ae-bc4e-49c7-b979-e455bbfd6b95 fwd="82.222.237.15" dyno= connect= service= status=503 bytes= protocol=https
When I run this
heroku ps:scale web=1 --app suacm
I get this:
Scaling dynos... !
▸ Couldn't find that process type (web).
And finally when I try to run heroku locally under src folder with this command
src % heroku local web
I get this response:
[INFO] Starting gunicorn 20.1.0
[INFO] Listening at: http://0.0.0.0:5000 (35246)
[INFO] Using worker: sync
[INFO] Booting worker with pid: 35247
Failed to find attribute 'app' in 'suacm'.
[INFO] Worker exiting (pid: 35247)
.
.
If needed, this is my requirements.txt file:
django_environ==0.4.5
djangorestframework_simplejwt==4.6.0
django_filter==2.4.0
Django==3.1.3
djangorestframework==3.12.4
environ==1.0
PyJWT==2.1.0
gunicorn==20.1.0
django-on-heroku==1.1.2
whitenoise==5.2.0
This is my first time deploying a django app. I hope I gave enough information. Just ask if there is more information needed.
Put your Procfile in the root directory, not in the src and
change this
web: gunicorn suacm.wsgi
to
web: gunicorn src.suacm.wsgi
Then why it work on a local server?
In your local setup, you are launching the server from the src directory which is not the root directory!
But the in the production Heroku launches the application from the root directory, since there is no Procfile in the root directory you are getting these errors.

Django site hosting on Heroku "No web processes runnng"

So I tried to host my Django application to Heroku and at first it worked. Then I wanted to add some release commands so I did this:
release_commands.sh
python manage.py makemigrations
python manage.py migrate
And in my Procfile:
release: bash ./release_commands.sh
web: gunicorn todo.wsgi --log-file -
The second line in my Procfile is unchanged, so I guessed that the error must be coming from the release commands, but that's not the case as in my heroku logs I have this:
2021-02-17T19:41:31.675215+00:00 heroku[release.6232]: Process exited with status 0
2021-02-17T19:41:31.772693+00:00 heroku[release.6232]: State changed from up to complete
2021-02-17T19:41:34.021990+00:00 app[api]: Release v11 created by user georgi.hr.dim#gmail.com
This is the error message:
2021-02-17T19:41:43.594322+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=POST path="/accounts/login/?next=/" host=essentialtodo.herokuapp.com request_id=5dce4816-6343-44c3-9c8f
-171e79379abc fwd="78.90.0.206" dyno= connect= service= status=503 bytes= protocol=https
Just found out what the problem was. For some reason after adding the release commands my dynos were turned off. To fix this: go to your heroku app (on the heroku website) -> go to resources -> press the edit button on your dyno -> turn it on and confirm
.

Django H14 Heroku error, how do i fix this?

2020-09-08T17:05:06.205027+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=uvdocdash.herokuapp.com request_id=f17ceaee-3e7c-4eba-aebf-19dd4b424eee fwd="70.39.71.29" dyno= connect= service= status=503 bytes= protocol=https
I get this error in the logs, so far I havent been able to find out why my app isnt working. It's a django app, and the requirments.txt is correct as far as i know.
asgiref==3.2.10
Django==3.1.1
gunicorn==20.0.4
pytz==2020.1
sqlparse==0.3.1
django-heroku >= 0.3.1
Add a Procfile to your folder that has manage.py in it. Just add a file called Procfile and add web: gunicorn projectname.wsgi inside of that file. save and push.

Heroku logs says: "No web processes running"

I made a website with django and tried deploying it using Heroku. After deploying, I can't access to it and Heroku log shows the following error :
at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=pur-beurre-oc8.herokuapp.com request_id=9e33d4c8-83d6-4214-baf8-e4d1023b43ff fwd="176.134.6.63" dyno= connect= service= status=503 bytes= protocol=https
After looking through some similar problems, I tried:
heroku ps:scale web=1
and got:
Scaling dynos... !
▸ Couldn't find that process type (web).
I tried to remove and add buildpacks:
heroku buildpacks:clear
heroku buildpacks:add --index heroku/python
but this last command return to me:
Error: Expected an integer but received: heroku/python
at Object.parse (/snap/heroku/3832/node_modules/#oclif/parser/lib/flags.js:17:19)
at Parser._flags (/snap/heroku/3832/node_modules/#oclif/parser/lib/parse.js:152:49)
at Parser.parse (/snap/heroku/3832/node_modules/#oclif/parser/lib/parse.js:113:28)
at Object.parse (/snap/heroku/3832/node_modules/#oclif/parser/lib/index.js:25:27)
at Add.parse (/snap/heroku/3832/node_modules/#oclif/command/lib/command.js:83:41)
at Add.run (/snap/heroku/3832/node_modules/#heroku-cli/plugin-buildpacks/lib/commands/buildpacks/add.js:7:36)
at Add._run (/snap/heroku/3832/node_modules/#oclif/command/lib/command.js:44:31)
So I do not know what I'm doing wrong
My Proficle is like this:
web: gunicorn pur_beurre.wsgi
I tried to change Procfile like this:
web: gunicorn pur_beurre:app
or this:
web gunicorn pur_beurre:app
but heroku ps:scale web=1 still not working
Edit
My Procfile was not in my app’s root directory, so I moved it and now heroku ps:scale web=1 returns:
Scaling dynos... done, now running web at 1:Free
But I still have the error:
at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=pur-beurre-oc8.herokuapp.com request_id=8cc800fa-cd49-43a9-8fc5-babf0028ca1f fwd="176.134.6.63" dyno= connect= service= status=503 bytes= protocol=https