Running a script on startup

Nextcloud version: 20.0.5
Operating system and version: Docker
Nginx vesion: 1.20.2
PHP version: 8.0.25
The issue you are facing:

Just looking for advice on how to run a shell script one time when Nextcloud has finsihed it’s startup function, I don’t want to run it under cron as it only needs to run the once and the Nextcloud Background Tasks documentation doesn’t explain this very well.

Any help would be greatly appreciated.


I think there is no startup function. What time do you mean? Normally the webserver is up and running and then happens … nothing … until cron or someone executes a php script from Nextcloud.

Hi devnull, thanks for getting back to me.

Let’s assume the server has done a reboot, I need it to run one time after Nextcloud has started again, there’s no user interaction at all.

You can do this with cronjobs as well:

When your Linux uses sytemd (like Ubuntu does), this could be your friend:

This is an example, not your ready to copy&paste solution!

Think of a good catchy name for your job and put it in lowercase in place of the YOURONETIME placeholder:

Create this file /etc/systemd/system/YOURONETIME.service

In the place of “//DESCRIPTION OF YOURONETYME JOB//” add a brief description of what your script does. User and Group is only necessary if the script should not be run as root.


User=(e.g. www-data)
Group=(e.g. www-data)

WantedBy =

You can change the After= target in:



try around, in which configuration your script starts at the right time and if the required services are loaded. You can even make a combination of all your required services like this:

After=apache2.service mysql.service

enable with sudo systemctl enable --now YOURONETIME.service

To uninstall after it is no longer needed, run:

sudo systemctl disable YOURONETIME.service && sudo rm /etc/systemd/system/YOURONETIME.service

There are lots of wikis in the web about systemd.

Just my 2 cent
I hope I could help