Can't get Init script to run

lmannyr

Contributor
Joined
Oct 11, 2015
Messages
198
I used to have this fan script automatically start and stay running on boot. After several truNAS upgrades....it is no longer running. Running "PS" in shell does not show it running. I can manually run it in shell...but when shell is shut down....the script is shut down. I need it to run on boot....and stay running. What am I doing wrong here. Path the the .sh file is correct.

Screen Shot 2022-06-10 at 10.14.50 PM.png
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
Does the script have all the execute bits set? Try chmod 755 </path/to/script>.
 

lmannyr

Contributor
Joined
Oct 11, 2015
Messages
198
Does the script have all the execute bits set? Try chmod 755 </path/to/script>.
No change. I added "999999999" to the timeout to see if I see it running once boot is complete.. If so...then I need to know how to disable the "timeout" entry for the init script setup.
 

lmannyr

Contributor
Joined
Oct 11, 2015
Messages
198
"0" in timeout doesn't disable the "timeout" function.
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
What are the contents of the script? It could be something simple, like needing to specify the full paths of any executables in the script.
 

lmannyr

Contributor
Joined
Oct 11, 2015
Messages
198
What are the contents of the script? It could be something simple, like needing to specify the full paths of any executables in the script.

Above is the link to the script. It has ALWAYS worked. Still works now if I manually start it in shell. For the meantime, I have it running under TMUX just fine. It just wont run in "INIT". There is a TIMEOUT entry in the INIT setup. The timeout help says it is the amount in seconds until the script is terminated. So, what do I put in the TIMEOUT section if I DON"T want it to terminate and would rather it run indefinitely?
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
You write

Code:
#!/bin/sh

(
# your code
# that should run
# forever
) >/dev/null 2>&1 &

exit 0
 

lmannyr

Contributor
Joined
Oct 11, 2015
Messages
198
You write

Code:
#!/bin/sh

(
# your code
# that should run
# forever
) >/dev/null 2>&1 &

exit 0
Write that where? In the "timeout" section of the init setup? really?
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
No,that's what you put in your script. Enclose all the code you want to keep running in parentheses () and add a & at the end --> background job. So the script you use as an init task can exit but the code you need to run keeps running, Shell programming 101 ...
 

lmannyr

Contributor
Joined
Oct 11, 2015
Messages
198
No,that's what you put in your script. Enclose all the code you want to keep running in parentheses () and add a & at the end --> background job. So the script you use as an init task can exit but the code you need to run keeps running, Shell programming 101 ...
I'll give it a shot. No programming ed here, but can get around with some guidance. Thanks!!
 

lmannyr

Contributor
Joined
Oct 11, 2015
Messages
198
No,that's what you put in your script. Enclose all the code you want to keep running in parentheses () and add a & at the end --> background job. So the script you use as an init task can exit but the code you need to run keeps running, Shell programming 101 ...
This worked. Thank you sir.
 

lmannyr

Contributor
Joined
Oct 11, 2015
Messages
198
This worked. Thank you sir.
I take this partly back. This will keep it running if ran under shell/ssh etc and exiting. TMUX not needed. But still does not work as a TRU NAS Core Post init task. Its still not running after a reboot.
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,700
If you want to be able to interact with the script while it continues running I would suggest running it with tmux as I mention in the edit at the bottom of this post:

That also conveniently gets around the need to deal with timeouts, as it effectively exits from the launcher just like a command with "&" at the end.
 

lmannyr

Contributor
Joined
Oct 11, 2015
Messages
198
If you want to be able to interact with the script while it continues running I would suggest running it with tmux as I mention in the edit at the bottom of this post:
"I" dont' need to interact with the script. I need it to run in the background 24/7 post system boot. System RARELY gets a reboot, but don't want to forget to run this manually. Worked prior to all the updates as a post init task.
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,700
"I" dont' need to interact with the script. I need it to run in the background 24/7 post system boot. System RARELY gets a reboot, but don't want to forget to run this manually. Worked prior to all the updates as a post init task.
Well, what I'm proposing IS a post init task that has worked (and still works) for me, which wraps the script in a tmux session that automatically starts as an init script... ignore it if you want.

It's also a clean way to avoid needing to reboot in order to restart/modify the script as you can just keep it going in the tmux session.
 

lmannyr

Contributor
Joined
Oct 11, 2015
Messages
198
Well, what I'm proposing IS a post init task that has worked (and still works) for me, which wraps the script in a tmux session that automatically starts as an init script... ignore it if you want.

It's also a clean way to avoid needing to reboot in order to restart/modify the script as you can just keep it going in the tmux session.
Ah....Ok. I'll read up on the post. Thanks!
 
Top