工头在“工头开始”后关闭了美洲狮
Foreman shuts down puma after `foreman start`
我的 puma 服务器没有保持活动状态,它一直在关闭。我认为这与发布有关,但不确定如何使其动态化,因此它适用于 heroku 但不适用于工头。
我在 运行 foreman start
时使用 procfile 启动了我的 puma 服务器和 sidekiq worker
请看下面的设置代码。我不确定为什么它一直关闭。
我安装了工头
$ gem install foreman
设置 Procfile
Procfile.rb
release: bin/heroku_release.sh
web: bundle exec puma -C ./config/puma.rb
worker: bundle exec sidekiq
设置一个bin/heroku_release.sh文件
heroku__release.sh 文件
#!/usr/bin/env bash
#
# Usage: bin/heroku_deploy
RED='3[0;31m'
GREEN='3[0;32m'
YELLOW='3[0;33m'
NO_COLOR='3[0m'
CLEAR_LINE='\r3[K'
set -euo pipefail
schema_version=$(bin/rails db:version | { grep "^Current version: [0-9]\+$" || true; } | tr -s ' ' | cut -d ' ' -f3)
if [ -z "$schema_version" ]; then
printf "${RED} [Release Phase]: Database schema version could not be determined. Does the database exist?${NO_COLOR}\n"
exit 1
fi
if [ "$schema_version" -eq "0" ]; then
printf "\n⏳${YELLOW} [Release Phase]: Loading the database schema.${NO_COLOR}\n"
bin/rails db:schema:load
else
printf "\n⏳${YELLOW} [Release Phase]: Running database migrations.${NO_COLOR}\n"
bin/rails db:migrate
fi
printf "\n${GREEN} [Release Phase]: Database is up to date.${NO_COLOR}\n"
foreman start
之后的控制台:
14:53:39 release.1 | started with pid 10418
14:53:39 web.1 | started with pid 10419
14:53:39 worker.1 | started with pid 10420
14:53:40 web.1 | Puma starting in single mode...
14:53:40 web.1 | * Version 4.3.5 (ruby 2.7.1-p83), codename: Mysterious Traveller
14:53:40 web.1 | * Min threads: 5, max threads: 5
14:53:40 web.1 | * Environment: development
14:53:44 web.1 | * Listening on tcp://0.0.0.0:5100
14:53:44 web.1 | Use Ctrl-C to stop
14:53:44 release.1 |
14:53:44 release.1 | ⏳ [Release Phase]: Running database migrations.
14:53:44 worker.1 | 2020-09-25T19:53:44.905Z pid=10420 tid=arg INFO: Booted Rails 6.0.3.3 application in development environment
14:53:44 worker.1 | 2020-09-25T19:53:44.906Z pid=10420 tid=arg INFO: Running in ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin17]
14:53:44 worker.1 | 2020-09-25T19:53:44.907Z pid=10420 tid=arg INFO: See LICENSE and the LGPL-3.0 for licensing details.
14:53:44 worker.1 | 2020-09-25T19:53:44.907Z pid=10420 tid=arg INFO: Upgrade to Sidekiq Pro for more features and support: https://sidekiq.org
14:53:44 worker.1 | 2020-09-25T19:53:44.907Z pid=10420 tid=arg INFO: Booting Sidekiq 6.1.2 with redis options {}
14:53:44 worker.1 | 2020-09-25T19:53:44.910Z pid=10420 tid=arg DEBUG: Client Middleware:
14:53:44 worker.1 | 2020-09-25T19:53:44.910Z pid=10420 tid=arg DEBUG: Server Middleware:
14:53:44 worker.1 | 2020-09-25T19:53:44.911Z pid=10420 tid=arg DEBUG: {:queues=>["critical", "default", "mailers"], :labels=>[], :concurrency=>10, :require=>".", :strict=>true, :environment=>nil, :timeout=>25, :poll_interval_average=>nil, :average_scheduled_poll_interval=>5, :error_handlers=>[#<Sidekiq::ExceptionHandler::Logger:0x00007ff9e2a150e8>], :death_handlers=>[], :lifecycle_events=>{:startup=>[], :quiet=>[], :shutdown=>[], :heartbeat=>[]}, :dead_max_jobs=>10000, :dead_timeout_in_seconds=>15552000, :reloader=>#<Sidekiq::Rails::Reloader @app=Teacher::Application>, :verbose=>true, :production=>{:concurrency=>25}, :staging=>{:concurrency=>15}, :config_file=>"./config/sidekiq.yml", :tag=>"teacher", :identity=>"me-MacBook-Air.local", :fetch=>#<Sidekiq::BasicFetch:0x00007ff9e906d430 @options={...}, @strictly_ordered_queues=true, @queues=["queue:critical", "queue:default", "queue:mailers", 2]>}
14:53:48 release.1 | (0.3ms) SELECT pg_try_advisory_lock(5720425725902639640)
14:53:48 release.1 | (1.4ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
14:53:48 release.1 | ActiveRecord::InternalMetadata Load (0.6ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = LIMIT [["key", "environment"], ["LIMIT", 1]]
14:53:48 release.1 | (0.4ms) SELECT pg_advisory_unlock(5720425725902639640)
14:53:48 release.1 | (1.5ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
14:53:48 release.1 |
14:53:48 release.1 | [Release Phase]: Database is up to date.
14:53:48 release.1 | exited with code 0
14:53:48 system | sending SIGTERM to all processes
14:53:48 web.1 | - Gracefully stopping, waiting for requests to finish
14:53:48 worker.1 | 2020-09-25T19:53:48.873Z pid=10420 tid=arg DEBUG: Got TERM signal
14:53:48 worker.1 | 2020-09-25T19:53:48.873Z pid=10420 tid=arg INFO: Shutting down
14:53:48 worker.1 | 2020-09-25T19:53:48.873Z pid=10420 tid=arg INFO: Terminating quiet workers
14:53:48 worker.1 | 2020-09-25T19:53:48.874Z pid=10420 tid=1qno INFO: Scheduler exiting...
14:53:48 web.1 | === puma shutdown: 2020-09-25 14:53:48 -0500 ===
14:53:48 web.1 | - Goodbye!
14:53:48 web.1 | terminated by SIGTERM
14:53:49 worker.1 | 2020-09-25T19:53:49.380Z pid=10420 tid=arg INFO: Bye!
14:53:49 worker.1 | exited with code 0
我认为问题在于您制作的 Heroku release
脚本不适用于开发环境。 Heroku 知道将该脚本作为其管理的构建管道的一部分来处理 behind the scenes,但是您在开发中的工头实例没有任何特殊处理来知道该做什么。默认情况下,Foreman 用于 long-running 个进程,Heroku 通过 Procfile 处理短 one-off 个进程的操作是针对其平台定制的。
我建议创建两个不同的 Procfile,一个用于开发,一个用于生产,因为它们必然会随着时间的推移而有所不同。我常用的一种设置是:
- Procfile - 默认生产 procfile
- Procfile.dev - 我想要 运行 在开发中的 procfile。
你的开发过程文件真的只需要你的长 运行ning 进程在里面,因为你可以手动 运行 迁移(或你的发布脚本),而不用担心影响任何人。
要在本地 运行 一个不同的 Procfile(即 Procfile.dev),你只需要 运行:
foreman start -f Procfile.dev
我的 puma 服务器没有保持活动状态,它一直在关闭。我认为这与发布有关,但不确定如何使其动态化,因此它适用于 heroku 但不适用于工头。
我在 运行 foreman start
请看下面的设置代码。我不确定为什么它一直关闭。
我安装了工头
$ gem install foreman
设置 Procfile
Procfile.rb
release: bin/heroku_release.sh
web: bundle exec puma -C ./config/puma.rb
worker: bundle exec sidekiq
设置一个bin/heroku_release.sh文件
heroku__release.sh 文件
#!/usr/bin/env bash
#
# Usage: bin/heroku_deploy
RED='3[0;31m'
GREEN='3[0;32m'
YELLOW='3[0;33m'
NO_COLOR='3[0m'
CLEAR_LINE='\r3[K'
set -euo pipefail
schema_version=$(bin/rails db:version | { grep "^Current version: [0-9]\+$" || true; } | tr -s ' ' | cut -d ' ' -f3)
if [ -z "$schema_version" ]; then
printf "${RED} [Release Phase]: Database schema version could not be determined. Does the database exist?${NO_COLOR}\n"
exit 1
fi
if [ "$schema_version" -eq "0" ]; then
printf "\n⏳${YELLOW} [Release Phase]: Loading the database schema.${NO_COLOR}\n"
bin/rails db:schema:load
else
printf "\n⏳${YELLOW} [Release Phase]: Running database migrations.${NO_COLOR}\n"
bin/rails db:migrate
fi
printf "\n${GREEN} [Release Phase]: Database is up to date.${NO_COLOR}\n"
foreman start
之后的控制台:
14:53:39 release.1 | started with pid 10418
14:53:39 web.1 | started with pid 10419
14:53:39 worker.1 | started with pid 10420
14:53:40 web.1 | Puma starting in single mode...
14:53:40 web.1 | * Version 4.3.5 (ruby 2.7.1-p83), codename: Mysterious Traveller
14:53:40 web.1 | * Min threads: 5, max threads: 5
14:53:40 web.1 | * Environment: development
14:53:44 web.1 | * Listening on tcp://0.0.0.0:5100
14:53:44 web.1 | Use Ctrl-C to stop
14:53:44 release.1 |
14:53:44 release.1 | ⏳ [Release Phase]: Running database migrations.
14:53:44 worker.1 | 2020-09-25T19:53:44.905Z pid=10420 tid=arg INFO: Booted Rails 6.0.3.3 application in development environment
14:53:44 worker.1 | 2020-09-25T19:53:44.906Z pid=10420 tid=arg INFO: Running in ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin17]
14:53:44 worker.1 | 2020-09-25T19:53:44.907Z pid=10420 tid=arg INFO: See LICENSE and the LGPL-3.0 for licensing details.
14:53:44 worker.1 | 2020-09-25T19:53:44.907Z pid=10420 tid=arg INFO: Upgrade to Sidekiq Pro for more features and support: https://sidekiq.org
14:53:44 worker.1 | 2020-09-25T19:53:44.907Z pid=10420 tid=arg INFO: Booting Sidekiq 6.1.2 with redis options {}
14:53:44 worker.1 | 2020-09-25T19:53:44.910Z pid=10420 tid=arg DEBUG: Client Middleware:
14:53:44 worker.1 | 2020-09-25T19:53:44.910Z pid=10420 tid=arg DEBUG: Server Middleware:
14:53:44 worker.1 | 2020-09-25T19:53:44.911Z pid=10420 tid=arg DEBUG: {:queues=>["critical", "default", "mailers"], :labels=>[], :concurrency=>10, :require=>".", :strict=>true, :environment=>nil, :timeout=>25, :poll_interval_average=>nil, :average_scheduled_poll_interval=>5, :error_handlers=>[#<Sidekiq::ExceptionHandler::Logger:0x00007ff9e2a150e8>], :death_handlers=>[], :lifecycle_events=>{:startup=>[], :quiet=>[], :shutdown=>[], :heartbeat=>[]}, :dead_max_jobs=>10000, :dead_timeout_in_seconds=>15552000, :reloader=>#<Sidekiq::Rails::Reloader @app=Teacher::Application>, :verbose=>true, :production=>{:concurrency=>25}, :staging=>{:concurrency=>15}, :config_file=>"./config/sidekiq.yml", :tag=>"teacher", :identity=>"me-MacBook-Air.local", :fetch=>#<Sidekiq::BasicFetch:0x00007ff9e906d430 @options={...}, @strictly_ordered_queues=true, @queues=["queue:critical", "queue:default", "queue:mailers", 2]>}
14:53:48 release.1 | (0.3ms) SELECT pg_try_advisory_lock(5720425725902639640)
14:53:48 release.1 | (1.4ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
14:53:48 release.1 | ActiveRecord::InternalMetadata Load (0.6ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = LIMIT [["key", "environment"], ["LIMIT", 1]]
14:53:48 release.1 | (0.4ms) SELECT pg_advisory_unlock(5720425725902639640)
14:53:48 release.1 | (1.5ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
14:53:48 release.1 |
14:53:48 release.1 | [Release Phase]: Database is up to date.
14:53:48 release.1 | exited with code 0
14:53:48 system | sending SIGTERM to all processes
14:53:48 web.1 | - Gracefully stopping, waiting for requests to finish
14:53:48 worker.1 | 2020-09-25T19:53:48.873Z pid=10420 tid=arg DEBUG: Got TERM signal
14:53:48 worker.1 | 2020-09-25T19:53:48.873Z pid=10420 tid=arg INFO: Shutting down
14:53:48 worker.1 | 2020-09-25T19:53:48.873Z pid=10420 tid=arg INFO: Terminating quiet workers
14:53:48 worker.1 | 2020-09-25T19:53:48.874Z pid=10420 tid=1qno INFO: Scheduler exiting...
14:53:48 web.1 | === puma shutdown: 2020-09-25 14:53:48 -0500 ===
14:53:48 web.1 | - Goodbye!
14:53:48 web.1 | terminated by SIGTERM
14:53:49 worker.1 | 2020-09-25T19:53:49.380Z pid=10420 tid=arg INFO: Bye!
14:53:49 worker.1 | exited with code 0
我认为问题在于您制作的 Heroku release
脚本不适用于开发环境。 Heroku 知道将该脚本作为其管理的构建管道的一部分来处理 behind the scenes,但是您在开发中的工头实例没有任何特殊处理来知道该做什么。默认情况下,Foreman 用于 long-running 个进程,Heroku 通过 Procfile 处理短 one-off 个进程的操作是针对其平台定制的。
我建议创建两个不同的 Procfile,一个用于开发,一个用于生产,因为它们必然会随着时间的推移而有所不同。我常用的一种设置是:
- Procfile - 默认生产 procfile
- Procfile.dev - 我想要 运行 在开发中的 procfile。
你的开发过程文件真的只需要你的长 运行ning 进程在里面,因为你可以手动 运行 迁移(或你的发布脚本),而不用担心影响任何人。
要在本地 运行 一个不同的 Procfile(即 Procfile.dev),你只需要 运行:
foreman start -f Procfile.dev