mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-13 22:41:32 -05:00
Merge pull request #4738 from jaswilli/socket-perms
Allow socket permissions to be set from config
This commit is contained in:
commit
3310dba9ea
3 changed files with 54 additions and 12 deletions
|
@ -41,11 +41,29 @@ function ConfigManager(config) {
|
||||||
|
|
||||||
// Are we using sockets? Custom socket or the default?
|
// Are we using sockets? Custom socket or the default?
|
||||||
ConfigManager.prototype.getSocket = function () {
|
ConfigManager.prototype.getSocket = function () {
|
||||||
|
var socketConfig,
|
||||||
|
values = {
|
||||||
|
path: path.join(this._config.paths.contentPath, process.env.NODE_ENV + '.socket'),
|
||||||
|
permissions: '660'
|
||||||
|
};
|
||||||
|
|
||||||
if (this._config.server.hasOwnProperty('socket')) {
|
if (this._config.server.hasOwnProperty('socket')) {
|
||||||
return _.isString(this._config.server.socket) ?
|
socketConfig = this._config.server.socket;
|
||||||
this._config.server.socket :
|
|
||||||
path.join(this._config.paths.contentPath, process.env.NODE_ENV + '.socket');
|
if (_.isString(socketConfig)) {
|
||||||
|
values.path = socketConfig;
|
||||||
|
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_.isObject(socketConfig)) {
|
||||||
|
values.path = socketConfig.path || values.path;
|
||||||
|
values.permissions = socketConfig.permissions || values.permissions;
|
||||||
|
|
||||||
|
return values;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -124,19 +124,19 @@ GhostServer.prototype.start = function (externalApp) {
|
||||||
|
|
||||||
// ## Start Ghost App
|
// ## Start Ghost App
|
||||||
return new Promise(function (resolve) {
|
return new Promise(function (resolve) {
|
||||||
if (config.getSocket()) {
|
var socketConfig = config.getSocket();
|
||||||
|
|
||||||
|
if (socketConfig) {
|
||||||
// Make sure the socket is gone before trying to create another
|
// Make sure the socket is gone before trying to create another
|
||||||
try {
|
try {
|
||||||
fs.unlinkSync(config.getSocket());
|
fs.unlinkSync(socketConfig.path);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// We can ignore this.
|
// We can ignore this.
|
||||||
}
|
}
|
||||||
|
|
||||||
self.httpServer = rootApp.listen(
|
self.httpServer = rootApp.listen(socketConfig.path);
|
||||||
config.getSocket()
|
|
||||||
);
|
|
||||||
|
|
||||||
fs.chmod(config.getSocket(), '0660');
|
fs.chmod(socketConfig.path, socketConfig.permissions);
|
||||||
} else {
|
} else {
|
||||||
self.httpServer = rootApp.listen(
|
self.httpServer = rootApp.listen(
|
||||||
config.server.port,
|
config.server.port,
|
||||||
|
|
|
@ -519,9 +519,33 @@ describe('Config', function () {
|
||||||
it('allows server to use a socket', function (done) {
|
it('allows server to use a socket', function (done) {
|
||||||
overrideConfig({server: {socket: 'test'}});
|
overrideConfig({server: {socket: 'test'}});
|
||||||
|
|
||||||
config.load().then(function (localConfig) {
|
config.load().then(function () {
|
||||||
should.exist(localConfig);
|
var socketConfig = config.getSocket();
|
||||||
localConfig.server.socket.should.equal('test');
|
|
||||||
|
socketConfig.should.be.an.Object;
|
||||||
|
socketConfig.path.should.equal('test');
|
||||||
|
socketConfig.permissions.should.equal('660');
|
||||||
|
|
||||||
|
done();
|
||||||
|
}).catch(done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('allows server to use a socket and user-defined permissions', function (done) {
|
||||||
|
overrideConfig({
|
||||||
|
server: {
|
||||||
|
socket: {
|
||||||
|
path: 'test',
|
||||||
|
permissions: '666'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
config.load().then(function () {
|
||||||
|
var socketConfig = config.getSocket();
|
||||||
|
|
||||||
|
socketConfig.should.be.an.Object;
|
||||||
|
socketConfig.path.should.equal('test');
|
||||||
|
socketConfig.permissions.should.equal('666');
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).catch(done);
|
}).catch(done);
|
||||||
|
|
Loading…
Reference in a new issue