User avatar
Ferdinand
Posts: 236
Joined: Sun Dec 01, 2013 2:24 pm
Location: Leiderdorp, NL

Re: python script at startup

Mon Jul 03, 2017 6:51 pm

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.
Success with your project!
Ferdinand

tpylkko
Posts: 383
Joined: Tue Oct 14, 2014 5:21 pm

Re: python script at startup

Tue Jul 04, 2017 6:02 am

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

komarek
Posts: 146
Joined: Fri Mar 31, 2017 1:19 am

HEY GUYS i found what the problem was

Fri Aug 11, 2017 10:21 am

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

User avatar
RaTTuS
Posts: 10497
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: python script at startup

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
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 .
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

komarek
Posts: 146
Joined: Fri Mar 31, 2017 1:19 am

Re: python script at startup

Fri Aug 11, 2017 11:59 am

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

komarek
Posts: 146
Joined: Fri Mar 31, 2017 1:19 am

AND FINALLY-...... SOLVED

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
:)

User avatar
RaTTuS
Posts: 10497
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

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

Fri Aug 11, 2017 12:46 pm

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]
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

Return to “General discussion”