我正在尝试检测错误并从 django 应用程序重新启动服务器。
我正在使用以下代码:
try:
# do something
except:
print('here')
subprocess.call(['/home/my_username/restart.sh'])
restart.sh如下
#!/bin/sh
/home/my_username/webapps/app/apache2/bin/restart
/home/my_username/webapps/my_db/bin/cron
我正在使用 webfaction 作为托管提供商。
上面的代码打印语句,但不重新启动服务器,也不启动 my_db 下的 mysql 数据库。
也许我需要提供用户名/密码?怎么做?
The subprocess.call
不会扩大~
波形符字符添加到您的主目录,因此它将在您当前的工作目录中查找名为的文件夹~然后从那里寻找您的应用程序
您可以使用os.path.expanduser
函数来获得所需的行为,它将是这样的:
try:
# do something
except:
print('here')
subprocess.call([os.path.expanduser('~/webapps/app/apache2/bin/restart')])
该脚本将寻找/home/user/webapps/app/apache2/bin/restart
并执行它。
祝你好运 ;)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)