python开机自启动代码_在启动时自动启动python脚本?

我遵循了stackoverflow上提供的关于在启动时启动python脚本的多个教程,但它们都不起作用。

我需要激活一个virtualenv然后启动一个flask服务器我试过了

初始d方法

我在/etc/init.d/中做了一个start.sh#!/bin/sh

### BEGIN INIT INFO

# Provides: skeleton

# Required-Start: $remote_fs $syslog

# Required-Stop: $remote_fs $syslog

# Should-Start: $portmap

# Should-Stop: $portmap

# X-Start-Before: nis

# X-Stop-After: nis

# Default-Start: 2 3 4 5

# Default-Stop: 0 1 6

# X-Interactive: true

# Short-Description: Example initscript

# Description: This file should be used to construct scripts to be

# placed in /etc/init.d.

### END INIT INFO

cd /home/ion/

source /home/ion/py35/bin/activate

cd /home/ion/Desktop/flask/

nohup python main.py &

echo "Done"

它的权限是chmod at+xion@aurora:/etc/init.d$ ll start.sh

-rwxr-xr-x 1 root root 625 Jun 25 19:10 start.sh*

转到/etc/rc.local#!/bin/sh -e

#

# rc.local

#

# This script is executed at the end of each multiuser runlevel.

# Make sure that the script will "exit 0" on success or any other

# value on error.

#

# In order to enable or disable this script just change the execution

# bits.

#

# By default this script does nothing.

/etc/init.d/start.sh

exit 0

不起作用cronjob方法

sudo crontab-e

并附加@reboot sh '/etc/init.d/start.sh'

也没起作用,我错在哪里?

手动触发日志(py35) ion@aurora:~/Desktop/flask$ python main.py

WARNING:tensorflow:From /home/ion/Desktop/flask/encoder.py:57: calling l2_normalize (from tensorflow.python.ops.nn_impl) with dim is deprecated and will be removed in a future version.

Instructions for updating:

dim is deprecated, use axis instead

2018-06-25 19:34:05.511943: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA

* Serving Flask app "main" (lazy loading)

* Environment: production

WARNING: Do not use the development server in a production environment.

Use a production WSGI server instead.

* Debug mode: on

* Running on http://localhost:5505/ (Press CTRL+C to quit)

* Restarting with stat

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值