默认情况下如何停止Travis CI上运行的服务? [英] How to stop services on Travis CI running by default?

查看:146
本文介绍了默认情况下如何停止Travis CI上运行的服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为Travis CI运行的计算机实例默认情况下启动某些服务我的项目没有用.因此,我想停止这些服务.我的第一个想法是在我的 .travis.yml 中使用以下代码块:

The machine instances running for Travis CI start some services by default which are not useful to my project. Therefore I want to stop these services. My first idea was to use the following block in my .travis.yml to do so:

before_script:
  # Disable services enabled by default
  - sudo service mysql stop
  - sudo service postgresql stop

但是,对于一台计算机,这成功,而对于另一台计算机,失败:

However, this was successful for one and failed for another machine:

$ 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吗?

Another option is /etc/init.d/mysql stop but this could fail on a machine which started the process via the service command. Is there a try-catch I can use in the .travis.yml script?

推荐答案

事实证明,使用提到的/etc/init.d/ ...更为可靠.有一些警告说应该使用sudo service ...,但是我并没有成功.因此,这就是我现在正在运行的内容:

It turns out that using the mentioned /etc/init.d/ ... works more reliable. There are some warnings that one should use sudo service ... but I was not successful with those. So here is what I am running now:

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

这篇关于默认情况下如何停止Travis CI上运行的服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆