Created
October 24, 2013 13:36
-
-
Save mikekunze/7137464 to your computer and use it in GitHub Desktop.
This coffee script is meant to be used with a docker container running drupal instances. It starts mysql, httpd, postfix, and waits for mysql to boot up before creating the drupal database.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
spawn = require('child_process').spawn | |
dohttpd = ()-> | |
httpd = spawn '/etc/init.d/apache2', ['start'] | |
httpd.stdout.setEncoding 'utf8' | |
httpd.stderr.setEncoding 'utf8' | |
httpd.stdout.on 'data', (data)-> | |
console.log data | |
httpd.stderr.on 'data', (data)-> | |
console.log data | |
domysql = ()-> | |
mysql = spawn '/usr/sbin/mysqld' | |
mysql.stdout.setEncoding 'utf8' | |
mysql.stderr.setEncoding 'utf8' | |
mysql.stdout.on 'data', (data)-> | |
console.log data | |
mysql.stderr.on 'data', (data)-> | |
console.log data | |
dopostfix = ()-> | |
postfix = spawn '/etc/init.d/postfix', ['start'] | |
postfix.stdout.setEncoding 'utf8' | |
postfix.stderr.setEncoding 'utf8' | |
postfix.stdout.on 'data', (data)-> | |
console.log data | |
postfix.stderr.on 'data', (data)-> | |
console.log data | |
# Here we are waiting on mysql | |
net = require 'net' | |
tryCount = 0 | |
checkMysqlPortAndDoCreateDb = ()-> | |
sock = new net.Socket() | |
sock.connect(3306, '127.0.0.1') | |
sock.on 'connect', ()-> | |
console.log 'connection to mysql succeeded, creating database' | |
docreatedb() | |
sock.destroy() | |
sock.on 'error', (e)-> | |
if tryCount > 10 | |
console.log 'giving up trying to create drupal table' | |
else | |
tryCount++ | |
setTimeout checkMysqlPortAndDoCreateDb, 350 | |
console.log e | |
sock.on 'timeout', (e)-> | |
console.log e | |
docreatedb = ()-> | |
createdb = spawn 'mysql', ['-uroot', '-e create database drupal'] | |
createdb.stdout.setEncoding 'utf8' | |
createdb.stderr.setEncoding 'utf8' | |
createdb.stdout.on 'data', (data)-> | |
console.log data | |
createdb.stderr.on 'data', (data)-> | |
console.log data | |
dohttpd() | |
domysql() | |
dopostfix() | |
checkMysqlPortAndDoCreateDb() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment