This repository has been archived by the owner on May 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cloudfiles-mirror
executable file
·97 lines (84 loc) · 2.7 KB
/
cloudfiles-mirror
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env node
var program = require('commander'),
_ = require("underscore"),
cluster = require('cluster'),
path = require("path"),
fs = require("fs"),
cli_path = path.join(__dirname, '..', 'lib', 'cloudfiles-mirror', 'cli.js'),
loadConfig,
config;
program
.version('0.1.7')
.option('-c, --config [value]', 'Configuration file', '.cloudfiles-mirror.json')
.option('-l --local [value]', 'Local directory to mirror', process.cwd())
.option('-r --remote [value]', "Remote container", path.basename(process.cwd()))
.option('-b --base [value]', "Remote base directory", "")
.option('-u --user [value]', "Rackspace username", "")
.option('-k --key [value]', "Rackspace API key", "")
.option('--cdn', "Enable CDN support when creating the container")
.option('-m --monitor', 'Enable monitor the local directory')
.option('-s --servicenet', 'Enable ServiceNet (unmetered, double throughput) Only within Rackpace servers')
.option('-w --workers <n>', 'Number of symultaneous parallel workers interacting with the Cloud Servers API', 20)
.option('--show_config', 'Show current configuration and exits')
.option('--sync_all', 'Pushes all local files on the first run.')
.option('-v --verbose', 'Verbose mode.')
.option('--tmp [value]', 'Working directory base path.', (process.env['TMPDIR'] || process.env['TMP'] || process.env['TEMP'] || '/tmp/'))
.parse(process.argv);
loadConfig = function () {
var defaults = {
localPath: program.local,
remoteBase: program.base,
container: program.remote,
auth: {
username: program.user,
apiKey: program.key
},
cdnEnabled: program.cdn || false,
monitor: program.monitor || false,
pushOnBoot: program.sync_all || false,
servicenet: program.servicenet || false,
verbose: program.verbose || false
},
config = {},
configFile = program.config;
if (configFile) {
try {
stats = fs.statSync(configFile),
config = JSON.parse(fs.readFileSync(configFile).toString());
} catch (e) { }
}
defaults.cache = {
cachePath: program.tmp
+ ".cache-cloudfiles-mirror"
+ ((config && config.auth && config.auth.username) || '')
};
config = _.defaults(config, defaults);
return config;
};
config = loadConfig();
if (program.show_config) {
console.log(config);
process.exit(0);
}
if (program.monitor) {
// Node 0.4.x
try {
var proc = cluster()
.set('workers', 1)
.use(cluster.reload(cli_path))
.start();
if (!proc.isWorker) {
return;
}
// Node 0.6.x
} catch (e) {
if (cluster.isMaster) {
cluster.fork();
cluster.on('death', function(worker) {
cluster.fork();
});
return;
}
}
}
(require(cli_path))(config);