Aerodb Posted June 29, 2020 Share Posted June 29, 2020 14 minutes ago, 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 Thank you for the catch. second attempt attached. aeroserver2-diagnostics-20200628-2040.zip Quote Link to comment
tmchow Posted July 6, 2020 Share Posted July 6, 2020 Is there a way to have a script run after array first starts then on a custom schedule after that?I could create two identical scripts and have one set to array start and the other as custom but i figure there must be a better way? Quote Link to comment
avluis Posted July 6, 2020 Share Posted July 6, 2020 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. Quote Link to comment
IKWeb Posted July 9, 2020 Share Posted July 9, 2020 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? Quote Link to comment
Squid Posted July 9, 2020 Author Share Posted July 9, 2020 Closest you could get on events would be at Array Stop, and First Array Start with whatever you want to accomplish. Quote Link to comment
Aerodb Posted July 12, 2020 Share Posted July 12, 2020 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 Quote Link to comment
ddphd Posted July 13, 2020 Share Posted July 13, 2020 (edited) 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 July 13, 2020 by ddphd Quote Link to comment
Alex.b Posted July 13, 2020 Share Posted July 13, 2020 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 » Quote Link to comment
Energen Posted July 13, 2020 Share Posted July 13, 2020 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. Quote Link to comment
Energen Posted July 13, 2020 Share Posted July 13, 2020 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. Quote Link to comment
Simon Posted July 15, 2020 Share Posted July 15, 2020 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? Quote Link to comment
mgutt Posted July 15, 2020 Share Posted July 15, 2020 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. 1 Quote Link to comment
mgutt Posted July 15, 2020 Share Posted July 15, 2020 (edited) 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 July 31, 2020 by mgutt Quote Link to comment
JonathanM Posted July 16, 2020 Share Posted July 16, 2020 3 hours ago, Alex.b said: After testing it pause the VM, not shutdown Do you have the guest agent installed in the VM? Quote Link to comment
Energen Posted July 16, 2020 Share Posted July 16, 2020 11 minutes ago, Alex.b said: I'm sorry, what is the guest agent ? https://wiki.unraid.net/index.php/UnRAID_6/VM_Management#Step_5:_Install_the_VirtIO_drivers_from_inside_the_VM_.28Windows_Guests_Only.29 Quote Link to comment
Energen Posted July 16, 2020 Share Posted July 16, 2020 https://www.google.com/search?q=virtio+guest+agent Quote Link to comment
comet424 Posted July 19, 2020 Share Posted July 19, 2020 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 Quote Link to comment
comet424 Posted July 21, 2020 Share Posted July 21, 2020 (edited) so i was able to get ssh into Raspberry pi but running code on the Raspberry Pi doesnt work right i get this error on Unraid "Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. /tmp/user.scripts/tmpScripts/raspberry pi/script: line 4: /home/pi/bin/pumpon.py: No such file or directory" my user script is ssh [email protected] /home/pi/bin/pumpon.py 16 it says no such file or directory.. but it defently exisits on the pi so i dunno why its giving me errors Edited July 21, 2020 by comet424 Quote Link to comment
Phoenix Down Posted July 22, 2020 Share Posted July 22, 2020 Simple question: If the "clearLog" option is not turned on, does a script's log file ever get rotated or does it just keep growing until /tmp is full? Quote Link to comment
jowi Posted July 24, 2020 Share Posted July 24, 2020 I'm running some python scripts on array startup; each script sends an email when it is started, and also when an exception occurs, but also when the program exits, using the atexit exit handler (https://medium.com/better-programming/create-exit-handlers-for-your-python-appl-bc279e796b6b) If i run the python script manually, ctrl-c will indeed make the program send an email that it has been stopped, but if i call the python script from a user-script, and stop the program from user-script, no exit email is being sent, the exit handler doesn't seem to be called. I guess this has to do with the way user-script runs these in the background, is there another way to hook up to some exit function in python so this works? Quote Link to comment
Phoenix Down Posted July 24, 2020 Share Posted July 24, 2020 (edited) 3 hours ago, jowi said: I'm running some python scripts on array startup; each script sends an email when it is started, and also when an exception occurs, but also when the program exits, using the atexit exit handler (https://medium.com/better-programming/create-exit-handlers-for-your-python-appl-bc279e796b6b) If i run the python script manually, ctrl-c will indeed make the program send an email that it has been stopped, but if i call the python script from a user-script, and stop the program from user-script, no exit email is being sent, the exit handler doesn't seem to be called. I guess this has to do with the way user-script runs these in the background, is there another way to hook up to some exit function in python so this works? @Squid can provide the real answer, but I suspect that User Script may be sending a SIGKILL to stop the script. When you are running your script interactively and you push Ctrl-C, a SIGINT signal is sent to your script. If your script has a signal handler (which the atexit exit handler is), this signal can be caught, which allows your script to do a more graceful exit. In your case, that includes sending an email before exiting. However, a script with a signal handler can misbehave, either by choosing to or failing to exit after intercepting the SIGINT. This is where SIGKILL comes in. That's the signal that is sent when you run "kill -9 $PID". SIGKILL cannot be caught by a signal handler. It just shoots the script in the head immediately without waiting for a response. Generally speaking, it's better to send a SIGINT first to allow a process to exit gracefully. And after a certain amount of time (i.e. 10 secs) and the process still has not exited, then send a follow-up SIGKILL to kill it immediately. If I'm right and User Scripts only sends SIGKILL, then perhaps this is a feature request you can put in for User Script. Edited July 24, 2020 by Phoenix Down 1 Quote Link to comment
Squid Posted July 24, 2020 Author Share Posted July 24, 2020 2 hours ago, Phoenix Down said: @Squid can provide the real answer, but I suspect that User Script may be sending a SIGKILL to stop the script. What I'm doing is pkill -TERM -P $pid kill -9 $pid followed by ps aux | grep -i ' /usr/bin/php /tmp/user.scripts/tmpScripts/$script' | grep -v grep And kill -9 on anything returned by the above Killing off scripts is the worst part of user scripts, and something that doesn't quite seem to ever work correctly 100% (especially with long running processes spawned by the script) Quote Link to comment
Phoenix Down Posted July 25, 2020 Share Posted July 25, 2020 7 hours ago, Squid said: What I'm doing is pkill -TERM -P $pid kill -9 $pid followed by ps aux | grep -i ' /usr/bin/php /tmp/user.scripts/tmpScripts/$script' | grep -v grep And kill -9 on anything returned by the above Killing off scripts is the worst part of user scripts, and something that doesn't quite seem to ever work correctly 100% (especially with long running processes spawned by the script) I hear you, orphaned processes are a pain in the rear. After you send the SIGTERM, do you wait at all before sending SIGKILL? Quote Link to comment
mgutt Posted July 26, 2020 Share Posted July 26, 2020 Feature Request: I really like to see echo output inside the logs (maybe as optional setting?). At the moment only errors are logged. Quote Link to comment
itimpi Posted July 26, 2020 Share Posted July 26, 2020 3 minutes ago, mgutt said: Feature Request: I really like to see echo output inside the logs (maybe as optional setting?). At the moment only errors are logged. You can always get the script to handle this by sending entries to the syslog by redirecting the output to go through the ‘logger’ command Quote Link to comment
Recommended Posts
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.