[Plugin] CA User Scripts


Recommended Posts

On 6/13/2020 at 6:11 PM, Squid said:

If you look at the syslog (Tools), do you see "bread" errors?

checked syslog, not seeing anything with the word "bread" in it. yet i cant apply any changes in the user scripts plugin. i can only run the scripts or hit done. 

Link to comment
On 5/31/2020 at 8:26 AM, Squid said:

Long running processes cannot be killed via the abort button.  (I've tried everything to try and kill the PID of children from the PID of the parent, and nothing works because of how everything works under the hood)

I've had a few python scripts that run in the background which I needed to start/stop alongside the array; ex:

#!/bin/bash
#description=Starts Stream Deck Home Assistant Client. Req: python3
#arrayStarted=true
#name=start stream deck HASS client

# Change to app directory
cd /mnt/user/appdata/homeassistant-streamdeck/

# Source python venv
source venv/bin/activate

# Change to app src directory
cd /mnt/user/appdata/homeassistant-streamdeck/src

# Check if already running and stop
if pgrep -f "python3 HassClient.py" &>/dev/null; then
    echo "app is already running, killing"
    pkill -9 -f "python3 HassClient.py"
    sleep 5
fi

# Start app
python3 HassClient.py &
pid=$!

# User Scripts background fix
echo $pid > /tmp/user.scripts/running/start-streamdeck-ha
wait $pid


I've been able to get the intended behavior by saving the child PID manually along with a wait command.

Haven't looked too deep into exec.php for a better workaround but this is working for the moment.

Link to comment

Evening all 

I am new to User Scripts and wanted to know if the below is possible. 

When the UNRAID Server moves over to battery power and the UPS kicks in - is it possiable to create a script that will then trigger a URL? Then the same again when power is restored, a 2nd script that will trigger a 2nd URL? 

Link to comment
On 6/28/2020 at 8:42 PM, Aerodb said:

 

Thank you for the catch. second attempt attached. 

aeroserver2-diagnostics-20200628-2040.zip 346.85 kB · 2 downloads

 

On 6/28/2020 at 8:27 PM, trurl said:

That is not the diagnostics. Diagnostics includes log but also other things.

 

Tools - Diagnostics.

 

On 6/21/2020 at 6:20 AM, Squid said:

Then post the diagnostics

was this helpful at all? im not sure what im looking at with these logs/diagnostics. fresh copy attached.  

aeroserver2-diagnostics-20200712-1007.zip

Link to comment

If I include `git pull` in a script I get `fatal: could not read Username for 'https://github.com': No such device or address` I'm able to `git pull` fine if I use the terminal. Is there a reason why it would work in the terminal, but not with user scripts?

Edited by ddphd
Link to comment
On 7/9/2020 at 3:26 PM, IKWeb said:

Evening all 

I am new to User Scripts and wanted to know if the below is possible. 

When the UNRAID Server moves over to battery power and the UPS kicks in - is it possiable to create a script that will then trigger a URL? Then the same again when power is restored, a 2nd script that will trigger a 2nd URL? 

 

Seems it might be possible but would actually require interacting with apcupsd rather than as a "user script" that's easy to just drop into Unraid.  This would take some custom work, but not overly difficult it doesn't look like.

 

https://www.systutorials.com/docs/linux/man/8-apccontrol/

 

Specifically you'd be wanting to implement a script when apcupsd triggers this notificaiton:

 

powerout

apcupsd generates this event as soon as apcupsd detects that the UPS has switched to battery power and it is not a self-test.

Link to comment
6 hours ago, Alex.b said:

Hello I just want power on for 30 mins a Windows 10 VM to execute a software every day. How Can I achieve this ? I’m a total beginner with user script. I read to use « virsh start »

Yes, here's a basic script to do that.

 

virsh start <name of vm>
sleep 30m
virsh shutdown <name of vm>

 

Or you could just start it and then have the Windows VM shut itself down after a period of time.

Link to comment

Apologies if this has previously been answered, but I'm looking to run a set of light commands every 20 seconds for diagnostic purposes.

 

If I enter a script such as:

 

#!/bin/bash
while true
do
 <my stuff>
 sleep 20
done

And schedule it for run in background  and at first array start only will it run forever?

Link to comment
5 hours ago, Simon said:

will it run forever?

It should, but maybe something goes wrong inside your script or something else causes a crash.

 

Maybe it's better to set the cron interval to "every hour". But you need to think about what happens if your script is running multiple times. If this is a problem, you need to build a condition to be sure it's running only once.

  • Like 1
Link to comment
On 5/1/2020 at 11:26 AM, mgutt said:

Is CA User Scripts race condition safe or do I need to make my own check to be sure that my script runs atomic?

I made a little test and its not, so I created this script:

#!/bin/bash

# make script race condition safe
if [[ -d "/tmp/${0///}" ]] || ! mkdir "/tmp/${0///}"; then
    exit 1
fi
trap 'rmdir "/tmp/${0///}"' EXIT

# script
# ...

By that a dir is created in /tmp with the name of the script and it is deleted after the script has been executed. And as long the script is running (so the dir is not deleted), the script will not be executed again.

 

Edited by mgutt
Link to comment
On 7/13/2020 at 5:59 PM, Energen said:

Yes, here's a basic script to do that.

 

virsh start <name of vm>
sleep 30m
virsh shutdown <name of vm>

 

Or you could just start it and then have the Windows VM shut itself down after a period of time.

After testing it pause the VM, not shutdown :(

 

image.png.3cedaed7ffe44c9356da1337e4a9a66e.png

Link to comment

hi  i i have couple questions i tried googling didnt find the answers

1... can you  access Raspberry PI to run a command on it  from the user scripts  at a certain time.

2.. i know how to setup rsync to login another unraid  using the pub key stuff..   but can i do the same for raspberry pi kinda thing

 

what i wanan do is

Unraid ====>certain time====>tells Raspberry Pi to flip a relay on  using one of my raspberry pi scripts

then unraid(main)  in the userscript then tells another computer to turn on WOL       and then rsyncs with it..  

then after  unraid tells that computer to shut down.. and then tells Raspberry pi to run another script before ending the user script

 

is there any code that could help me

 

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.