fst – Rev 1

Subversion Repositories:
Rev:
#!/usr/bin/env node

const os = require('os')
const dns = require('dns')
const SyncData = require('./SyncData.js')
const path = require('path');
const YAML = require('yamljs');
const net = require('net');

// Load configuration file.
const config = YAML.load(
    path.join(
        path.dirname(
            require.main.filename
        ),
        'config.yml'
    )
)

// Get command line arguments.
const args = process.argv.splice(process.execArgv.length + 2);

// Get the hostname and send the sync message to the distributor.
dns.lookup(os.hostname(), { hints: dns.ADDRCONFIG }, function (error, ip) {
    dns.lookupService(ip, 0, function (error, hostname, service) {
        if (error) {
            console.log('unable to determine local hostname');
            return;
        }

        // Create sync message.
        var syncMessage;
        try {
            syncMessage = new SyncData(hostname, args[0], args[1], args[2], args[3], args[4])
        }
        catch (error) {
            console.log('invalid arguments')
            return
        }

        // Connect to socket and write the payload.
        const stream = net.createConnection({ path: config.distribution.socket }, function () {
            stream.write(JSON.stringify(syncMessage))
            stream.end()
        }).on('error', function (error) {
            console.log('could not write to distribution socket, is the distribution server running?')
        })
    });
});

Generated by GNU Enscript 1.6.5.90.