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.
February 14, 2023, 12:23pm
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.
February 14, 2023, 12:53pm
February 16, 2023, 1:07pm
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
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.
Description = //DESCRIPTION OF YOURONETYME JOB//
WantedBy = multi-user.target
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 redis-server.target mysql.service
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