fix log_path

This commit is contained in:
les 2021-06-04 15:36:03 +02:00
parent 27c5185c35
commit 3b041df157
No known key found for this signature in database
GPG key ID: 352918250B012177

View file

@ -12,6 +12,7 @@ const mkdirp = require('mkdirp')
const url = require('url') const url = require('url')
const cwd = process.cwd() const cwd = process.cwd()
const data_path = process.env.GANCIO_DATA || path.resolve('./')
// needed by nuxt // needed by nuxt
process.chdir(path.resolve(__dirname, '..')) process.chdir(path.resolve(__dirname, '..'))
@ -66,7 +67,7 @@ async function setupQuestionnaire (is_docker, db) {
questions.push({ questions.push({
name: 'db.storage', name: 'db.storage',
message: 'sqlite db path', message: 'sqlite db path',
default: './db.sqlite', default: path.resolve(data_path, 'db.sqlite'),
filter: p => path.resolve(cwd, p), filter: p => path.resolve(cwd, p),
when: answers => answers.db.dialect === 'sqlite', when: answers => answers.db.dialect === 'sqlite',
validate: db_path => validate: db_path =>
@ -142,7 +143,14 @@ async function setupQuestionnaire (is_docker, db) {
return true return true
} }
}) })
questions.push({
name: 'log_path',
message: 'Log path',
default: path.resolve(data_path, 'logs')
})
} }
questions.push({ questions.push({
name: 'admin.email', name: 'admin.email',
message: 'Admin email', message: 'Admin email',
@ -162,12 +170,6 @@ async function setupQuestionnaire (is_docker, db) {
validate: notEmpty validate: notEmpty
}) })
questions.push({
name: 'log_path',
message: 'Log path',
default: '/opt/gancio/logs'
})
questions.push({ questions.push({
name: 'smtp_type', name: 'smtp_type',
message: 'How should we send the emails ?', message: 'How should we send the emails ?',
@ -233,11 +235,11 @@ async function setupQuestionnaire (is_docker, db) {
const answers = await inquirer.prompt(questions) const answers = await inquirer.prompt(questions)
if (is_docker) { if (is_docker) {
answers.server = { host: '0.0.0.0', port: 13120 } answers.server = { host: '0.0.0.0', port: 13120 }
answers.upload_path = '/opt/gancio/uploads' answers.upload_path = path.resolve(data_path, 'uploads')
answers.log_level = 'debug' answers.log_level = 'debug'
answers.log_path = '/opt/gancio/logs' answers.log_path = path.resolve(data_path, 'logs')
if (db === 'sqlite') { if (db === 'sqlite') {
answers.db = { dialect: db, storage: '/opt/gancio/db.sqlite' } answers.db = { dialect: db, storage: path.resolve(data_path, 'db.sqlite') }
} else { } else {
answers.db = { answers.db = {
dialect: db, dialect: db,
@ -255,24 +257,29 @@ async function setupQuestionnaire (is_docker, db) {
async function run_migrations (db_conf) { async function run_migrations (db_conf) {
const Umzug = require('umzug') const Umzug = require('umzug')
const Sequelize = require('sequelize') const Sequelize = require('sequelize')
const db = new Sequelize(db_conf) try {
const umzug = new Umzug({ const db = new Sequelize(db_conf)
storage: 'sequelize', const umzug = new Umzug({
storageOptions: { sequelize: db }, storage: 'sequelize',
logging: consola.info, storageOptions: { sequelize: db },
migrations: { logging: consola.info,
wrap: fun => { migrations: {
return () => wrap: fun => {
fun(db.queryInterface, Sequelize).catch(e => { return () =>
consola.error(e) fun(db.queryInterface, Sequelize).catch(e => {
return false consola.error(e)
}) return false
}, })
path: path.resolve(__dirname, 'migrations') },
} path: path.resolve(__dirname, 'migrations')
}) }
await umzug.up() })
return db.close() await umzug.up()
return db.close()
} catch (e) {
consola.warn(` ⚠️ Cannot connect to db, check your configuration => ${e}`)
process.exit(-1)
}
} }
async function start (options) { async function start (options) {
@ -304,7 +311,7 @@ async function setup (options) {
process.exit(-1) process.exit(-1)
} }
if (options.docker) { if (options.docker) {
consola.info('You can edit ./config.json to modify your configuration.') consola.info('You can edit ./data/config.json to modify your configuration.')
consola.info('Start the server with "docker-compose up"') consola.info('Start the server with "docker-compose up"')
} else { } else {
consola.info( consola.info(
@ -331,7 +338,7 @@ require('yargs')
.option('config', { .option('config', {
alias: 'c', alias: 'c',
describe: 'Configuration file', describe: 'Configuration file',
default: '/opt/gancio/config.json' default: path.resolve(data_path, 'config.json')
}) })
.coerce('config', config_path => { .coerce('config', config_path => {
const absolute_config_path = path.resolve(cwd, config_path) const absolute_config_path = path.resolve(cwd, config_path)