简体   繁体   English

如何使用Foreman正确关闭和转储Redis服务器?

[英]How do I properly shutdown and dump a Redis server with Foreman?

I have a Procfile that I use with Foreman to start my local redis and webrick server: 我有一个与Foreman一起使用的Procfile,用于启动本地Redis和Webrick服务器:

web: bundle exec rails server -p $PORT
redis: redis-server config/redis.development.conf

I connect to Redis using a named socket that is defined in the configuration like this: 我使用如下配置中定义的命名套接字连接到Redis:

unixsocket /tmp/redis-APPNAME.sock

Everything works fine in Rails, but when I hit CTRL + C to terminate Foreman in the terminal, the Redis DB is not dumped. 在Rails中一切正常,但是当我按CTRL + C终止终端中的Foreman时,Redis数据库不会被转储。 The Redis server is terminated by SIGINT this way. Redis服务器terminated by SIGINT So, whenever I restart the Foreman stack I get old Redis data. 因此,每当重新启动Foreman堆栈时,我都会得到旧的Redis数据。

Is there a way to tell Foreman to use the proper SHUTDOWN on Redis that will also dump the database? 有没有一种方法可以让Foreman在Redis上使用正确的SHUTDOWN来转储数据库? Or should I modify the Redis config to persist data all the time in development? 还是应该修改Redis配置以在开发过程中始终保留数据?

您是否尝试过使用包装脚本来发送SIGTERM

I ended up using Append-only File persistance on my development laptop for Redis instances. 我最终在开发笔记本电脑上针对Redis实例使用了仅附加文件持久性。 To turn it on you just have to add appendonly yes to your redis config. 要打开它,您只需在您的redis配置中添加appendonly yes I left the fsync option to 1 second. 我将fsync选项设置为1秒。

This way I always get persisted data when I terminate Foreman and switch to another project. 这样,当我终止Foreman并切换到另一个项目时,我总是会获得持久数据。

More details about Redis persistance options here: http://redis.io/topics/persistence 有关Redis持久性选项的更多详细信息,请参见: http : //redis.io/topics/persistence

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM