针对Travis CI start some services by default运行的机器实例对my project无效。因此我想停止这些服务。我的第一个想法是在 .travis.yml 中使用以下块来执行此操作:
before_script:
# Disable services enabled by default
- sudo service mysql stop
- sudo service postgresql stop
但是,对于另一台机器,成功,失败:
$ sudo service mysql stop
mysql stop/waiting
$ sudo service postgresql stop
* Stopping PostgreSQL 9.1 database server
...done.
* Stopping PostgreSQL 9.2 database server
...done.
* Stopping PostgreSQL 9.3 database server
...done.
...
$ sudo service mysql stop
stop: Unknown instance:
The command "sudo service mysql stop" failed and exited with 1 during .
另一个选项是/etc/init.d/mysql stop
但是在通过service
命令启动进程的计算机上可能会失败。我可以在 .travis.yml 脚本中使用try-catch吗?
答案 0 :(得分:6)
事实证明,使用上面提到的/etc/init.d/ ...
更加可靠。有一些警告说应该使用sudo service ...
,但我没有成功。所以我现在正在运行:
language: android
jdk:
- oraclejdk7
- openjdk7
android:
components:
# All the build system components should be at the latest version
- tools
- platform-tools
- build-tools-21.1.1
- android-19
# The libraries we can't get from Maven Central or similar
- extra-android-support
notifications:
email: true
before_script:
# Disable services enabled by default
# http://docs.travis-ci.com/user/database-setup/#MySQL
- sudo /etc/init.d/mysql stop
- sudo /etc/init.d/postgresql stop
# The following did not work reliable
# - sudo service mysql stop
# - sudo service postgresql stop
# Ensure Gradle wrapper is executable
- chmod +x gradlew
# Ensure signing configuration is present
- mv app/gradle.properties.example app/gradle.properties
script:
- ./gradlew clean assembleDebug
答案 1 :(得分:0)
sudo service mysql stop
我正在使用带有mysql的laradock的travis。那个命令为我做了工作。