6

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?

JJD
  • 50,076
  • 60
  • 203
  • 339

2 Answers2

7

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
JJD
  • 50,076
  • 60
  • 203
  • 339
0

sudo service mysql stop

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

Player1
  • 2,878
  • 2
  • 26
  • 38