Skip to content

Commit 0efe2d9

Browse files
committed
Container user 'linuxgsm' crontab can be saved optionally
This should be transparent to users and requires no intervention if they do not wish to use a custom crontab. Current behavior is retained. To actually use the custom crontab, the user needs to set LGSM_SAVE_CRONTAB to true. If set to false, the container will function exactly as it functions now. This variable needs to be documented in the downstream (docker image) repository.
1 parent cc097bb commit 0efe2d9

5 files changed

Lines changed: 14 additions & 1 deletion

File tree

Dockerfile.ubuntu-2004

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ ENV UPDATE_CHECK=60
2929
ENV USER=linuxgsm
3030
ENV UID=1000
3131
ENV GID=1000
32+
ENV LGSM_SAVE_CRONTAB=false
3233

3334
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
3435

Dockerfile.ubuntu-2204

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ ENV UPDATE_CHECK=60
2929
ENV USER=linuxgsm
3030
ENV UID=1000
3131
ENV GID=1000
32+
ENV LGSM_SAVE_CRONTAB=false
3233

3334
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
3435

Dockerfile.ubuntu-2404

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ ENV UPDATE_CHECK=60
2929
ENV USER=linuxgsm
3030
ENV UID=1000
3131
ENV GID=1000
32+
ENV LGSM_SAVE_CRONTAB=false
3233

3334
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
3435

entrypoint-user.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ else
9191
./"${GAMESERVER}" sponsor
9292
fi
9393

94-
if [ -n "${UPDATE_CHECK}" ] && [ "${UPDATE_CHECK}" != "0" ]; then
94+
if ( "${LGSM_SAVE_CRONTAB}" ) && [ -e "${LGSM_CRONTAB_SAVEPOINT}" ] ; then
95+
echo -e ""
96+
echo -e "Found saved crontab, restoring"
97+
echo -e "================================="
98+
cat "${LGSM_CRONTAB_SAVEPOINT}" | crontab - || echo -e "Crontab is invalid, NOT restored!"
99+
elif [ -n "${UPDATE_CHECK}" ] && [ "${UPDATE_CHECK}" != "0" ]; then
95100
echo -e ""
96101
echo -e "Starting Update Checks"
97102
echo -e "================================="

entrypoint.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
exit_handler() {
44
# Execute the shutdown commands
5+
if ( ${LGSM_SAVE_CRONTAB} ) ; then
6+
echo -e "Saving user ${USER} crontab"
7+
crontab -u "${USER}" -l > "${LGSM_CRONTAB_SAVEPOINT}"
8+
fi
59
echo -e "Stopping ${GAMESERVER}"
610
exec gosu "${USER}" ./"${GAMESERVER}" stop
711
exitcode=$?
@@ -62,6 +66,7 @@ chown -R "${USER}":"${USER}" /data
6266
echo -e "updating permissions for /app"
6367
chown -R "${USER}":"${USER}" /app
6468
export HOME=/data
69+
export LGSM_CRONTAB_SAVEPOINT="${HOME}"/saved-crontab
6570

6671
echo -e ""
6772
echo -e "Switch to user ${USER}"

0 commit comments

Comments
 (0)