【问题标题】:Django Server autorun when Ubuntu startup or reboot?Ubuntu启动或重新启动时Django Server自动运行?
【发布时间】:2016-04-25 03:11:07
【问题描述】:

我希望我的逻辑服务器(Python3+Django+uwsgi+nginx)在 Ubuntu 服务器启动或重启时自动运行。所以,我写了一个执行脚本(uwsgi --ini=/data/xxx.ini),并将其添加到/etc/rc.local

然后,我重新启动服务器,逻辑服务器运行,但是当程序打印日志到文件时,python3 抛出异常:

Traceback (most recent call last):
  File "/usr/lib/python3.4/logging/handlers.py", line 73, in emit
    logging.FileHandler.emit(self, record)
  File "/usr/lib/python3.4/logging/__init__.py", line 1041, in emit
    StreamHandler.emit(self, record)
  File "/usr/lib/python3.4/logging/__init__.py", line 984, in emit
    self.handleError(record)
  File "/usr/lib/python3.4/logging/__init__.py", line 915, in handleError
    traceback.print_stack(frame, file=sys.stderr)
  File "/usr/lib/python3.4/traceback.py", line 286, in print_stack
    print_list(extract_stack(_get_stack(f), limit=limit), file=file)
  File "/usr/lib/python3.4/traceback.py", line 30, in print_list
    print(item, file=file, end="")
UnicodeEncodeError: 'ascii' codec can't encode characters in position 95-100: ordinal not in range(128)
Call stack:
  File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/wsgi.py", line 177, in __call__
    response = self.get_response(request)
  File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "./carwashing/views/decorators.py", line 65, in _require_login_release
    json_resp = views(request, user=token_cache.employee, *args, **kwargs)

当我直接手动启动 uwsgi 时,它运行良好。

【问题讨论】:

标签: django python-3.x ubuntu uwsgi


【解决方案1】:

你必须用虚拟激活码写一个 .sh 文件

#!/bin/bash
clear
cd /path/to your/virtual environment  #path to your virtual environment
. bin/activate  #Activate your virtual environment
cd /path/to your/project directory
python manage.py runserver  #run django server

然后为这个 .sh 文件编写一个重启 cron 作业,它会为你工作。

查看link了解更多详情..

【讨论】:

    猜你喜欢
    • 2015-12-08
    • 1970-01-01
    • 1970-01-01
    • 2018-11-07
    • 2011-08-24
    • 1970-01-01
    • 2019-11-11
    • 2013-07-08
    • 2015-05-24
    相关资源
    最近更新 更多