How to stop services on Travis CI running by default?

ⅰ亾dé卋堺 提交于 2020-01-24 03:56:44

问题


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 .

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?


回答1:


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



回答2:


sudo service mysql stop

I am using travis with laradock with mysql. And that command did the work for me.



来源:https://stackoverflow.com/questions/27382295/how-to-stop-services-on-travis-ci-running-by-default

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!