rework of init script, now functioning as intended
This commit is contained in:
+2
-2
@@ -1,3 +1,3 @@
|
||||
# who crons will run as
|
||||
USER_ID=1000
|
||||
GROUP_ID=1000
|
||||
USER_ID=720
|
||||
GROUP_ID=720
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
FROM alpine
|
||||
|
||||
RUN mkdir -p /tock/crons
|
||||
RUN mkdir /tock
|
||||
WORKDIR /tock
|
||||
COPY . /tock/
|
||||
|
||||
|
||||
+6
-5
@@ -1,17 +1,18 @@
|
||||
services:
|
||||
preauth:
|
||||
tock:
|
||||
# TODO rename ".env.example" to just ".env"
|
||||
# edit USER_ID and GROUP_ID if needed
|
||||
container_name: tock
|
||||
env_file:
|
||||
# TODO rename ".env.example" to just ".env"
|
||||
# edit USER_ID and GROUP_ID if needed
|
||||
- .env
|
||||
image: digitaladapt/tock
|
||||
init: true
|
||||
restart: unless-stopped
|
||||
user: ${USER_ID}:${GROUP_ID}
|
||||
volumes:
|
||||
- tock-crons:/tock/crons
|
||||
# if desired, use your host timezone
|
||||
#- /etc/localtime:/etc/localtime:ro # read-only
|
||||
|
||||
volumes:
|
||||
tock-crons:
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
#m h dom mon dow command
|
||||
* * * * * date | tee -a '/var/log/cron.log'
|
||||
* * * * * date
|
||||
|
||||
|
||||
@@ -1,11 +1,51 @@
|
||||
#!/bin/sh
|
||||
|
||||
# on each boot of this container, we build the crontab
|
||||
echo '--- building combined cron ---'
|
||||
cat /tock/crons/* | tee '/tmp/tock/combined'
|
||||
crontab /tmp/tock/combined
|
||||
cd /tock
|
||||
|
||||
# check that we have some cron files to work with
|
||||
cron_files=$(find crons -type f)
|
||||
if [ -z "$cron_files" ]; then
|
||||
echo 'no crons files specified, nothing to do, stopping'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# check that we have some cron lines to work with
|
||||
cat $cron_files | grep -vE '^(#|$)' > /tmp/tock/combined
|
||||
cron_tasks=$(wc -l /tmp/tock/combined | cut -d ' ' -f 1)
|
||||
if [ "1" -gt "${cron_tasks:-0}" ]; then
|
||||
echo 'no crons tasks specified, nothing to do, stopping'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# default user/group, if not set
|
||||
if [ -z "$USER_ID" ]; then
|
||||
USER_ID=720
|
||||
fi
|
||||
if [ -z "$GROUP_ID" ]; then
|
||||
GROUP_ID=720
|
||||
fi
|
||||
|
||||
# check that the user "tock" exists and has the desired UID
|
||||
uid=$(id -u tock 2> /dev/null)
|
||||
if [ -z "$uid" ]; then
|
||||
# does not exist yet, create now
|
||||
addgroup -g $GROUP_ID tock
|
||||
adduser -D -H -u $USER_ID -G tock tock
|
||||
elif [ "$uid" -ne "$USER_ID" ]; then
|
||||
# wrong uid, remove bad and replace
|
||||
deluser -f tock
|
||||
delgroup -f tock
|
||||
addgroup -o -g $GROUP_ID tock
|
||||
adduser -M -o -u $USER_ID -g $GROUP_ID tock
|
||||
fi
|
||||
|
||||
# now that tock user exists, we can set their crontab
|
||||
crontab -u tock /tmp/tock/combined
|
||||
rm /tmp/tock/combined
|
||||
|
||||
echo "Found: $cron_tasks Cron Tasks from the following files:"
|
||||
find crons -type f
|
||||
echo '--- starting cron ---'
|
||||
|
||||
exec crond -f && tail -f /var/log/cron.log
|
||||
exec crond -f
|
||||
|
||||
|
||||
Reference in New Issue
Block a user