I'm trying to detect an error and restart server from django application. I'm using the following code:
try:
# do something
except:
print('here')
subprocess.call(['/home/my_username/restart.sh'])
restart.sh is as follows
#!/bin/sh
/home/my_username/webapps/app/apache2/bin/restart
/home/my_username/webapps/my_db/bin/cron
I'm using webfaction as hosting provider. Aboved code prints statement, but doesn't restart the server and doesn't start mysql database which is under my_db.
Maybe I need to supply username/pass? How to do that?
The subprocess.call won't expand the ~ tilde character to your home directory, and therefore it'll look into your current working directory for a folder called ~ and then from there look for your app
You can use the os.path.expanduser function to get the desired behaviour, it'll be something like this:
try:
# do something
except:
print('here')
subprocess.call([os.path.expanduser('~/webapps/app/apache2/bin/restart')])
This script will look for /home/user/webapps/app/apache2/bin/restart and execute it.
Good luck ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With