Execution de 3 scripts python au demarrage

vic1707

Dabbler
Joined
Jan 28, 2019
Messages
46
Bonjour à tous,
Je cherche à rendre automatique l’exécution de 3 scripts codés en python au démarrage de mon freenas 11.1 U7.
C'est scripts sont des boucles infinies : utilisation du modules pyinotify (ils surveillent l'activités des dossiers ou sont téléchargés mes fichiers via une Jail JDownloader2, les renomme selon certaines règles et les ranges dans les dossiers pour être détectés par plex)
J'ai tenté via l'onglet Tasks mais rien n'y fait. En mettant des scripts dans "/etc/rc.d/" ex:
"
cd /mnt/DATA/added_by_JD2/scripts/
python3 rename.py
"
Mais cela ne marche pas non plus...
Je sais quand mes python sont lancés (date et heure de lancement dans un fichier txt)
Merci d'avance pour votre aide.
 

Apollo

Wizard
Joined
Jun 13, 2013
Messages
1,450
Bonjour vic1707,

Serait il preferable d executer se genre d action via a cron job?
Pour information, peux tu indiquer ce qui ne fonctionne pas?
Du peu que je me souvienne, le script python doit pointer sur le repertoire ou le program python est installe.
Cron et peut etre python n'ont pas le meme environement au lencement dans la fenetre de commande et celle du system.
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,702
Python can be executed natively in FreeNAS.

You should use the GUI to set a Post-init script to run. Direct modifications elsewhere can be removed by the system on reboot.
 

vic1707

Dabbler
Joined
Jan 28, 2019
Messages
46
Bonjour vic1707,

Serait il preferable d executer se genre d action via a cron job?
Pour information, peux tu indiquer ce qui ne fonctionne pas?
Du peu que je me souvienne, le script python doit pointer sur le repertoire ou le program python est installe.
Cron et peut etre python n'ont pas le meme environement au lencement dans la fenetre de commande et celle du system.

Je suis un grand debutant avec freenas, comment t'y prendrais-tu?
Les scripts ne se lancent tout simplement pas au demarrage de freenas mais je peux les executer via putty une fois dans le bon repertoire ( avec la commande "python3 rename.py" donc je sais qu'ils fonctionnent. ^^
Python et le module ne sont pas dans une jail mais directement dans freenas.

Python can be executed natively in FreeNAS.

You should use the GUI to set a Post-init script to run. Direct modifications elsewhere can be removed by the system on reboot.

Thanks I just discover that when i put scripts in etc/rc.d/ (not in a jail because python and the module aren't in a jail but directly in freenas) there are removed in something like 30 seconds.
I tried to create a post-init script but it seems to not work, the python scripts aren't writing in the txt file as they should.
 

Apollo

Wizard
Joined
Jun 13, 2013
Messages
1,450
You need to include the path to the python location in your Cron job:

/usr/local/bin/python /mnt/your_pool/your_dataset/your_python_script.py
 

vic1707

Dabbler
Joined
Jan 28, 2019
Messages
46
cron job.png
thanks, so i didi this, for the hours minutes day ect... what should i set?
 

Apollo

Wizard
Joined
Jun 13, 2013
Messages
1,450
It seems the script should run every hours.
If in doubt, you want to create a script that will run something simple and can be checked easily like creating a file and writing to it.
From memory, "Redirect stdout" could have a side effect on scripts. Can't say what exactly. You need to experiment.
You can also increase the recurrence to every 5 minutes and see how it works.
You can also request to run the cron job manually too, I think.
 

vic1707

Dabbler
Joined
Jan 28, 2019
Messages
46
Thanks for your help, the cron job worked perfectly but i achieve what i wanted by creating a task post init the execute a new python script which execute as the 3 others. Now It's perfectly working !
 
Top