如何从Maven exec插件启动/停止Rails应用程序?
问题描述:
我想从Maven exec插件启动一个Rails应用程序。我使用./script/rails server
启动服务器,使用kill -9 cat tmp/pids/server.pid
停止服务器。但是exec在服务器启动后不断等待。是否有可能在后台运行这样的shell命令而不是等待?有没有更好的方式来从Maven开始/停止rails应用程序?这里是我的pom.xml:如何从Maven exec插件启动/停止Rails应用程序?
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>start-rails-app</id>
<phase>pre-integration-test</phase>
<configuration>
<executable>script/rails</executable>
<workingDirectory>${rails.app.dir}</workingDirectory>
<arguments>
<argument>server</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
<execution>
<id>stop-rails-app</id>
<phase>post-integration-test</phase>
<configuration>
<executable>kill -9 `cat tmp/pids/server.pid`</executable>
<workingDirectory>${rails.app.dir}</workingDirectory>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
答
传递-d
参数来启动服务器作为后台进程:rails server -d
。
这里的rails server
命令的详细信息:
rails server -h
Usage: rails server [mongrel, thin, etc] [options]
-p, --port=port Runs Rails on the specified port.
Default: 3000
-b, --binding=ip Binds Rails to the specified ip.
Default: 0.0.0.0
-c, --config=file Use custom rackup configuration file
-d, --daemon Make server run as a Daemon.
-u, --debugger Enable ruby-debugging for the server.
-e, --environment=name Specifies the environment to run this server under (test/development/production).
Default: development
-P, --pid=pid Specifies the PID file.
Default: tmp/pids/server.pid
-h, --help Show this help message.