Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

gunicornエラー

解決したいこと

ここに解決したい内容を記載してください。

例)
Djangoでアプリを作成しています。
EC2、gunicorn、nginxを使用してデプロイしようとしていますが、エラーが発生しました。
解決方法を教えて下さい。

発生している問題・エラー

● gunicorn.service - gunicorn daemon
   Loaded: error (Reason: Invalid argument)
   Active: failed (Result: exit-code) since 日 2022-02-27 09:19:14 UTC; 1h 30min ago
 Main PID: 14745 (code=exited, status=203/EXEC)

 2月 27 09:19:14 ip-10-0-10-248.ap-northeast-1.compute.internal systemd[14745]: Failed at step EXEC spawning /usr/local/bin/gunicorn: No such file or directory
 2月 27 09:19:14 ip-10-0-10-248.ap-northeast-1.compute.internal systemd[1]: gunicorn.service: main process exited, code=exited, status=203/EXEC
 2月 27 09:19:14 ip-10-0-10-248.ap-northeast-1.compute.internal systemd[1]: Unit gunicorn.service entered failed state.
 2月 27 09:19:14 ip-10-0-10-248.ap-northeast-1.compute.internal systemd[1]: gunicorn.service failed.
 2月 27 09:34:01 ip-10-0-10-248.ap-northeast-1.compute.internal systemd[1]: [/etc/systemd/system/gunicorn.service:10] Executable path is not absolute, ignoring: ~/ven...ication
 2月 27 09:34:01 ip-10-0-10-248.ap-northeast-1.compute.internal systemd[1]: [/etc/systemd/system/gunicorn.service:11] Unknown lvalue 'RemainAfterExist' in section 'Service'
 2月 27 09:34:01 ip-10-0-10-248.ap-northeast-1.compute.internal systemd[1]: gunicorn.service lacks both ExecStart= and ExecStop= setting. Refusing.
 2月 27 09:35:48 ip-10-0-10-248.ap-northeast-1.compute.internal systemd[1]: [/etc/systemd/system/gunicorn.service:10] Executable path is not absolute, ignoring: ~/.lo...ication
 2月 27 09:35:48 ip-10-0-10-248.ap-northeast-1.compute.internal systemd[1]: [/etc/systemd/system/gunicorn.service:11] Unknown lvalue 'RemainAfterExist' in section 'Service'
 2月 27 09:35:48 ip-10-0-10-248.ap-northeast-1.compute.internal systemd[1]: gunicorn.service lacks both ExecStart= and ExecStop= setting. Refusing.
Warning: gunicorn.service changed on disk. Run 'systemctl daemon-reload' to reload units.
Hint: Some lines were ellipsized, use -l to show in full.

例)

NameError (uninitialized constant World)

または、問題・エラーが起きている画像をここにドラッグアンドドロップ

該当するソースコード

Description=gunicorn daemon 
Requires=gunicorn.socket 
After=network.target

[Service]
User=ec2-user
Group=www-data 
WorkingDirectory=/home/ec2-user/econal
ExecStart=/home/ec2-user/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/ec2-user/econal/econal.sock wsgi:application
RemainAfterExist=yes

[Install]
WantedBy=multi-user.target

自分で試したこと

ネットで調べながら色々と試していましたが、やっている内容を理解しきれておらず苦戦しています。
0 likes

5Answer

Run 'systemctl daemon-reload' to reload units.

(root権限で)以下のコマンドを実行した後、再度試してみてください。

systemctl daemon-reload
0Like

ご回答いただきありがとうございます。
上記のコマンドを実行してみましたが、「systemctl status gunicorn.service」の結果は変わりませんでした。
どこをお見せすれば解決につながるか教えていただければ幸いです。

0Like
 2月 27 09:19:14 ip-10-0-10-248.ap-northeast-1.compute.internal systemd[14745]: Failed at step EXEC spawning /usr/local/bin/gunicorn: No such file or directory

/usr/local/bin/gunicorn が存在しないというエラーが出ています。 ご質問のソースコードからは使われていないようですが。

 2月 27 09:34:01 ip-10-0-10-248.ap-northeast-1.compute.internal systemd[1]: [/etc/systemd/system/gunicorn.service:10] Executable path is not absolute, ignoring: ~/ven...ication

ExecStart で実行ファイルが絶対パスで指定されていないエラーも出ています。これも絶対パスになっているはずです。

もしかしてソースコードを変えながら何度か起動を試した結果のエラーログをまとめて貼っているのでしょうか。現在のソースコードで起動したときのログだけ貼ってもらえると助かります。

0Like

/home/ec2-user/econal/start_gunicorn.sh を作って以下の内容を書き込み、

#!/bin/sh

source /home/ec2-user/venv/activate
exec /home/ec2-user/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/ec2-user/econal/econal.sock wsgi:application

chmod +x /home/ec2-user/econal/start_gunicorn.sh を実行して、 ExecStart を以下のように変えれば起動できると思います。

ExecStart=/home/ec2-user/econal/start_gunicorn.sh

また、エラーログに出ているように、 RemainAfterExist は間違いです。 RemainAfterExit に直してください。

0Like

Comments

  1. @kanji_hirayama

    Questioner

    gunicornの設定うまくできました。ファイアウォールの設定がうまくいかずにサイトにアクセスできないのですがどのように設定したらよいかご教授していただけないでしょうか。
    自分が試したこと
    sudo ufw allow 'Nginx Full'
    結果
    ERROR: Could not find a profile matching 'Nginx Full'
    試したこと
    sudo ufw status
    結果
    To Action From
    -- ------ ----
    SSH ALLOW Anywhere
    224.0.0.251 mDNS ALLOW Anywhere
    8000 ALLOW Anywhere
    SSH (v6) ALLOW Anywhere (v6)
    ff02::fb mDNS ALLOW Anywhere (v6)

Your answer might help someone💌