Ubuntu开机自启服务

Ubuntu开机自动启动Python程序

#1 环境

Ubuntu16.04

#2 需求

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

#3 开始

#3.1 Python程序

这里启动一个Tornado程序

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脚本中

#!/bin/bash
nohup python3 /home/trunk/work/test/py-test/master/14.restart_built.py  &

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

#3.3 配置

sudo vim /etc/profile

添加shell脚本路径

...
/home/Desktop/selfstarting/ubuntu_start.sh

#3.4 重启

重启Ubuntu, 即可启动Tornado程序

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值