Page 4 of 4

Re: python script at startup

Posted: Mon Jul 03, 2017 6:51 pm
by Ferdinand
What is your exactly your problem? If you start rc.local proposed in my previous post than your problem has been solved. The only thing is you have to do some tweaks.

Modify analitico.py for systemd

1) Add time.sleep(20)
2) Remove the while loop and try except stuff inside the while loop too.
You don't need the while loop.
3) disable invia_analitici() by placing a # before that instruction
4) keep in mind goolge stuff is not needed for a simple test. If everything works fine than enable that instruction.

Start your analitico.sh and see what happens.

Important
Remember analitico.sh does not open a terminal so you don't see any output. The output is redirected to a log file analitico.log.

Re: python script at startup

Posted: Tue Jul 04, 2017 6:02 am
by tpylkko
komarek wrote:
i dont think i understand what you mean
Sorry, I'll explain a bit better. In Linux operating systems you can automatically start programs in many ways. One of these many ways is via the desktop, so that when the graphical interface launches it also starts those other programs. This is good when you want to launch a larger more complicated program for a specific user (like a browser, you cannot launch a browser with rc.local or systemd service, but you can autolaunch it with a desktop). The example in the Debian guide below the guy launches a terminal window with a music player program automatically. But you could adapt it to your script by starting a Python shell and then the script.

https://debian-administration.org/artic ... n_X_starts

See also:
viewtopic.php?t=18968


Don't get frustrated, there are truly hundreds of ways to auto run stuff on Linux. Some methods are better suited for some types of applications and others for others. You will notice this if you read that second link I posted above

HEY GUYS i found what the problem was

Posted: Fri Aug 11, 2017 10:21 am
by komarek
the python script to run properly actually need to be launched from a directory where a file called "analytics.dat" is.
so... how can i fix this on systemd level?
cheers

Re: python script at startup

Posted: Fri Aug 11, 2017 11:11 am
by RaTTuS
tpylkko wrote:
Tue Jul 04, 2017 6:02 am
... (like a browser, you cannot launch a browser with rc.local or systemd service, but you can autolaunch it with a desktop)....
actually you can , but it's gets a bit more complex it's is usually easier to start with the x autostart method

re - setting home directories
umm maybe the use of
AssertPathExists=/full/path/to/base
may be what you want , though personally I'd make sure the program is path independent and/or uses a config file that you can specify on the command line .

Re: python script at startup

Posted: Fri Aug 11, 2017 11:59 am
by komarek
RaTTuS wrote:
Fri Aug 11, 2017 11:11 am
tpylkko wrote:
Tue Jul 04, 2017 6:02 am
... (like a browser, you cannot launch a browser with rc.local or systemd service, but you can autolaunch it with a desktop)....
actually you can , but it's gets a bit more complex it's is usually easier to start with the x autostart method

re - setting home directories
umm maybe the use of
AssertPathExists=/full/path/to/base
to put it in the .service file?
may be what you want , though personally I'd make sure the program is path independent and/or uses a config file that you can specify on the command line .
unfortunately the call is not made by my script but by the analytics module, that's why it search on the home directory

AND FINALLY-...... SOLVED

Posted: Fri Aug 11, 2017 12:35 pm
by komarek
all i did was to add these line to the .service file:

WorkingDirectory=/home/pi
ExecStart=/home/pi/analitico.sh

i just put the shell file in the home directory and now it's running like charm
thanks everyone
it took me weeks to understand this stupid things
:)

Re: AND FINALLY-...... SOLVED

Posted: Fri Aug 11, 2017 12:46 pm
by RaTTuS
komarek wrote:
Fri Aug 11, 2017 12:35 pm
all i did was to add these line to the .service file:

WorkingDirectory=/home/pi
ExecStart=/home/pi/analitico.sh

i just put the shell file in the home directory and now it's running like charm
thanks everyone
it took me weeks to understand this stupid things
:)
+1; yes forgot about that one [brain fade]