From dc779da2b51778c401fea2e0d098bc66ae567169 Mon Sep 17 00:00:00 2001 From: James Allen Date: Sat, 22 Feb 2014 15:02:21 +0000 Subject: [PATCH] Add in check for S3 credentials --- server-ce/Gruntfile.coffee | 47 +++++++++++++++++++++++++++++++++++--- server-ce/README.md | 2 +- server-ce/package.json | 6 +++-- 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/server-ce/Gruntfile.coffee b/server-ce/Gruntfile.coffee index 32993f3f39..90208723f3 100644 --- a/server-ce/Gruntfile.coffee +++ b/server-ce/Gruntfile.coffee @@ -4,6 +4,8 @@ exec = require("child_process").exec rimraf = require "rimraf" Path = require "path" semver = require "semver" +settings = require "settings-sharelatex" +knox = require "knox" SERVICES = [{ name: "web" @@ -89,7 +91,9 @@ module.exports = (grunt) -> Helpers.checkRedis @async() grunt.registerTask "check:latexmk", "Check that latexmk is installed", () -> Helpers.checkLatexmk @async() - grunt.registerTask "check", "Check that you have the required dependencies installed", ["check:redis", "check:latexmk"] + grunt.registerTask "check:s3", "Check that Amazon S3 credentials are configured", () -> + Helpers.checkS3 @async() + grunt.registerTask "check", "Check that you have the required dependencies installed", ["check:redis", "check:latexmk", "check:s3"] Helpers = installService: (repo_src, dir, callback = (error) ->) -> @@ -141,7 +145,7 @@ module.exports = (grunt) -> exec "redis-cli info", (error, stdout, stderr) -> if error? and error.message.match("Could not connect") grunt.log.error "FAIL. Redis is not running" - return + return callback(error) else if error? return callback(error) else @@ -149,6 +153,7 @@ module.exports = (grunt) -> if !m? grunt.log.error "FAIL." grunt.log.error "Unknown redis version" + error = new Error("Unknown redis version") else version = m[1] if semver.gt(version, "2.6.0") @@ -157,7 +162,8 @@ module.exports = (grunt) -> else grunt.log.error "FAIL." grunt.log.error "Redis version is too old (#{version}). Must be 2.6.0 or greater." - callback() + error = new Error("Redis version is too old (#{version}). Must be 2.6.0 or greater.") + callback(error) checkLatexmk: (callback = (error) ->) -> grunt.log.write "Checking latexmk is installed... " @@ -170,6 +176,7 @@ module.exports = (grunt) -> latexmk comes with TexLive 2013, and must be a version from 2013 or later. This is a not a fatal error, but compiling will not work without latexmk """ + return callback(error) else if error? return callback(error) else @@ -177,6 +184,7 @@ module.exports = (grunt) -> if !m? grunt.log.error "FAIL." grunt.log.error "Unknown latexmk version" + error = new Error("Unknown latexmk version") else version = m[1] if semver.gte(version + ".0", "4.39.0") @@ -188,6 +196,39 @@ module.exports = (grunt) -> latexmk version is too old (#{version}). Must be 4.39 or greater. This is a not a fatal error, but compiling will not work without latexmk """ + error = new Error("latexmk is too old") + callback(error) + + checkS3: (callback = (error) ->) -> + grunt.log.write "Checking S3 credentials... " + try + client = knox.createClient({ + key: settings.s3.key + secret: settings.s3.secret + bucket: settings.s3.buckets.user_files + }) + catch e + grunt.log.error "FAIL." + grunt.log.errorlns """ + Please configure you Amazon S3 credentials in config/settings.development.coffee + + Amazon S3 (Simple Storage Service) is a cloud storage service provided by + Amazon. ShareLaTeX uses S3 for storing binary files like images. You can + sign up for an account and find out more at: + + http://aws.amazon.com/s3/ + + """ + return callback() + + client.getFile "does-not-exist", (error, response) -> + unless response? and response.statusCode == 404 + grunt.log.error "FAIL." + grunt.log.errorlns """ + Could not connect to Amazon S3. Please check your credentials. + """ + else + grunt.log.write "OK." callback() diff --git a/server-ce/README.md b/server-ce/README.md index 251b9f6260..0f47ece3bb 100644 --- a/server-ce/README.md +++ b/server-ce/README.md @@ -26,7 +26,7 @@ Next install all the node modules and ShareLaTeX services: Now check that your system is set up correctly to run ShareLaTeX (checks that you have the required dependencies installed.) Watch out for any failures. - $ grunt check + $ grunt check --force When that has finished, run ShareLaTeX with diff --git a/server-ce/package.json b/server-ce/package.json index 6b75122473..383fa5951f 100644 --- a/server-ce/package.json +++ b/server-ce/package.json @@ -2,7 +2,8 @@ "name": "sharelatex", "description": "An online collaborative LaTeX editor", "dependencies": { - "rimraf": "~2.2.6" + "rimraf": "~2.2.6", + "settings-sharelatex": "git+https://github.com/sharelatex/settings-sharelatex.git" }, "devDependencies": { "grunt": "~0.4.2", @@ -11,6 +12,7 @@ "grunt-execute": "~0.1.5", "grunt-available-tasks": "~0.4.1", "grunt-concurrent": "~0.4.3", - "semver": "~2.2.1" + "semver": "~2.2.1", + "knox": "~0.8.9" } }