fst – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | #!/usr/bin/env node |
2 | |||
3 | const os = require('os') |
||
4 | const dns = require('dns') |
||
5 | const SyncData = require('./SyncData.js') |
||
6 | const path = require('path'); |
||
7 | const YAML = require('yamljs'); |
||
8 | const net = require('net'); |
||
9 | |||
10 | // Load configuration file. |
||
11 | const config = YAML.load( |
||
12 | path.join( |
||
13 | path.dirname( |
||
14 | require.main.filename |
||
15 | ), |
||
16 | 'config.yml' |
||
17 | ) |
||
18 | ) |
||
19 | |||
20 | // Get command line arguments. |
||
21 | const args = process.argv.splice(process.execArgv.length + 2); |
||
22 | |||
23 | // Get the hostname and send the sync message to the distributor. |
||
24 | dns.lookup(os.hostname(), { hints: dns.ADDRCONFIG }, function (error, ip) { |
||
25 | dns.lookupService(ip, 0, function (error, hostname, service) { |
||
26 | if (error) { |
||
27 | console.log('unable to determine local hostname'); |
||
28 | return; |
||
29 | } |
||
30 | |||
31 | // Create sync message. |
||
32 | var syncMessage; |
||
33 | try { |
||
34 | syncMessage = new SyncData(hostname, args[0], args[1], args[2], args[3], args[4]) |
||
35 | } |
||
36 | catch (error) { |
||
37 | console.log('invalid arguments') |
||
38 | return |
||
39 | } |
||
40 | |||
41 | // Connect to socket and write the payload. |
||
42 | const stream = net.createConnection({ path: config.distribution.socket }, function () { |
||
43 | stream.write(JSON.stringify(syncMessage)) |
||
44 | stream.end() |
||
45 | }).on('error', function (error) { |
||
46 | console.log('could not write to distribution socket, is the distribution server running?') |
||
47 | }) |
||
48 | }); |
||
49 | }); |