2016-10-31 14:54:48 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
set -eu -o pipefail
|
|
|
|
|
|
|
|
|
|
if [[ ${EUID} -ne 0 ]]; then
|
|
|
|
|
echo "This script should be run as root." > /dev/stderr
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2023-05-15 19:05:39 +02:00
|
|
|
readonly updater_service="cloudron-updater"
|
2016-10-31 14:54:48 +01:00
|
|
|
|
|
|
|
|
if [[ $# == 1 && "$1" == "--check" ]]; then
|
|
|
|
|
echo "OK"
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
2018-10-26 09:49:52 -07:00
|
|
|
if [[ $# != 1 ]]; then
|
|
|
|
|
echo "sourceDir argument required"
|
2016-10-31 14:54:48 +01:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2023-05-15 19:05:39 +02:00
|
|
|
function log() {
|
|
|
|
|
echo -e "$(date +'%Y-%m-%dT%H:%M:%S')" "==> update: $1"
|
|
|
|
|
}
|
2016-10-31 14:54:48 +01:00
|
|
|
|
2023-05-15 19:05:39 +02:00
|
|
|
readonly source_dir="${1}"
|
2018-08-01 15:38:40 -07:00
|
|
|
readonly installer_path="${source_dir}/scripts/installer.sh"
|
2016-12-23 18:28:18 -08:00
|
|
|
|
2023-05-15 19:05:39 +02:00
|
|
|
log "updating Cloudron with ${source_dir}"
|
|
|
|
|
|
|
|
|
|
systemctl reset-failed "${updater_service}" 2>/dev/null || true
|
2016-11-02 10:56:53 +01:00
|
|
|
|
2018-11-15 10:52:31 -08:00
|
|
|
# StandardError will follow StandardOutput in default inherit mode. https://www.freedesktop.org/software/systemd/man/systemd.exec.html
|
2022-11-02 21:22:42 +01:00
|
|
|
readonly DATETIME=`date '+%Y-%m-%d_%H-%M-%S'`
|
|
|
|
|
readonly LOG_FILE="/home/yellowtent/platformdata/logs/updater/cloudron-updater-${DATETIME}.log"
|
|
|
|
|
|
2023-05-15 19:05:39 +02:00
|
|
|
log "starting service ${updater_service}. see logs at ${LOG_FILE}"
|
2016-11-01 18:13:45 +01:00
|
|
|
|
2023-05-15 19:05:39 +02:00
|
|
|
if ! systemd-run --property=OOMScoreAdjust=-1000 --unit "${updater_service}" -p StandardOutput=file:${LOG_FILE} ${installer_path}; then
|
|
|
|
|
log "Failed to install cloudron"
|
2018-12-04 15:02:48 -08:00
|
|
|
exit 1
|
|
|
|
|
fi
|
2016-11-02 11:13:12 +01:00
|
|
|
|
|
|
|
|
while true; do
|
2023-05-15 19:05:39 +02:00
|
|
|
if systemctl is-failed "${updater_service}" >/dev/null 2>&1; then
|
|
|
|
|
log "${updater_service} failed"
|
2016-11-02 11:13:12 +01:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2023-05-15 19:05:39 +02:00
|
|
|
log "${updater_service} is still active. will check in 5 seconds"
|
2018-11-30 21:18:01 -08:00
|
|
|
|
2016-11-02 11:13:12 +01:00
|
|
|
sleep 5
|
|
|
|
|
# this loop will stop once the update process stopped the box unit and thus terminating this child process
|
|
|
|
|
done
|