Mysql fails to run after reboot using crontab - python

I have made a script which saves data to Mysql database using mysqldp and python. When I run script from console (python myscript.py) it works, but when I run it on reboot using Crontab I get an email with following error:
_mysql_exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
When I try to run the script using Crontab not on reboot, but accordingly to time I don't get following error.
Maybe you have some ideas?
What if I would call the same script with while(1) loop once and once again (It will start the new background task every time)?

Thanks to Shadow's hint I have solved the problem.
I just have started the Mysql server manually from the script and now it works.
I have used this command to start the server
from subprocess import call
call(['sudo','service','mysql','start'])

Related

How do i automatically run python code when my localhost apache server starts up in windows

I am trying to run a local host server using laragon .I want to start a python program and keep it running(even after server restart) until my server shutdowns .
Suppose i have a file test.py , I want to keep it running as soon as my server starts up .
I know it might work when used with PHP and calling that script using the browser. But i want to run it as soon as the server starts up as a python program.

Python Won't Run Even Through It Is In the Path

I have a SQL Server Agent job that executes some python scripts using CmdExec. Everything is set up with a proxy account as expected.
When I run the job I get:
Message
Executed as user: domain\proxyaccount. 'python' is not recognized as an internal or external command, operable program or batch file. Process Exit Code 1. The step failed.
I'm using Anaconda and Python is in the system PATH variable. When I run python from command line, it works. When I run python cutting and pasting the specific command from the job, it works. When I use runas to mimic the proxy account it works. The only place Python doesn't run is form inside the job.
What else do I need to look at to trouble shoot this issue?
You should restart SQL Server Agent after you installed Python on the server.
It is necessary for SQL Server Agent to load new environment variables, including the updated PATH with Python in it.
There are also suggestions to restart SQL Server too, but I believe restarting SQL Server Agent will be enough.

Python connection refused from localhost when runningn on cron

This is funny because most questions I found are the other way around.
I have a flask server that I start on debugging mode, listening on port 6000.
I have a script that accesses the url through localhost which sends back a JSON reply.
When I do an ssh tunnel using ssh -L and run the script that sends a request in my machine to localhost everything works fine. When I run the script directly from the server it also works fine. However, since I want to ultimately use a big data set, I setup a cron job. When the cron runs, the script crashes with connection refused error. I can see that the server is running after the script crashes and the port is correct on both.
I have no idea why this can happen. Any ideas are appreciated.
Solution
I couldn't figure out the reason or how to solve it, so I decided to run manually and put it in the background.
How to make a programme continue to run after log out from ssh?

Executing remote command using PXSSH in Python

I am trying to make Python script that will remotely start upgrade procesure of a program located on server. The upgrade procedure actually starts, but does not finish. It acctually exits immediately after start.
Here is my code:
import pxssh
w=pxssh.pxssh()
w.login('15.24.22.10','root','pass')
w.sendline('cd /home/incoming/')
w.prompt()
w.sendline('./upgrade')
w.prompt()
w.wait()
Any help would be appreciated.

supervise (python deamontools) exits after closing ssh client

I am trying to keep a python script running on my server after I close my ssh client connection. Normally I use
sudo supervise . >output.log 2>err.log < /dev/null &
but now on a new server its not working. It works fine when i start it first and still connected but the second I close my connection supervise stops.
This is my run file, and I've tripled checked its in the correct directory:
#!/bin/bash
sudo python3 Server.py
Any help is greatly appreciated!
For such task I use screen, that creates virtual terminals that can be safely detached.
You can find brief tutorial here.

Categories