如果服务器尚未运行,我想编写一个 grunt 任务来启动进程 mongod。我需要一个正在运行的 mongod 进程,但还需要 grunt-watch 以便稍后在任务流中工作。
This question解释了如何使用 grunt-shell 启动 mongod ...接受的答案是阻塞的,异步版本将生成一个新服务器,即使存在一个。
有没有办法(例如 shell 脚本)仅在 mongod 未运行时启动它,而不会阻塞其余的 grunt 任务流?
谢谢
最佳答案
这是一个更简洁的版本
将其存储为 startMongoIfNotRunning.sh与 Gruntfile 位于同一位置:
# this script checks if the mongod is running, starts it if not
if pgrep -q mongod; then
echo running;
else
mongod;
fi
exit 0;
在你的 Gruntfile 中:
shell: {
mongo: {
command: "sh startMongoIfNotRunning.sh",
options: {
async: true
}
},
}
编辑 - 原始版本如下
好的 - 我认为这工作正常......
创建一个 shell 脚本,如果它没有运行,它将启动 mongod...将它保存在某个地方,可能在您的项目中。我将其命名为 startMongoIfNotRunning.sh :
# this script checks if the mongod is running, starts it if not
`ps -A | grep -q '[m]ongod'`
if [ "$?" -eq "0" ]; then
echo "running"
else
mongod
fi
您可能必须使其可执行:chmod +x path/to/script/startMongoIfNotRunning.sh
安装 grunt-shell-spawn:npm install grunt-shell-spawn --save-dev
然后在你的 Gruntfile 中添加:
shell: {
mongo: {
command: "exec path/to/script/startMongoIfNotRunning.sh",
options: {
async: true
}
},
}
(如果您使用的是 yeoman,则使用 <%= yeoman.app %> 无效,因为这些路径是相对于整个项目的,因此您会得到类似“app”的内容,而不是脚本的整个路径。我敢肯定你可以让它工作,我只是不知道如何获得 )
如果你只是执行任务grunt shell:mongo mongod 将启动,但我无法使用 grunt shell:mongo:kill 关闭它.但是,假设您稍后使用阻塞任务(我使用的是 watch ),那么当您结束该任务时它应该会自动终止。
希望这对某人有帮助!
关于javascript - 咕噜任务 : start mongod if not running,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20696457/
我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时
如何使用RSpec::Core::RakeTask初始化RSpecRake任务?require'rspec/core/rake_task'RSpec::Core::RakeTask.newdo|t|#whatdoIputinhere?endInitialize函数记录在http://rubydoc.info/github/rspec/rspec-core/RSpec/Core/RakeTask#initialize-instance_method没有很好的记录;它只是说:-(RakeTask)initialize(*args,&task_block)AnewinstanceofRake
我写了一个非常简单的rake任务来尝试找到这个问题的根源。namespace:foodotaskbar::environmentdoputs'RUNNING'endend当在控制台中执行rakefoo:bar时,输出为:RUNNINGRUNNING当我执行任何rake任务时会发生这种情况。有没有人遇到过这样的事情?编辑上面的rake任务就是写在那个.rake文件中的所有内容。这是当前正在使用的Rakefile。requireFile.expand_path('../config/application',__FILE__)OurApp::Application.load_tasks这里
我遇到了一个非常奇怪的问题,我很难解决。在我看来,我有一个与data-remote="true"和data-method="delete"的链接。当我单击该链接时,我可以看到对我的Rails服务器的DELETE请求。返回的JS代码会更改此链接的属性,其中包括href和data-method。再次单击此链接后,我的服务器收到了对新href的请求,但使用的是旧的data-method,即使我已将其从DELETE到POST(它仍然发送一个DELETE请求)。但是,如果我刷新页面,HTML与"new"HTML相同(随返回的JS发生变化),但它实际上发送了正确的请求类型。这就是这个问题令我困惑的
我以前没有使用过cron,所以我不能确定我这样做是对的。我想要自动化的任务似乎没有运行。我在终端中执行了这些步骤:sudogeminstall每当切换到应用程序目录无论何时。(这创建了文件schedule.rb)我将此代码添加到schedule.rb:every10.minutesdorunner"User.vote",environment=>"development"endevery:hourdorunner"Digest.rss",:environment=>"development"end我将此代码添加到deploy.rb:after"deploy:symlink","depl
如何在Rake任务中运行Capybara功能?例如:访问('http://google.com')谢谢! 最佳答案 在任务中尝试这样的事情:require'capybara'require'capybara/dsl'Capybara.current_driver=:seleniumBrowser=Class.new{includeCapybara::DSL}page=Browser.new.pagepage.visit("http://www.google.com")puts(page.html)
我正在根据Rakefile中的现有测试文件动态生成测试任务。假设您有各种以模式命名的单元测试文件test_.rb.所以我正在做的是创建一个以“测试”命名空间内的文件名命名的任务。使用下面的代码,我可以用raketest:调用所有测试require'rake/testtask'task:default=>'test:all'namespace:testdodesc"Runalltests"Rake::TestTask.new(:all)do|t|t.test_files=FileList['test_*.rb']endFileList['test_*.rb'].eachdo|task|n
我有这个:AccountSummary我想单击该链接,但在使用link_to时出现错误。我试过:bot.click(page.link_with(:href=>/menu_home/))bot.click(page.link_with(:class=>'top_level_active'))bot.click(page.link_with(:href=>/AccountSummary/))我得到的错误是:NoMethodError:nil:NilClass的未定义方法“[]” 最佳答案 那是一个javascript链接。Mechan
根据thispostbyStephenHagemann,我正在尝试为我的一个rake任务编写Rspec测试.lib/tasks/retry.rake:namespace:retrydotask:message,[:message_id]=>[:environment]do|t,args|TextMessage.new.resend!(args[:message_id])endendspec/tasks/retry_spec.rb:require'rails_helper'require'rake'describe'retrynamespaceraketask'dodescribe're
我看到有关未找到文件min.map的错误消息:GETjQuery'sjquery-1.10.2.min.mapistriggeringa404(NotFound)截图这是从哪里来的? 最佳答案 如果ChromeDevTools报告.map文件的404(可能是jquery-1.10.2.min.map、jquery.min.map或jquery-2.0.3.min.map,但任何事情都可能发生)首先要知道的是,这仅在使用DevTools时才会请求。您的用户不会遇到此404。现在您可以修复此问题或禁用sourcemap功能。修复:获取文