Initialisation script in Pihole Core v6 on powerup

Hi All,

My Pihole v5 box died so I deployed a new docker with Core v6.

Previously in Pihole Docker v5, which was Debian, I had an initialisation script mounted to /etc/cont-init.d/ that configured a cron schedule for me.

example.

volumes:
   - ./etc-cont-init/deploy-cron-job.sh:/etc/cont-init.d/99-deploy-cron-job.sh

When the container was powered on it would run the script which ran crontab "file.txt".

With Core v6 it seems to be using Alpine, /etc/cont-init.d does not exist, so I am unable to load my cron scripts. Does anyone know where I can configure init scripts in Alpine?

My current workaround is to modify the /crontabs.txt but this is not really clean way of doing it.

Kind Regards

You could adjust your docker-compose.yaml to use the docker entrypoint rather than non existent init.rd.

volumes:
   - ./etc-cont-init/deploy-cron-job.sh:/etc/docker-entrypoint.d.d/99-deploy-cron-job.sh
"

Hi robgill,

So I tried modifying entrypoint.

Although my script does not seem to run.. I need it to run after the start.sh because I want to append to the existing "Pihole" populated crontab.

entrypoint: ["/bin/bash", "-c", "start.sh && /opt/scripts/init.sh"]

If I move my script before start.sh it creates the crontab, but is missing the Pihole entries. Not sure if this is the best way to do it.

Kind Regards

Sorry, my mistake. /etc/docker-entrypoint.d isn't part of the alpine image either.

It's slightly messier completely taking over the entry point but it works as follows:

If you change entrypoint to:
"/startfirst.sh"

Example startfirst.sh (the important thing is that it ends with start.sh, to hand over to the normal startup script).

#!/bin/bash
cat /cronfile.txt >> /crontab.txt
start.sh

And be sure to copy across both your new startup script and the cronfile.txt

volumes:
   - ./startfirst.sh:/startfirst.sh
   - ./cronfile.txt:/cronfile.txt

In my examples above I've dropped everything in root, but they could be placed anywhere so long as the script and volumes are in agreement about where everything is located.

I've just tested this on current Pihole Docker, it appends the contents of cronfile.txt to the pihole provided crontab.txt (which is the one that gets read into /etc/crontabs/root by start.sh).

Hi robgill,

Thanks this seems to work! really appreciate it.

One question I do have is why I could not get the following to work? maybe I had something miss configured.

init.sh

#!/bin/bash
cat /opt/scripts/cronjob.txt >> /crontab.txt

compose.yml (only modified section).

entrypoint: ["/bin/bash", "-c", "/opt/scripts/init.sh && start.sh"

This would create a default crontab file with only my settings. Would have thought this would be the same as having a wrapper.

Kind Regards

No worries.

The problem with tagging it on to the entrypoint with && start.sh is that is that start.sh doesn't finish until it's time for the container to shut down, so it never passes to the script.

Essentially the same reason it had to be the last entry in my example script.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.