68 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			68 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
| #!/bin/bash
 | |
| # 2023-08-25 Hyperling
 | |
| # Put the cron command in a script as well as other automation.
 | |
| # This will need added to root's crontab with the full path, such as:
 | |
| #   */5 * * * * /opt/Docker/Config/Nextcloud/cron.ksh
 | |
| 
 | |
| DIR="$(dirname -- "${BASH_SOURCE[0]}")"
 | |
| PROG="$(basename -- "${BASH_SOURCE[0]}")"
 | |
| 
 | |
| # Check if a job is already going.
 | |
| RUNNING=`ps -ef | grep $PROG | grep -v grep | grep -v $$ | grep -v "sh -c" | wc -l`
 | |
| if (( $RUNNING > 0 )); then
 | |
| 	exit $RUNNING
 | |
| fi
 | |
| 
 | |
| # Usage function for when -h or bad parameters are passed.
 | |
| function usage() {
 | |
| 	cat <<- EOF
 | |
| 		Script to help with scheduling Nextcloud's cron requirements.
 | |
| 		Usage: $PROG [-h|-v]
 | |
| 			-h ) Display the usage and help text.
 | |
| 				| --help
 | |
| 			-v) Pass a verbose request to cron.php.
 | |
| 				| --verbose
 | |
| 	EOF
 | |
| 	exit $1
 | |
| }
 | |
| 
 | |
| # Check for any parameters.
 | |
| verbose=""
 | |
| case "$1" in
 | |
| 	"") ;;
 | |
| 	"-h"|"--help")
 | |
| 		usage 0
 | |
| 		;;
 | |
| 	"-v"|"--verbose")
 | |
| 		verbose="-v"
 | |
| 		;;
 | |
| 	*)
 | |
| 		echo -e "ERROR: Unknown parameter '$1'. Exiting.\n"
 | |
| 		usage 1
 | |
| 		;;
 | |
| esac
 | |
| 
 | |
| # Keep ownership correct and apps up to date. Also exists in fixes.sh.
 | |
| sh -c "docker exec -i nc-app chown -Rc www-data:www-data ."
 | |
| # No longer update apps in advance of NC updates, allow the upgrade process to do it.
 | |
| #sh -c "docker exec -itu www-data nc-app ./occ app:update --all"
 | |
| 
 | |
| # Prepare the variables being passed to the execution command.
 | |
| if [[ -f $DIR/.env ]]; then
 | |
| 	source $DIR/.env
 | |
| else
 | |
| 	PHP_MEMORY_LIMIT=256M
 | |
| fi
 | |
| 
 | |
| # Main part of what would go in the crontab.
 | |
| sh -c "
 | |
| 	docker exec nc-app \
 | |
| 	sudo -u www-data \
 | |
| 	php \
 | |
| 	-d apc.enable_cli=1 \
 | |
| 	-d memory_limit=$PHP_MEMORY_LIMIT \
 | |
| 	-f cron.php $verbose \
 | |
| "
 | |
| 
 | |
| exit 0
 |