Python Script stops after leaving shell page

JStuff

Cadet
Joined
Jul 7, 2022
Messages
3
I want to keep my python script (Located at /media/main.py. Which is accessed through a mount point) running 24/7. The problm is, when I close the jail's shell page in which the script is running, the script dies/stops responding. Does anyone know how I keep the script running after closing the shell?

I'm running Truenas Core | TrueNAS-13.0-RELEASE
The script is running in a jail Named "python". Jail version: 13.1-RELEASE
 
Joined
Jul 10, 2016
Messages
521
One of the easiest ways is to install tmux or screen in your jail. There are plenty of tutorials and how-tos on the internet.
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
And best forget the shell page even exists and use ssh instead.
 

Paul5

Contributor
Joined
Jun 17, 2013
Messages
117
I want to keep my python script (Located at /media/main.py. Which is accessed through a mount point) running 24/7. The problm is, when I close the jail's shell page in which the script is running, the script dies/stops responding. Does anyone know how I keep the script running after closing the shell?

Ok everybody does things differently and has different set-ups. Ie, I don't have any jails.

If I want to run a script from the shell and close it, for example, a one of rsync task or other I use: nohup (Your Script Command) &>/dev/null
to see if it's running you can type 'top' in the shell and the process may be noticeable to you. To kill it ,type in 'kill' followed by the process number.

If you are going to run it 24/7 why not setup the script to start via 'PostInit' and script it to loop if it's looking for something or a 'Cron' job to restart the script every xxxx.

Examples:
I have a script started by PostInit that self loops until a specific IP appears on the network.
I also have a Cron run script that loops every 11 minutes so when all IP addresses on the list disappear the NAS shutsdown.
 
Top