Django服务器在Ubuntu启动或重启时自动运行吗? [英] Django Server autorun when Ubuntu startup or reboot?

查看:75
本文介绍了Django服务器在Ubuntu启动或重启时自动运行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want my logic server(Python3+Django+uwsgi+nginx) autorun when Ubuntu-server startup or reboot. So, I write a execute script (uwsgi --ini=/data/xxx.ini), and add it to /etc/rc.local .

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

Then, I restart server, logic-server running, But when program print log to file , python3 throw exception:

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时,效果很好.

When I direct start uwsgi in manual, it works well.

推荐答案

您必须使用虚拟激活代码编写一个.sh文件

You have to write a .sh file with virtual activate code

#!/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作业,它将对您有用.

then write a reboot cron job for this .sh file, it will work for you.

选中此链接有关更多详细信息.

Check this link for more details..

这篇关于Django服务器在Ubuntu启动或重启时自动运行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆