gunicornがubuntu上でのsudo systemctl enable gunicornで動きません。

1,825 views
Skip to first unread message

yyy so

unread,
Oct 30, 2018, 8:57:30 PM10/30/18
to django-ja
環境
django2 nginx
で、APIを作り、アマゾンインスタンスのubuntu上にデプロイしようとしています。

virtualenv上での
manage.py runserver
gunicorn –-bind 0.0.0.0:8000 project-name.wsgi
は問題なく起動しました。

その後、
sudo vim /etc/systemd/system/gunicorn.service

[Unit]

Description=gunicorn daemon

After=network.target

 

[Service]

User=ubuntu

Group=www-data

WorkingDirectory=/home/ubuntu/myFirstAPI

ExecStart=/home/ubuntu/myFirstAPI/myFirstAPI(envのフォルダ)/bin/gunicorn --access-logfile - -- workers 3 --bind unix:/home/ubuntu/myFirstAPI/project.sock project.wsgi:application

 

[Install]

WantedBy=multi-user.target
と記入し、

sudo systemctl start gunicorn

sudo systemctl enable gunicorn

sudo systemctl status gunicorn


として動作確認したところ、


 gunicorn.service - gunicorn daemon

   Loaded: loaded (/etc/systemd/system/gunicorn.service; disabled; vendor preset

   Active: failed (Result: exit-code) since Sun 2018-10-28 15:07:34 UTC; 1 day 2

 Main PID: 2001 (code=exited, status=3)


Oct 28 15:07:34 ip-10-0-0-186 gunicorn[2001]:   File "/home/ubuntu/myFirstAPI/my

Oct 28 15:07:34 ip-10-0-0-186 gunicorn[2001]:     return util.import_app(self.ap

Oct 28 15:07:34 ip-10-0-0-186 gunicorn[2001]:   File "/home/ubuntu/myFirstAPI/my

Oct 28 15:07:34 ip-10-0-0-186 gunicorn[2001]:     __import__(module)

Oct 28 15:07:34 ip-10-0-0-186 gunicorn[2001]: ModuleNotFoundError: No module nam

Oct 28 15:07:34 ip-10-0-0-186 gunicorn[2001]: [2018-10-28 15:07:34 +0000] [2020]

Oct 28 15:07:34 ip-10-0-0-186 gunicorn[2001]: [2018-10-28 15:07:34 +0000] [2001]

Oct 28 15:07:34 ip-10-0-0-186 gunicorn[2001]: [2018-10-28 15:07:34 +0000] [2001]

Oct 28 15:07:34 ip-10-0-0-186 systemd[1]: gunicorn.service: Main process exited,

Oct 28 15:07:34 ip-10-0-0-186 systemd[1]: gunicorn.service: Failed with result '


と、ActiveがFailedでうまく動いておりません、、、、

のサイトを参考に進め、postgresqlだけ無視(正確には失敗した)しています。
はじめてのプログラミング、デプロイでこれまで幾多のエラーを起こしてまいりましたが、
今までになく見当もつきません。
どなたかお力お借りすることができればとわらにもすがる思いで投稿させていただきます。
どうぞお知恵をお貸しくださいませ。
よろしくお願いいたします。

筒井 隆次

unread,
Oct 31, 2018, 2:12:50 AM10/31/18
to djan...@googlegroups.com
と、ActiveがFailedでうまく動いておりません、、、、
これの上に貼ってもらったログは、右側が切れていないでしょうか?
「ModuleNotFoundError: No module nam」の部分はおそらく「ModuleNotFoundError: No module named ‘xxxx'」のような表示で、何らかのPythonライブラリが足りなくてエラーになっているはずですが、名前が見えないので何とも言えません。


virtualenv上での
manage.py runserver
gunicorn –-bind 0.0.0.0:8000 project-name.wsgi
は問題なく起動しました。
一点確認しておきたいのですが、上記動作確認のとき使ったvirtualenv環境にactivateした状態で「which gunicorn」したとき、gunicorn.serviceのExecStartに書いたgunicornへのパスと同じ値が表示されるでしょうか?
もし違っていたら、「which gunicorn」で表示されるパスをgunicorn.serviceのExecStartに書くようにすれば動くはずです。


2018/10/30 23:47、yyy so <djma...@gmail.com>のメール:

--
----------------- http://djangoproject.jp/ -----------------
You received this message because you are subscribed to the Google Groups "django-ja" group.
To post to this group, send email to djan...@googlegroups.com
To unsubscribe from this group, send email to django-ja-...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-ja
---
このメールは Google グループのグループ「django-ja」に登録しているユーザーに送られています。
このグループから退会し、グループからのメールの配信を停止するには django-ja+...@googlegroups.com にメールを送信してください。
その他のオプションについては https://groups.google.com/d/optout にアクセスしてください。

yyy so

unread,
Nov 3, 2018, 9:51:48 AM11/3/18
to django-ja
ご助言ありがとうございます!
ログは確かに切れておりました

Oct 28 15:07:34 ip-10-0-0-186 gunicorn[2001]:   File "/home/ubuntu/myFirstAPI/myFirstAPI/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
Oct 28 15:07:34 ip-10-0-0-186 gunicorn[2001]:     return util.import_app(self.app_uri)
Oct 28 15:07:34 ip-10-0-0-186 gunicorn[2001]:   File "/home/ubuntu/myFirstAPI/myFirstAPI/lib/python3.6/site-packages/gunicorn/util.py", line 350, in import_app
Oct 28 15:07:34 ip-10-0-0-186 gunicorn[2001]:     __import__(module)
Oct 28 15:07:34 ip-10-0-0-186 gunicorn[2001]: ModuleNotFoundError: No module named 'worker'
Oct 28 15:07:34 ip-10-0-0-186 gunicorn[2001]: [2018-10-28 15:07:34 +0000] [2020] [INFO] Worker exiting (pid: 2020)
Oct 28 15:07:34 ip-10-0-0-186 gunicorn[2001]: [2018-10-28 15:07:34 +0000] [2001] [INFO] Shutting down: Master
Oct 28 15:07:34 ip-10-0-0-186 gunicorn[2001]: [2018-10-28 15:07:34 +0000] [2001] [INFO] Reason: Worker failed to boot.
Oct 28 15:07:34 ip-10-0-0-186 systemd[1]: gunicorn.service: Main process exited, code=exited, status=3/NOTIMPLEMENTED
Oct 28 15:07:34 ip-10-0-0-186 systemd[1]: gunicorn.service: Failed with result 'exit-code'.

が本来のログで、workerというpythonモジュールが足りていないんですね
ではモジュールを追加、またはパスを通せば解決するかも、ということですね!
試してみます!


which gunicorn で表示されるパスはそのまま書いていて起きたエラーでしたので、上の線でやってみます。

2018年10月31日水曜日 15時12分50秒 UTC+9 Ryuji Tsutsui:
Reply all
Reply to author
Forward
0 new messages