OPNsense Forum

English Forums => Development and Code Review => Topic started by: Jonny on October 19, 2020, 11:06:19 am

Title: [Solved] OPNsense custom cron script errors, how to debug this
Post by: Jonny on October 19, 2020, 11:06:19 am
Hi Guys.

I've made this script for PIA and Wireguard, its nearly 100% working I've got one bug.

When the script gets run by OPNsense's cron, it'll error when I've got the script's portfowarding enabled. Then when I run the python script in the terminal it doesn't error and the exit code is 0.

So with the port forwarding for PIA, you need to refresh the port on the server every 15 minutes to keep it active, so the script will wait for 599 seconds to pass and then tell the API on the WireGuard server you still want that port.

When the 599 seconds has passed, that's when the error occurs on OPNsense, if I then run the script in the terminal it doesn't error, the timer is reset and OPNsense won't error running the script til the time is up again.

How would I go about trying to debug what out the script is getting when ran by OPNsense cron?
I'm after the stdout or stderr, if that's able to be logged by the cron?

Code: [Select]
Script action failed with Command '/conf/PIAWireguard.py' returned non-zero exit status 1. at Traceback (most recent call last): File "/usr/local/opnsense/service/modules/processhandler.py", line 479, in execute stdout=output_stream, stderr=error_stream) File "/usr/local/lib/python3.7/subprocess.py", line 363, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '/conf/PIAWireguard.py' returned non-zero exit status 1.
Code: https://github.com/FingerlessGlov3s/OPNsensePIAWireguard
Title: Re: OPNsense custom cron script errors, how to debug this
Post by: Gauss23 on October 19, 2020, 11:50:01 am
As it seems to be a problem with the exit status of a 3rd party script I'd suggest creating an issue at the GitHub repository:
https://github.com/FingerlessGlov3s/OPNsensePIAWireguard/issues -> new issue.
Title: Re: OPNsense custom cron script errors, how to debug this
Post by: Jonny on October 19, 2020, 12:45:54 pm
It's my Repo 😉 OP "I've made this script"

The script has an exit code of 0, when its ran in the terminal. If I can record the stdout of the script when OPNsense cron runs it I might give me a stacktrace for the issue but I can't replicate the issue in the terminal annoying.

Is there anyway at all to get the stdout/stderr out of the OPNsense cron?

EDIT:
Forgot about Try Catch, used that and found the issue 😅. Silly working path issue typical lol