diff --git a/src/scripts/update.sh b/src/scripts/update.sh index 0f6c70fd9..6cd4d8637 100755 --- a/src/scripts/update.sh +++ b/src/scripts/update.sh @@ -14,8 +14,8 @@ if [[ $# == 1 && "$1" == "--check" ]]; then exit 0 fi -if [[ $# != 1 ]]; then - echo "sourceDir argument required" +if [[ $# != 2 ]]; then + echo "Usage: update.sh arguments required" exit 1 fi @@ -24,19 +24,17 @@ function log() { } readonly source_dir="${1}" +readonly log_file="${2}" + readonly installer_path="${source_dir}/scripts/installer.sh" +readonly ubuntu_version=$(lsb_release -rs) log "updating Cloudron with ${source_dir}" -systemctl reset-failed "${updater_service}" 2>/dev/null || true - # StandardError will follow StandardOutput in default inherit mode. https://www.freedesktop.org/software/systemd/man/systemd.exec.html -readonly DATETIME=`date '+%Y-%m-%d_%H-%M-%S'` -readonly LOG_FILE="/home/yellowtent/platformdata/logs/updater/cloudron-updater-${DATETIME}.log" - -log "starting service ${updater_service}. see logs at ${LOG_FILE}" - -if ! systemd-run --property=OOMScoreAdjust=-1000 --unit "${updater_service}" -p StandardOutput=file:${LOG_FILE} ${installer_path}; then +systemctl reset-failed "${updater_service}" 2>/dev/null || true +[[ "${ubuntu_version}" == "18.04" ]] && file_mode="file" || file_mode="append" +if ! systemd-run --property=OOMScoreAdjust=-1000 --unit "${updater_service}" -p StandardOutput=${file_mode}:${log_file} ${installer_path}; then log "Failed to install cloudron" exit 1 fi diff --git a/src/taskworker.js b/src/taskworker.js index 46c9ccf50..648d2bf20 100755 --- a/src/taskworker.js +++ b/src/taskworker.js @@ -53,6 +53,7 @@ async function setupLogging() { const callback = typeof args[args.length-1] === 'function' ? args.pop() : function () {}; // callback is required for fs.write fs.write.apply(fs, [logFd, ...args, callback]); }; + process.stdout.logFile = logFile; // used by update task } // this is also used as the 'uncaughtException' handler which can only have synchronous functions diff --git a/src/updater.js b/src/updater.js index 8cb9f00aa..f3032915f 100644 --- a/src/updater.js +++ b/src/updater.js @@ -155,8 +155,7 @@ async function update(boxUpdateInfo, options, progressCallback) { progressCallback({ percent: 70, message: 'Installing update' }); - // run installer.sh from new box code as a separate service - await shell.promises.sudo('update', [ UPDATE_CMD, packageInfo.file ], {}); + await shell.promises.sudo('update', [ UPDATE_CMD, packageInfo.file, process.stdout.logFile ], {}); // run installer.sh from new box code as a separate service // Do not add any code here. The installer script will stop the box code any instant }