diff --git a/src/scripts/update.sh b/src/scripts/update.sh index d5be3941e..0f6c70fd9 100755 --- a/src/scripts/update.sh +++ b/src/scripts/update.sh @@ -7,7 +7,7 @@ if [[ ${EUID} -ne 0 ]]; then exit 1 fi -readonly UPDATER_SERVICE="cloudron-updater" +readonly updater_service="cloudron-updater" if [[ $# == 1 && "$1" == "--check" ]]; then echo "OK" @@ -19,34 +19,35 @@ if [[ $# != 1 ]]; then exit 1 fi +function log() { + echo -e "$(date +'%Y-%m-%dT%H:%M:%S')" "==> update: $1" +} + readonly source_dir="${1}" - -echo "Updating Cloudron with ${source_dir}" - readonly installer_path="${source_dir}/scripts/installer.sh" -echo "=> reset service ${UPDATER_SERVICE} status (of previous update)" -systemctl reset-failed "${UPDATER_SERVICE}" 2>/dev/null || true +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 -echo "=> Run installer.sh as ${UPDATER_SERVICE}." readonly DATETIME=`date '+%Y-%m-%d_%H-%M-%S'` readonly LOG_FILE="/home/yellowtent/platformdata/logs/updater/cloudron-updater-${DATETIME}.log" -echo "=> starting service ${UPDATER_SERVICE}. see logs at ${LOG_FILE}" +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 - echo "Failed to install cloudron. See log for details" +if ! systemd-run --property=OOMScoreAdjust=-1000 --unit "${updater_service}" -p StandardOutput=file:${LOG_FILE} ${installer_path}; then + log "Failed to install cloudron" exit 1 fi while true; do - if systemctl is-failed "${UPDATER_SERVICE}" >/dev/null 2>&1; then - echo "=> ${UPDATER_SERVICE} has failed" + if systemctl is-failed "${updater_service}" >/dev/null 2>&1; then + log "${updater_service} failed" exit 1 fi - echo "${UPDATER_SERVICE} is still active. will check in 5 seconds" + log "${updater_service} is still active. will check in 5 seconds" sleep 5 # this loop will stop once the update process stopped the box unit and thus terminating this child process