Running a command on boot

Glengineer

Dabbler
Joined
Dec 20, 2020
Messages
15
Hello,

I want to run a python script I wrote that controls the fans on my server. The script is a loop so needs to stay running.

I went to the manual and saw Tasks > Init/Shutdown Scripts. I tried running the command `python /mnt/Test\ Storage/windowset/scripts/fan-controller.py` (and also with out the space escaped) and the timeout set to 0 but this did not work.

Any advise on how I can achieve my goal - I'm obviously very new to servers and TrueNAS.
 

Alecmascot

Guru
Joined
Mar 18, 2014
Messages
1,177
Are you running this Post Init ?
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,996
Does this script work when typed at the command line?
Have you looked at the TrueNAS log file to see what it might be telling you?
Is the command really
`python /mnt/Test\ Storage/windowset/scripts/fan-controller.py`
I ask because while I'm not an expert, I question the path name structure, the slash after "Test".
You might need to define the full path to python.
 

Glengineer

Dabbler
Joined
Dec 20, 2020
Messages
15
It does work via the command line, I included the \ to escape the space but I tried it without that.

I'll check the logs.
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,996
I checked the logs but grep did not find anything for python or py.
That is not good, I'd hope to see something.
Maybe a few screen shots of your GUI on how you entered the data, while I don't expect to see anything wrong, maybe something will jump out at someone. Also, try to put the script in a place where you do not have to use the \ symbol. It's an attempt to try something different because the GUI might not be able to handle it.
If I set timeout to 0 that won't end the script, right?
Um, where did you read that? I'm asking because I have not seen it and I'd like to confirm it. I would test this by making the value something like 500, this give you time to open a shell and use "top" to see if your script is running. Also, use "top" to test your script manually so you know what your are looking at. Hopefully it will work.
 

Glengineer

Dabbler
Joined
Dec 20, 2020
Messages
15
Thanks for your assistance @joeschmuck

I believe the issue with was the timeout setting. I changed the command to run in the background and redirected the output to a log file and it is all working now.

The full command I used is:

Code:
nohup python /mnt/Test\ Storage/windowset/scripts/fan-controller.py > /var/log/fan-controller.log 2>&1 &


With a timeout of 10
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,996
Great news, glad that worked. If your script is something others could make use of, you could post it as a resource and let others benefit from your work. We do that here, share knowledge.

Cheers!
 
Top