0

I have a openshift app with MySQL 5.5, PHP 5.4 and phpMyAdmin 4.0 I would like to convert this to be scalable.

So according to instructions by Shekhar Gulati on - https://www.openshift.com/forums/openshift/recreate-an-existing-app-so-it-is-scaleable#comment-30153 I took a snapshot of the old app.
Created a new scalable app with

$ rhc app create -s apiprod php-5.4 mysql-5.5 phpmyadmin-4

Since the old app had phpMyAdmin - and we cannot add phpmyadmin to a scalable app. So created the new app with just

$ rhc app create -s apiprod php-5.4 mysql-5.5 

Untarred the old snapshot, deleted the phpMyAdmin subdirectory from the old snapshot, tarred it up again, and tried restoring to the new scalable app - got the following error -

dev@ubuntusrv2:~$ rhc snapshot restore -a apiprod -f oldapp.tar.gz
Restoring from snapshot oldapp.tar.gz...
Removing old git repo: ~/git/apiprod.git/
Removing old data dir: ~/app-root/data/*
Restoring ~/git/apiprod.git and ~/app-root/data
Unable to restore mysql-5.5 because it appears there is no snapshot for that type
Activation status: success

RESULT:
Success

Now, this problem seems to be similar to the one experienced by Molokov on https://www.openshift.com/forums/openshift/recreate-an-existing-app-so-it-is-scaleable#comment-33240

Following the steps outlined by Molokov, I managed to restore my old app to the new scalable app without an error.

But mysqli::mysqli() seems to be having a problem connecting to the database -
command line access works all right -

[apiprod-domain.rhcloud.com behat]\> echo $OPENSHIFT_MYSQL_DB_HOST
53182ea2500446463d00002e-domain.rhcloud.com
[apiprod-domain.rhcloud.com behat]\> mysql -h 53182ea2500446463d00002e-domain.rhcloud.com -u test -p
(can log in all right)

ssh-ing back to oldapp shows an IP address instead of a hostname like on the new scalable app

[apiv1-domain.rhcloud.com 53101d1e5004465baa000282]\> echo $OPENSHIFT_MYSQL_DB_HOST
127.3.76.130

I am impressed by the ease with which things can be setup with Openshift Online and would like to use it for production.

This should be a fairly common use case - I would happy to know how I should proceed

Dharman
  • 30,962
  • 25
  • 85
  • 135
saraf
  • 530
  • 7
  • 22

1 Answers1

2

Creating a snapshot of a single gear application, and restoring to a scaled application is not supported, because of the way that the snapshots are created, and the fact that in a scaled application the db's etc go on their own gears. If you restore a snapshot of a non-scaled application to a non-scaled application, it does not currently know how to get the database onto the database gear. I believe the correct solution for this scenario would actually be to create a workflow on openshift that would facilitate a push button solution to migrating from a non-scaled to a scaled solution. Please make sure you vote on that feature here (https://www.openshift.com/content/conversion-of-non-scalable-app-to-scalable-one)

Also, here is a Knowledge Base article I just posted about it:https://www.openshift.com/kb/kb-e1092-user-is-not-able-to-restore-snapshot-of-non-scaled-application-to-scaled-application-or

  • Ok, thanks! What is the recommended procedure for migrating from a non-scaled app to a scaled app? – saraf Mar 06 '14 at 23:25
  • You would need to backup your data manually. mysqldump (or similar) for your databases, git holds your code, and then make sure you ssh into your gear and zip up anything in your app-root/data directory and download it. –  Mar 06 '14 at 23:46
  • Trying it manually as you suggested - created a new scalable app - pushed the code to the new app using git push -f, ran the script for creating an empty database and a script for populating the database with test data - still getting stuck when trying to connect to the database using mysqli! Should this be a new question? PHP Warning: mysqli::mysqli(): (HY000/2002): Connection timed out in /var/lib/openshift/53191b925973ca470a0001b7/app-root/runtime/repo/app/model/DbConnect.php on line 22 Failed to connect to MySQL: Connection timed out ... same code works ok on the single geared application – saraf Mar 07 '14 at 01:45
  • are you using the environment variables to connect? make sure you stop/start your gear, don't restart –  Mar 07 '14 at 01:49
  • function connect() { include_once dirname(__FILE__) . '/../Config.php'; // Connecting to mysql database $this->conn = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME); // Check for database connection error if (mysqli_connect_errno()) { //TODO: add proper error logging/exceptions error_log("Failed to connect to MySQL: " . mysqli_connect_error()); } return $this->conn; } – saraf Mar 07 '14 at 01:53
  • define('DB_USERNAME', 'test'); define('DB_PASSWORD', 'randompass'); define('DB_HOST', $_ENV['OPENSHIFT_MYSQL_DB_HOST']); define('DB_NAME', 'device_cloud'); – saraf Mar 07 '14 at 01:53
  • am creating a database named device_cloud using a sql script and adding a user named test from the ssh session – saraf Mar 07 '14 at 01:54
  • I did not know about stopping and starting the app instance manually - and now this http://stackoverflow.com/questions/22193021/openshift-app-cannot-see-logs-using-rhc-as-admin-collaborator crops up - rhc app stop -a prod Application 'prod' not found. – saraf Mar 07 '14 at 02:03
  • How do I stop and start an app from the web page, since rhc is giving me an app not found (although rhc apps shows it) – saraf Mar 07 '14 at 02:03
  • this would probably be related to the fact that in a scalable app mysql would be on a different gear - but I did add the test user with all privileges from "%" any host using the mysql command line client by sshing to the application. – saraf Mar 07 '14 at 02:13
  • 1
    Got it. Using the $_ENV['OPENSHIFT_MYSQL_DB_PORT'] is mandatory as a parameter when connecting using mysqli on a scalable app, whereas on a single gear app it is not necessary. – saraf Mar 07 '14 at 02:32
  • Yep, you got it! You have to use the port, since a scaled application has it's database on it's own gear, the port is non standard. –  Mar 07 '14 at 03:22
  • It is also recommended to use the default database & user that is created, the database will be the same as the name of your application, and you can use OPENSHIFT_APP_NAME to access it. –  Mar 07 '14 at 03:23
  • thanks for your prompt responses! also learnt that a namespace is necessary for using rhc with an app in another domain where I am a collaborator. – saraf Mar 07 '14 at 05:02