diff --git a/setup/start.sh b/setup/start.sh index 23d4e33d0..7ff218d74 100755 --- a/setup/start.sh +++ b/setup/start.sh @@ -45,8 +45,7 @@ mkdir -p "${APPS_DATA_DIR}" # keep these in sync with paths.js log "Ensuring directories" -# clear out graphite, since old installations are having some db migration issue -rm -rf "${PLATFORM_DATA_DIR}/graphite" && mkdir -p "${PLATFORM_DATA_DIR}/graphite" +mkdir -p "${PLATFORM_DATA_DIR}/graphite" mkdir -p "${PLATFORM_DATA_DIR}/mysql" mkdir -p "${PLATFORM_DATA_DIR}/postgresql" mkdir -p "${PLATFORM_DATA_DIR}/mongodb" diff --git a/src/graphite.js b/src/graphite.js deleted file mode 100644 index 08add8c53..000000000 --- a/src/graphite.js +++ /dev/null @@ -1,49 +0,0 @@ -'use strict'; - -exports = module.exports = { - start, - - DEFAULT_MEMORY_LIMIT: 256 * 1024 * 1024 -}; - -var assert = require('assert'), - async = require('async'), - infra = require('./infra_version.js'), - paths = require('./paths.js'), - shell = require('./shell.js'), - system = require('./system.js'); - -function start(existingInfra, serviceConfig, callback) { - assert.strictEqual(typeof existingInfra, 'object'); - assert.strictEqual(typeof serviceConfig, 'object'); - assert.strictEqual(typeof callback, 'function'); - - const tag = infra.images.graphite.tag; - const memoryLimit = serviceConfig.memoryLimit || exports.DEFAULT_MEMORY_LIMIT; - const memory = system.getMemoryAllocation(memoryLimit); - - const cmd = `docker run --restart=always -d --name="graphite" \ - --hostname graphite \ - --net cloudron \ - --net-alias graphite \ - --log-driver syslog \ - --log-opt syslog-address=udp://127.0.0.1:2514 \ - --log-opt syslog-format=rfc5424 \ - --log-opt tag=graphite \ - -m ${memory} \ - --memory-swap ${memoryLimit} \ - --dns 172.18.0.1 \ - --dns-search=. \ - -p 127.0.0.1:2003:2003 \ - -p 127.0.0.1:2004:2004 \ - -p 127.0.0.1:8417:8000 \ - -v "${paths.PLATFORM_DATA_DIR}/graphite:/var/lib/graphite" \ - --label isCloudronManaged=true \ - --read-only -v /tmp -v /run "${tag}"`; - - async.series([ - shell.exec.bind(null, 'stopGraphite', 'docker stop graphite || true'), - shell.exec.bind(null, 'removeGraphite', 'docker rm -f graphite || true'), - shell.exec.bind(null, 'startGraphite', cmd) - ], callback); -} diff --git a/src/infra_version.js b/src/infra_version.js index 6e19dc513..2adeceb7d 100644 --- a/src/infra_version.js +++ b/src/infra_version.js @@ -21,7 +21,7 @@ exports = module.exports = { 'mongodb': { repo: 'cloudron/mongodb', tag: 'cloudron/mongodb:4.0.2@sha256:9df297ccc3370f38c54f8d614e214e082b363777cd1c6c9522e29663cc8f5362' }, 'redis': { repo: 'cloudron/redis', tag: 'cloudron/redis:3.0.3@sha256:37e5222e01ae89bc5a742ce12030631de25a127b5deec8a0e992c68df0fdec10' }, 'mail': { repo: 'cloudron/mail', tag: 'cloudron/mail:3.3.0@sha256:c2366d009c649946f8d7d6346a0bcbbce49d8e4d7b9360a8004a5ca64707ee74' }, - 'graphite': { repo: 'cloudron/graphite', tag: 'cloudron/graphite:2.4.1@sha256:b00b64b8df4032985d7a1ddd548a2713b6d7d88a54ebe9b7d324cece2bd6829e' }, + 'graphite': { repo: 'cloudron/graphite', tag: 'cloudron/graphite:3.0.0@sha256:b00b64b8df4032985d7a1ddd548a2713b6d7d88a54ebe9b7d324cece2bd6829e' }, 'sftp': { repo: 'cloudron/sftp', tag: 'cloudron/sftp:3.2.0@sha256:61e8247ded1e07cf882ca478dab180960357c614472e80b938f1f690a46788c2' } } }; diff --git a/src/scripts/rmaddondir.sh b/src/scripts/rmaddondir.sh index 0c0e7398c..ad961fc53 100755 --- a/src/scripts/rmaddondir.sh +++ b/src/scripts/rmaddondir.sh @@ -19,13 +19,17 @@ fi addon="$1" appid="${2:-}" # only valid for redis -if [[ "${addon}" != "postgresql" && "${addon}" != "mysql" && "${addon}" != "mongodb" && "${addon}" != "redis" ]]; then - echo "${addon} must be postgresql/mysql/mongodb/redis" +if [[ "${addon}" != "postgresql" && "${addon}" != "mysql" && "${addon}" != "mongodb" && "${addon}" != "redis" && "${addon}" != "graphite" ]]; then + echo "${addon} must be postgresql/mysql/mongodb/redis/graphite" exit 1 fi if [[ "${BOX_ENV}" == "cloudron" ]]; then - readonly addon_dir="${HOME}/platformdata/${addon}/${appid}" + if [[ "${addon}" == "graphite" ]]; then + readonly addon_dir="${HOME}/platformdata/graphite" + else + readonly addon_dir="${HOME}/platformdata/${addon}/${appid}" + fi else readonly addon_dir="${HOME}/.cloudron_test/platformdata/${addon}/${appid}" fi diff --git a/src/services.js b/src/services.js index c162ce1f8..647a70132 100644 --- a/src/services.js +++ b/src/services.js @@ -41,7 +41,6 @@ var appdb = require('./appdb.js'), debug = require('debug')('box:services'), docker = require('./docker.js'), fs = require('fs'), - graphite = require('./graphite.js'), hat = require('./hat.js'), infra = require('./infra_version.js'), mail = require('./mail.js'), @@ -220,7 +219,7 @@ const SERVICES = { graphite: { status: statusGraphite, restart: docker.restartContainer.bind(null, 'graphite'), - defaultMemoryLimit: graphite.DEFAULT_MEMORY_LIMIT + defaultMemoryLimit: 256 * 1024 * 1024 }, nginx: { status: statusNginx, @@ -541,7 +540,7 @@ function rebuildService(id, callback) { if (id === 'postgresql') return startPostgresql({ version: 'none' }, callback); if (id === 'mysql') return startMysql({ version: 'none' }, callback); if (id === 'sftp') return sftp.rebuild(serviceConfig, { /* options */ }, callback); - if (id === 'graphite') return graphite.start({ version: 'none' }, serviceConfig, callback); + if (id === 'graphite') return startGraphite({ version: 'none' }, serviceConfig, callback); // nothing to rebuild for now. // TODO: mongo/postgresql/mysql need to be scaled down. @@ -845,7 +844,7 @@ function startServices(existingInfra, callback) { startPostgresql.bind(null, existingInfra), startMongodb.bind(null, existingInfra), startRedis.bind(null, existingInfra), - graphite.start.bind(null, existingInfra, servicesConfig['graphite'] || {}), + startGraphite.bind(null, existingInfra, servicesConfig['graphite'] || {}), sftp.start.bind(null, existingInfra, servicesConfig['sftp'] || {}), ); } else { @@ -857,7 +856,7 @@ function startServices(existingInfra, callback) { if (infra.images.postgresql.tag !== existingInfra.images.postgresql.tag) startFuncs.push(startPostgresql.bind(null, existingInfra)); if (infra.images.mongodb.tag !== existingInfra.images.mongodb.tag) startFuncs.push(startMongodb.bind(null, existingInfra)); if (infra.images.redis.tag !== existingInfra.images.redis.tag) startFuncs.push(startRedis.bind(null, existingInfra)); - if (infra.images.graphite.tag !== existingInfra.images.graphite.tag) startFuncs.push(graphite.start.bind(null, existingInfra, servicesConfig['graphite'] || {})); + if (infra.images.graphite.tag !== existingInfra.images.graphite.tag) startFuncs.push(startGraphite.bind(null, existingInfra, servicesConfig['graphite'] || {})); if (infra.images.sftp.tag !== existingInfra.images.sftp.tag) startFuncs.push(sftp.start.bind(null, existingInfra, servicesConfig['sftp'] || {})); debug('startServices: existing infra. incremental service create %j', startFuncs.map(function (f) { return f.name; })); @@ -1785,6 +1784,49 @@ function restoreMongoDb(app, options, callback) { }); } +function startGraphite(existingInfra, serviceConfig, callback) { + assert.strictEqual(typeof existingInfra, 'object'); + assert.strictEqual(typeof serviceConfig, 'object'); + assert.strictEqual(typeof callback, 'function'); + + const tag = infra.images.graphite.tag; + const memoryLimit = serviceConfig.memoryLimit || 256 * 1024 * 1024; + const memory = system.getMemoryAllocation(memoryLimit); + + const upgrading = existingInfra.version !== 'none' && requiresUpgrade(existingInfra.images.graphite.tag, tag); + + if (upgrading) debug('startGraphite: graphite will be upgraded'); + + const cmd = `docker run --restart=always -d --name="graphite" \ + --hostname graphite \ + --net cloudron \ + --net-alias graphite \ + --log-driver syslog \ + --log-opt syslog-address=udp://127.0.0.1:2514 \ + --log-opt syslog-format=rfc5424 \ + --log-opt tag=graphite \ + -m ${memory} \ + --memory-swap ${memoryLimit} \ + --dns 172.18.0.1 \ + --dns-search=. \ + -p 127.0.0.1:2003:2003 \ + -p 127.0.0.1:2004:2004 \ + -p 127.0.0.1:8417:8000 \ + -v "${paths.PLATFORM_DATA_DIR}/graphite:/var/lib/graphite" \ + --label isCloudronManaged=true \ + --read-only -v /tmp -v /run "${tag}"`; + + async.series([ + shell.exec.bind(null, 'stopGraphite', 'docker stop graphite || true'), + shell.exec.bind(null, 'removeGraphite', 'docker rm -f graphite || true'), + (done) => { + if (!upgrading) return done(); + shell.sudo('removeGraphiteDir', [ RMADDONDIR_CMD, 'graphite' ], {}, done); + }, + shell.exec.bind(null, 'startGraphite', cmd) + ], callback); +} + function setupProxyAuth(app, options, callback) { assert.strictEqual(typeof app, 'object'); assert.strictEqual(typeof options, 'object');