前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Ubuntu开机自启服务

Ubuntu开机自启服务

作者头像
Autooooooo
发布2020-11-09 10:33:04
1.1K0
发布2020-11-09 10:33:04
举报
文章被收录于专栏:Coxhuang

Ubuntu开机自动启动Python程序

#1 环境

代码语言:javascript
复制
Ubuntu16.04

#2 需求

  • Ubuntu开机自动启动一个Python程序

#3 开始

#3.1 Python程序

这里启动一个Tornado程序

代码语言:javascript
复制
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
from tornado.options import define, options
define("port", default=8000, help="run on the given port", type=int)

class IndexHandler(tornado.web.RequestHandler):
    def get(self):

        self.write("hello")

if __name__ == "__main__":
    tornado.options.parse_command_line()
    app = tornado.web.Application(handlers=[(r"/", IndexHandler)])
    http_server = tornado.httpserver.HTTPServer(app)
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.instance().start()

#3.2 shell脚本

将启动Python的命令写入shell脚本中

代码语言:javascript
复制
#!/bin/bash
nohup python3 /home/trunk/work/test/py-test/master/14.restart_built.py  &

脚本需要实现开放执行权限 sudo chmod 777 xxx.sh

#3.3 配置

代码语言:javascript
复制
sudo vim /etc/profile

添加shell脚本路径

代码语言:javascript
复制
...
/home/Desktop/selfstarting/ubuntu_start.sh

#3.4 重启

重启Ubuntu, 即可启动Tornado程序

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/07/25 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Ubuntu开机自动启动Python程序
  • #1 环境
  • #2 需求
  • #3 开始
    • #3.1 Python程序
      • #3.2 shell脚本
        • #3.3 配置
          • #3.4 重启
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档