Freebsd supervisord+virtualenv 源码运行odoo10

各种参考:

https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001432712108300322c61f256c74803b43bfd65c6f8d0d0000

http://blog.sina.com.cn/s/blog_955289220102ykzv.html

http://www.linuxidc.com/Linux/2012-10/71692.htm

https://blog.laslabs.com/2015/09/installing-odoo-8-from-source-ubuntu/

http://www.jianshu.com/p/40caabd91827

------------------------------------------------

切换shell命令:

#pkg install bash

#chsh -s /usr/local/bin/bash

#logout

更换非root用户默认的shell,#chsh -s /usr/local/bin/bash yourname

---------------------------------------------------

1、安装postgresql
版本不一样可能pg的用户名会是pgsql或者postgres(以下为postgres),以下用/pgsql/data作为数据库存放目录

#pkg search postgresql

 # pkg search postgresql

exim-postgresql-4.89_2         High performance MTA for Unix systems on the Internet
libgda5-postgresql-5.2.4       Provides postgresql access for the libgda5 library
opensmtpd-extras-table-postgresql-201606230001_2 PostgreSQL table support for OpenSMTPD
p5-PostgreSQL-PLPerl-Call-1.006_1 Simple interface for calling SQL functions from PostgreSQL PL/Perl
p5-PostgreSQL-PLPerl-Trace-1.001_1 Simple way to trace execution of Perl statements in PL/Perl
p5-Test-postgresql-0.09_1      Perl extension of postgresql runner for tests
pgtcl-postgresql10-2.0.0_1     TCL extension for accessing a PostgreSQL server (PGTCL-NG)
pgtcl-postgresql92-2.0.0_1     TCL extension for accessing a PostgreSQL server (PGTCL-NG)
pgtcl-postgresql93-2.0.0_1     TCL extension for accessing a PostgreSQL server (PGTCL-NG)
pgtcl-postgresql94-2.0.0_1     TCL extension for accessing a PostgreSQL server (PGTCL-NG)
pgtcl-postgresql95-2.0.0_1     TCL extension for accessing a PostgreSQL server (PGTCL-NG)
pgtcl-postgresql96-2.0.0_1     TCL extension for accessing a PostgreSQL server (PGTCL-NG)
postgresql-jdbc-9.2.1004       The Java JDBC implementation for PostgreSQL



挑一个合适的版本,目前9.6版本是没问题的
#pkg install postgresql96-server-9.6.6
#echo 'postgresql_enable="YES"' >> /etc/rc.conf
#echo 'postgresql_data="/pgsql/data"' >> /etc/rc.conf
#echo 'postgresql_class="postgres"' >> /etc/rc.conf
#echo 'postgresql_initdb_flags="--encoding=utf-8 --lc-collate=C"' >> /etc/rc.conf
 
#mkdir -p /pgsql/date
#chown -R postgres /pgsql
#chmod -R 777 /pgsql/date

#su postgres
$cd /pgsql/data

$

$ initdb -D /pgsql/data

The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "C".
The default database encoding has accordingly been set to "SQL_ASCII".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /server/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D /pgsql/data -l logfile start

$su root
#service postgresql restart



安装并创建odoo10数据库用户密码为123456
#su posgres
$psql postgres
#CREATE user odoo10  WITH PASSWORD '123456' CREATEDB;

Ctrl+d退出



2、配置odoo

以下操作root用户登录

创建用户odoo
adduser

 创建odoo10及log目录

mkdir /odoo10

mkdir /var/log/odoo10/

mkdir /var/log/supervisord/odoo10/

目录权限

chown -R odoo /odoo10

chmod -R 777 /odoo10

chown -R odoo /var/log/odoo10/

chmod -R 777 /var/log/odoo10/

用任意方法将odoo10源码上传到/odoo10

cd /odoo10
#创建虚拟环境

virtualenv --no-site-packages venv

#激活虚拟环境

source venv/bin/activate

#安装odoo的py支持环境
 pip install -r requirements.txt
deactivate命令退出虚拟环境 退出虚拟环境
node、wkhtmltopdf安装
pkg install node npm wkhtmltopdf
npm install -g less
npm install -g less-plugin-clean-css
ln -s /usr/local/bin/lessc /usr/bin/lessc
ln -s /usr/bin/node /usr/bin/node
ln -s /usr/bin/nodejs /usr/bin/node

ln -s /usr/bin/wkhtmltopdf /usr/bin/wkhtmltopdf

3.创建运行odoo10的配置文件
 vi /odoo10/odoo10.conf
内容如下:

[options]
; This is the password that allows database operations:
admin_passwd = 123456

db_host = 127.0.0.1
db_port = False
db_user = odoo10
db_password = 123456
addons_path = /server/odoo/odoo10/addons,/server/odoo/odoo10/odoo/addons
;addons_path = /server/odoo/odoo/openerp/addons
xmlrpc_port = 8069
log_level = info
logfile = /var/log/odoo10/odoo-server.log
logrotate = True
View Code


4、用python启动odoo
#进入odoo用户下用odoo10.conf配置启动odoo
su odoo
source /odoo10/venv/bin/activate
python /odoo10/odoo-bin -c /odoo10/odoo10.conf



运行正常则Ctrl+c 退出,有出错则根据错误进行解决
deactivate命令退出虚拟环境
5、用supervisor管理odoo的开机自动启动
-----------------------------------------------
安装bash
pkg install bash
创建bash脚本/odoo10/odoo10.sh
vi /odoo10/odoo10.sh
内容如下:
#!/bin/sh
source /odoo10/venv/bin/activate
python /odoo10/odoo-bin -c /odoo10/odoo10.conf

 ------------------------------------------------------------------

supervisord 管理odoo10.sh

安装supervisord

pkg search supervisor
py27-supervisor-3.3.3,1        System for controlling process state under UNIX

pkg install py27-supervisor-3.3.3,1
echo 'supervisord_enable="YES"' >> /etc/rc.conf

根据supervisor配置目录配置odoo10的supervisord脚本

vi /usr/local/etc/supervisord.conf
 [include]后面加入
files = supervisor/conf.d/*.conf
superviord-odoo10.conf
vi /usr/local/etc/supervisor/conf.d/superviord-odoo10.conf

内容如下:

[program:odoo10]
command=/usr/local/bin/bash /odoo10/odoo10.sh
directory=/odoo10/
autostart=true
autorestart=true
startsecs=8
environment=HOME="/odoo10",USER="odoo"
user=odoo
redirect_stderr=true
stdout_logfile=/var/log/supervisord/odoo10/supervisor-odoo10.log
stdout_logfile_maxbytes=500MB
stdout_logfile_backups=50
stdout_capture_maxbytes=1MB
stdout_events_enabled=false
loglevel=warn

重启supervisord服务

 service supervisord restart
 supervisorctl status

supervisorctl status odoo10
odoo10                           RUNNING   pid 705, uptime 1:30:39

===启动不起来的可能==
如果手动命令行下bash odoo10.sh可以启动,supervisor没有启动起来

看日志找不到python命令

exec python找不到 看supervisor提示 not found
把python替换为 绝对路径,如 /odoo_11c/venv/bin/python3.6

祝不报错,结束!

 
原文地址:https://www.cnblogs.com/misstaste/p/7932953.html