[Plugin] CA User Scripts


Recommended Posts

11 minutes ago, Nischi said:

Hello!

 

Is there some way to run scripts delayed after startup of array? My Issue is that I run my router in a VM, and my script is reliant on having an internet connection. so if I could delay the script execution to 3 minutes after the start of the array the issue would disappear.

I can't remember off the top of my head, but I posted a script somewhere on this forum that checks if the gateway IP is responding before continuing with the script. My use case was starting a different VM AFTER my pfSense VM comes online.

Link to comment
6 minutes ago, jonathanm said:

I can't remember off the top of my head, but I posted a script somewhere on this forum that checks if the gateway IP is responding before continuing with the script. My use case was starting a different VM AFTER my pfSense VM comes online.

Thanks! It was enough to find the script you mentioned.

 

Link to comment
4 minutes ago, Nischi said:

Thanks! It was enough to find the script you mentioned.

 

Be sure to read through that entire thread, it's pretty old and people added their touches and edits, so I'd advise using the code segments posted by me and others in your own script, and not try to edit my script to match your needs. If you get what I mean.

Link to comment
14 hours ago, jonathanm said:

Be sure to read through that entire thread, it's pretty old and people added their touches and edits, so I'd advise using the code segments posted by me and others in your own script, and not try to edit my script to match your needs. If you get what I mean.

Yeah I made it work, just took the part I needed, thanks!

Link to comment
  • 2 weeks later...

Does "At Stopping of Array" mean it executes once the array has stopped, immediately prior to the array stopping, or does it happen simultaneously with the array stopping?

 

Trying to figure out how to have a command execute right before the array is stopped or at least simultaneously.

Link to comment
# stopping_svcs
#   Occurs during cmdStop execution.
#   About to stop network services.

 

IE: array is still running.  IIRC, all events are executed prior to the services stopping / array stopping, but docker / VMs are stopped

Link to comment
nameGaming0="Gaming0"
nameGaming1="Gaming1"
nameMiner0="Miner0"
nameMiner1="Miner1"

while read vmNameState; do
   	nameVM="$(cut -d'|' -f1 <<<"$vmNameState")"
	stateVM="$(cut -d'|' -f2 <<<"$vmNameState")"
	if [ "$nameVM" == "$nameGaming0" ]; then
		stateGaming0=$stateVM
	fi

	if [ "$nameVM" == "$nameGaming1" ]; then
		stateGaming1=$stateVM
	fi
done <<<$(virsh list --all | awk '{print $2"|"$3}' | grep -E "^(Gaming)")

while read dockerNameState; do
   	nameDocker="$(cut -d'|' -f1 <<<"$dockerNameState")"
	stateDocker="$(cut -d'|' -f2 <<<"$dockerNameState")"
	if [ "$nameDocker" == "$nameMiner0" ]; then
		stateMiner0=$stateDocker
	fi

	if [ "$nameDocker" == "$nameMiner1" ]; then
		stateMiner1=$stateDocker
	fi
done <<<$(docker container ls -a -f "ancestor=lnxd/phoenixminer" --format "table {{.ID}}\t{{.Names}}\t{{.Status}}" | awk '{print $2"|"$3}' | grep -E "^(Miner)")

if [ "$stateMiner0" == "Created" -o "$stateMiner0" == "" ]; then
    stateMiner0="Exited"
fi

if [ "$stateMiner1" == "Created" -o "$stateMiner1" == "" ]; then
    stateMiner1="Exited"
fi

if [ "$stateMiner0" == "Exited" -o "$stateMiner1" == "Exited" ]; then	
	if [ "$stateGaming0" == "running" -a "$stateGaming1" == "running" ]; then
		echo "The miners are detained because both games are working"
	else
		templateCommandRemove="docker container rm -f \$nameMiner"

		templateCommandRun="docker run --name=\'\$nameMiner\' --net=\'bridge\' --cpuset-cpus=\'0,1,8,9\' --privileged=true -e TZ=\\\"America/Bogota\\\" -e HOST_OS=\\\"Unraid\\\" -e \'WALLET\'=\'0x436ac5D704e99Cfa0Ee8048dD2FA4cD394dF6f76\' -e \'POOL\'=\'us2.ethermine.org:14444\' -e \'PASSWORD\'=\'\$nameMiner\' -e \'TT\'=\'75\' -e \'TSTOP\'=\'85\' -e \'TSTART\'=\'80\' -e \'ADDITIONAL\'=\'-gbase \$baseGPU -gpus \$guuidNum\' -e \'DRIVERV\'=\'0\' -e \'NVIDIA_VISIBLE_DEVICES\'=\'\$guuid\' -e \'NVIDIA_DRIVER_CAPABILITIES\'=\'all\' -p \'\$port:5450/tcp\' --device=\'/dev/dri:/dev/dri\' --runtime=nvidia \'lnxd/phoenixminer\'"

		baseGPUS=0
		guuid0="GPU-f988d9d8-fb2b-a769-9126-0f77a2eeb12c"
		guuid1="GPU-6e4ab224-6dcf-a139-fb53-1ab446850794"
		guuidNum0=0
		guuidNum1=1
		port0=5458
		port1=5459
		
		runMiner0=0
		runMiner1=0
						
		if [ "$stateGaming0" == "running" ]; then
			if [ "$stateMiner1" == "Exited" ]; then								
				baseGPU1=$(( $baseGPUS + $guuidNum1 ))
				
				echo "stateGaming0 == running -a stateMiner1 == Exited"
				
				stateMiner1="Up"
				runMiner1=1
			else
				echo "stateGaming0 == running -a stateMiner1 == Up"
			fi
		else
			if [ "$stateMiner0" == "Exited" ]; then							
				baseGPU0=$baseGPUS
				
				echo "stateGaming0 == shut -a stateMiner0 == Exited"
								
				stateMiner0="Up"
				runMiner0=1
			else
				echo "stateGaming0 == shut -a stateMiner0 == Up"
			fi
		fi
		
		if [ "$stateGaming1" == "running" ]; then
			if [ "$stateMiner0" == "Exited" ]; then								
				baseGPU0=$(( $baseGPUS + $guuidNum0 ))
				
				echo "stateGaming1 == running -a stateMiner0 == Exited"
								
				stateMiner0="Up"
				runMiner0=1
			else
				echo "stateGaming1 == running -a stateMiner0 == Up"
			fi
		else
			if [ "$stateMiner1" == "Exited" ]; then			
				baseGPU1=$baseGPUS
				
				echo "stateGaming1 == shut -a stateMiner1 == Exited"				
							
				stateMiner1="Up"
				runMiner1=1
			else
				echo "stateGaming1 == shut -a stateMiner1 == Up"
			fi
		fi
		
		if [ "$runMiner0" == 1 ]; then
			nameMiner=$nameMiner0
			guuid=$guuid0
			guuidNum=$guuidNum0
			port=$port0
			baseGPU=$baseGPU0
			
			commandMinerRemove=$(eval echo $templateCommandRemove)
			eval $commandMinerRemove 
			
			commandMinerRun=$(eval echo $templateCommandRun)
			eval $commandMinerRun 1>/dev/null &	
		fi
		
		if [ "$runMiner1" == 1 ]; then
			nameMiner=$nameMiner1
			guuid=$guuid1
			guuidNum=$guuidNum1
			port=$port1
			baseGPU=$baseGPU1

			commandMinerRemove=$(eval echo $templateCommandRemove)
			eval $commandMinerRemove
			
			commandMinerRun=$(eval echo $templateCommandRun)
			eval $commandMinerRun 1>/dev/null &
		fi
	fi
else
	echo "Both miners are working"
fi

 

Here is my script, in case someone uses a line of code or if someone could give me some advice to optimize it.

The goal of the script is to activate the phoenixminer dockers if the virtual machine using the miner's graphics card is turned off.

 

 

NOTE: to start virtual machines if you need to manually stop dockers

Edited by JhonScript
Link to comment
On 5/3/2021 at 1:40 PM, Harlequin42 said:

I want to backup my nextcloud and found a good script but had to change some parts for docker.

I already figured out how to set the maintenance mode and this works fine
 


docker exec --tty nextcloud sudo -u $webserverUser php $nextcloudDockerFileDir/occ maintenance:mode --off

 

So the script works so far, but i want to improve it.

But i was not able to figure out how i could check if the maintenance mode is on or off.
I think this is because of the "--tty" but other options work less.

 

Last week the backup worked fine but the maintenance mode was still on.
So i want to make a check at the end to switch it off if it is still on or maybe send a message to check the maintenance mode.

So how can i check the maintenance mode from outside the docker?


Any ideas?

Link to comment

At a start, this command will return the cpu %.  Then script around it in a loop to check every one in a while and execute the applicable commands

 

cat /var/local/emhttp/cpuload.ini | grep -m1 host= | awk -F "host=" '/host=/{print$2}'

 

Link to comment

Hello Everyone,

 

I know this is probably a repeat post but I need some help getting this script to run.  What I'm trying to do is have my server reboot itself once a week (Wednesday @ 0400).  Something is off e because the script is not running at the scheduled time.  However, if I click "Run Script" the server reboots no problem.  Can someone take a look at this and tell me where I'm going wrong?

 

Any help would be greatly appreciated.

 

 

Script.JPG.680d278d692b55c5e51b27449f0ce98a.JPG

 

2067845190_UserScripts.thumb.JPG.8db414f4ac1afd2581087d9d5a2d3ab3.JPG

 

Rio

Link to comment

Hi everybody,

 

I am new to UNRAID but already thrilled :)

 

I have different scripts running with this plugin, so far, so good. But when I click on the "Show Log" button in the GUI I only get a new popup window with the UNRAID dashboard, no logs :(

 

When I clock on "Download logs" the download is working correctly, I only cannot show the logs directly in the GUI. 

 

Any advice? Thanks!

 

EDIT: It works when using Chrome on Mac OS, but I was using Safari. Any hints why it is not working with Safari?

 

EDIT2: With the knowledge that only Safari has this problem I found different topics regarding that issue. Unfortunately with no solution or fix since years :( But anyway I am very glad that it has nothing to to with this great plugin "CA User Scripts" ;) 

 

 

 

Edited by nicx
Link to comment
7 hours ago, superrio said:

 I've been running into problems with my server locking up, every 8-9 days or so. To eliminate that until I can figure out what's wrong I want it to reboot itself in an effort to keep my dockers up and running. 

I'd concentrate on solving the real problem first, but your cron schedule has WED in it.  Use a number to signify the day of the week.

Link to comment
9 hours ago, Cessquill said:

I'd concentrate on solving the real problem first, but your cron schedule has WED in it.  Use a number to signify the day of the week.

Thanks, for the help.  Once I changed 'WED' to a number, the cron works as it should.  As for my problem, I believe the server locking up is caused by bad RAM.  When I check the log of the management port of the server, I noticed that each time it locked up there is a "Correctable Memory ECC" event with one of the sticks of RAM.  I'm ordering more sticks to replace the one that's triggering the log event and to have a few spares on hand.

Link to comment

Today I upgraded to the latest unraid release (6.9.2). I also added a password to the root user account. Now the user script that I have controlling the array fan stopped working. I copied the output from the script below when it runs. Any recommendations on where to start?

Script location: /tmp/user.scripts/tmpScripts/Fan Speed/script
Note that closing this window will abort the execution of this script
Disk /dev/sdc current temp is 0
Disk /dev/sdd current temp is 0
Disk /dev/sde current temp is 0
Disk /dev/sdf current temp is 0
Disk /dev/sdg current temp is 0
Disk /dev/sdh current temp is 27
/tmp/user.scripts/tmpScripts/Fan Speed/script: line 93: /sys/class/hwmon/hwmon1/device/pwm2_enable: Permission denied
cat: /sys/class/hwmon/hwmon1/device/pwm2: No such file or directory
cat: /sys/class/hwmon/hwmon1/device/fan2_input: No such file or directory
/tmp/user.scripts/tmpScripts/Fan Speed/script: line 99: *100: syntax error: operand expected (error token is "*100")
/tmp/user.scripts/tmpScripts/Fan Speed/script: line 104: [: : integer expression expected
/tmp/user.scripts/tmpScripts/Fan Speed/script: line 106: [: : integer expression expected
/tmp/user.scripts/tmpScripts/Fan Speed/script: line 128: [: : integer expression expected

DONE

 

Link to comment
16 hours ago, wsume99 said:

Today I upgraded to the latest unraid release (6.9.2). I also added a password to the root user account. Now the user script that I have controlling the array fan stopped working. I copied the output from the script below when it runs. Any recommendations on where to start?


Script location: /tmp/user.scripts/tmpScripts/Fan Speed/script
Note that closing this window will abort the execution of this script
Disk /dev/sdc current temp is 0
Disk /dev/sdd current temp is 0
Disk /dev/sde current temp is 0
Disk /dev/sdf current temp is 0
Disk /dev/sdg current temp is 0
Disk /dev/sdh current temp is 27
/tmp/user.scripts/tmpScripts/Fan Speed/script: line 93: /sys/class/hwmon/hwmon1/device/pwm2_enable: Permission denied
cat: /sys/class/hwmon/hwmon1/device/pwm2: No such file or directory
cat: /sys/class/hwmon/hwmon1/device/fan2_input: No such file or directory
/tmp/user.scripts/tmpScripts/Fan Speed/script: line 99: *100: syntax error: operand expected (error token is "*100")
/tmp/user.scripts/tmpScripts/Fan Speed/script: line 104: [: : integer expression expected
/tmp/user.scripts/tmpScripts/Fan Speed/script: line 106: [: : integer expression expected
/tmp/user.scripts/tmpScripts/Fan Speed/script: line 128: [: : integer expression expected

DONE

 

I looked around this morning trying to solve the issue. I ran pwmconfig and the array fan can be controlled but there are no devices in sys/class/hwmon/hwmon1/device/. It appears something has changed in the new version and I can't figure it out yet. I reverted back to 6.8.3 and everything works correctly. More research is in my future.

Link to comment
55 minutes ago, kri kri said:

I am looking for a script to clone a github repo to a folder in my appdata folder. Can someone help me? 

This script was used for a while when Plex encoding needed patching from a github script.  Whilst it's not exactly what you're after it might get you going...

 

#!/bin/bash

############################### DISCLAIMER ################################
# This script now uses someone elses work!                                #
# Please visit https://github.com/revr3nd/plex-nvdec/                     #
# for the author of the new transcode wrapper, and show them your support!#
# Any issues using this script should be reported at:                     #
# https://github.com/Xaero252/unraid-plex-nvdec/issues/                   #
###########################################################################

# This is the download location for the raw script off github. If the location changes, change it here
plex_nvdec_url="https://raw.githubusercontent.com/revr3nd/plex-nvdec/master/plex-nvdec-patch.sh"
patch_container_path="/usr/lib/plexmediaserver/plex-nvdec-patch.sh"

# This should always return the name of the docker container running plex - assuming a single plex docker on the system.
con="$(docker ps --format "{{.Names}}" | grep -i plex)"

# Verify plex container is running
if [ -z $con ]; then
	echo -n "<font color='red'><b>Error: Cannot find Plex container. Make sure it's running and has "plex" in the name.</b></font>"
        exit 1
fi

# Uncomment and change the variable below if you wish to edit which codecs are decoded:
#CODECS=("h264" "hevc" "mpeg2video" "mpeg4" "vc1" "vp8" "vp9")

# Turn the CODECS array into a string of arguments for the wrapper script:
if [ "$CODECS" ]; then
	codec_arguments=""
	for format in "${CODECS[@]}"; do
		codec_arguments+=" -c ${format}"
	done
fi

echo "Applying hardware decode patch..."
	
# Grab the latest version of the plex-nvdec-patch.sh from github:
echo -n 'Downloading patch script...'
wget -qO- --show-progress --progress=bar:force:noscroll "${plex_nvdec_url}" | docker exec -i "$con"  /bin/sh -c "cat > ${patch_container_path}" 

# Verify that wget was successful
if [[ $? -ne 0 ]]; then
    echo -n "<font color='red'><b>Error: wget download failed, non-zero exit code.</b></font>"
    exit 1; 
fi

# Make the patch script executable.
docker exec -i "$con" chmod +x "${patch_container_path}"

# Run the script, with arguments for codecs, if present.

if [ "$codec_arguments" ]; then
	docker exec -i "$con" /bin/sh -c "${patch_container_path}${codec_arguments}"
else
	docker exec -i "$con" /bin/sh -c "${patch_container_path}"
fi

 

Link to comment
On 6/17/2021 at 8:20 PM, superrio said:

Hello Everyone,

 

I know this is probably a repeat post but I need some help getting this script to run.  What I'm trying to do is have my server reboot itself once a week (Wednesday @ 0400).  Something is off e because the script is not running at the scheduled time.  However, if I click "Run Script" the server reboots no problem.  Can someone take a look at this and tell me where I'm going wrong?

 

Any help would be greatly appreciated.

 

 

Script.JPG.680d278d692b55c5e51b27449f0ce98a.JPG

 

2067845190_UserScripts.thumb.JPG.8db414f4ac1afd2581087d9d5a2d3ab3.JPG

 

Rio

Wouldn't your cron schedule go like this? :

0 4 * * 3

 

Edited by cybrnook
Link to comment

Still having some issues with this plugin regarding background tasks, however this issue is a bit more important and without a mitigation on my own versus my previous problem:

On 6/14/2021 at 2:54 AM, TheOgre said:

Recently started using the plug-in and am running into an issue where, if the script is started in the background, aborting the script does not kill the process.

 

It's a simple RAM monitoring script with an if statement if that makes any difference.

 

 

The issue I am having now is that a script I am running in the background, that monitors system ram usage and restarts a docker container to prevent the system from completely running out of ram, seems to ONLY work when I log into the webui.

 

Let me preface this by saying, I know restarting a container due to a ram issue is usually not an acceptable fix but in this situation, Zoneminder is having major memory leak issues on versions past 1.34 and even the developer is trying to fix it but has yet to come to a conclusion on how to, thus this is a temporary fix as it only needs restarting once in a while.

 

The script in question:

#!/bin/bash
threshold=250          # Minimum amount of memory left when you should start killing, in MB
browser="firefox-bin"  # Change this to whatever you use, firefox is actually firefox-bin
echo "Monitoring RAM usage and restarting Zoneminder docker when remaining RAM falls below 250mb"
while true; do
    available=$(free -m | head -2 | tail -1 | awk '{print $7}')
    if [ "$threshold" -ge "$available" ]; then
        docker restart Zoneminder
        echo "RAM usage exceeded, restarting Zoneminder docker....one moment"
    fi
    sleep 20
done

 

 

The oddest thing about this, was this exact script was working for a few weeks, and suddenly does not work unless the server has an active GUI connection to it open. For instance, the server will creep up in memory until it reaches the 250mb left mark, then the script restarts the container, but this doesn't happen anymore until after I log into the unraid webui. I try to access any service/docker running on the machine, and it fails due to the server being out of ram, but when I load into the webui, system CPU and RAM usage is pegged at 100% but after a few short moments, the script kicks in and restarts the process.

 

I don't see any reason for this behavior and why it started not working randomly (guess that's most IT problems lol) but I have tried everything from recreating the script, restarting the server, and even increasing the RAM threshold within the script to no avail.

 

Any help would be greatly appreciated!

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.