简体   繁体   English

在Unix服务器上部署Python脚本

[英]Deploying a Python script on a Unix server

I'd like to deploy a Python script on a server and have it executed by the cron task scheduler. 我想在服务器上部署一个Python脚本,并让它由cron任务调度程序执行。 My script is not a web service or anything of the sort: it reads stuff from a database, does some computations on it and writes the results back to the database. 我的脚本不是Web服务或任何类型的东西:它从数据库中读取内容,对其进行一些计算并将结果写回数据库。

What would be the best way to deploy such a script? 部署这样一个脚本的最佳方法是什么? I've been considering either to make a stand-alone deployment using bbfreeze or to install Python on the target machine and install the script inside a virtualenv. 我一直在考虑使用bbfreeze进行独立部署,或者在目标机器上安装Python并在virtualenv中安装脚本。 What are the pros and cons of each approach? 每种方法的优缺点是什么? are there any other approaches I should consider? 有什么其他方法我应该考虑?

I think having the script.py + virtualenv on the server is more convenient: 我认为在服务器上使用script.py + virtualenv更方便:

  • You can use version control to update your program 您可以使用版本控制来更新程序
  • You can edit the script while on the UNIX server (eg configs, passwords), test it, then commit back to version control 您可以在UNIX服务器上编辑脚本(例如配置,密码),测试它,然后提交回版本控制
  • No extra steps of bundling the interpreter with the freeze 没有额外的步骤将解释器与冻结捆绑在一起

In which case you just need a cron line like 在这种情况下,你只需要一个像cron一样的线

@daily cd /path && . venv/bin/activate && script.py
                   ^ the dot is like "source", to activate the virtualenv  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM