use spawn instead of exec
authorTravis Webb <me@traviswebb.com>
Tue, 26 Aug 2014 20:30:23 +0000 (16:30 -0400)
committerTravis Webb <me@traviswebb.com>
Tue, 26 Aug 2014 20:30:23 +0000 (16:30 -0400)
scripts/lib/util/init_database.js

index 00b32fc..1fdb2eb 100644 (file)
@@ -35,19 +35,29 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */
         var schemaPath = path.join(path.dirname(spec.source), "440_schema.sql");
         winston.info("Building schema for database " + databaseName);
 
-        proc.spawn("psql -U " + creds.username + " -h " + creds.hostname + " --single-transaction -p " +
-          creds.port + " -d " + databaseName + " -f " + schemaPath, done);
+        var process = proc.spawn('psql', [
+          '-U', creds.username, '-h', creds.hostname, '--single-transaction', '-p',
+          creds.port, '-d', databaseName, '-f', schemaPath
+        ], { stdio: 'inherit' });
+        process.on('exit', done);
+        
       },
       populateData = function (done) {
         winston.info("Populating data for database " + databaseName + " from " + spec.source);
-        proc.spawn("psql -U " + creds.username + " -h " + creds.hostname + " --single-transaction -p " +
-          creds.port + " -d " + databaseName + " -f " + spec.source, done);
+        var process = proc.spawn('psql', [
+          '-U', creds.username, '-h', creds.hostname, '--single-transaction', '-p',
+          creds.port, '-d', databaseName, '-f', spec.source
+        ], { stdio: 'inherit'});
+        process.on('exit', done);
       },
       // use exec to restore the backup. The alternative, reading the backup file into a string to query
       // doesn't work because the backup file is binary.
       restoreBackup = function (done) {
-        proc.spawn("pg_restore -U " + creds.username + " -h " + creds.hostname + " -p " +
-          creds.port + " -d " + databaseName + " -j " + os.cpus().length + " " + spec.backup, function (err, res) {
+        var process = proc.spawn('pg_restore', [
+          '-U', creds.username, '-h', creds.hostname, '-p', creds.port, '-d', databaseName,
+          '-j', os.cpus().length, spec.backup
+        ], { stdio: 'inherit' });
+        process.on('exit', function (err, res) {
           if (err) {
             console.log("ignoring restore db error", err);
           }