Skip to content

Commit

Permalink
commen update on 11.12
Browse files Browse the repository at this point in the history
  • Loading branch information
gitbeyond committed Nov 12, 2020
1 parent ce09c58 commit 991accb
Show file tree
Hide file tree
Showing 20 changed files with 311 additions and 23 deletions.
10 changes: 5 additions & 5 deletions common_install/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ common_instance_name: '{{common_base_name}}'

# 项目启动的方式, 目前可选择 supervisor, nginx, systemd
common_boot_type: supervisor
common_src_boot_file:
common_src_boot_file: common_app.ini
common_port:

# copy to /etc/profile.d/ of env file
common_env_file:
common_env_file: common_app.sh

# type: list
#common_other_dirs:
common_conf_files:
common_child_confs:
common_bin_scripts:
common_conf_files: []
common_child_confs: []
common_bin_scripts: []


#supervisor_conf_dir: /data/apps/config/{{supervisor_prog_name}}
Expand Down
20 changes: 20 additions & 0 deletions common_install/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
allow_duplicates: true

dependencies:
- role: common_create_user
#name: create_prom_user
tags:
- common_create_user
- role: common_create_dir
tags:
- common_create_dir
- role: common_packet_install
tags:
- common_packet_install
- role: common_copy_conf_file
tags:
- common_copy_conf_file
- role: common_boot_app
tags:
- common_boot_app
4 changes: 2 additions & 2 deletions common_install/tasks/create_common_dir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
owner: root
group: root
mode: "0755"
with_items:
loop:
- "{{app_base_dir}}"
- "{{common_install_dir}}"

Expand All @@ -17,7 +17,7 @@
owner: '{{common_run_user}}'
group: '{{common_run_group}}'
mode: "0755"
with_items:
loop:
- "{{common_conf_dir}}"
- "{{common_log_dir}}"
- "{{common_var_dir}}"
Expand Down
4 changes: 3 additions & 1 deletion common_install/tasks/create_common_user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
name: '{{common_run_user}}'
state: present
system: '{{ common_run_user_system }}'
when: common_run_user is not none and common_run_user != 'root'
when:
- common_run_user is not none
- common_run_user != 'root'
5 changes: 4 additions & 1 deletion common_install/tasks/install_common_for_tgz.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@


- name: get common packet dir name
local_action: shell tar tvf {{common_packet}} |tail -n 1 |awk '{print $NF}' |awk -F'/' '{print $1}'
local_action:
module: shell
cmd: tar tf {{common_packet}} |head -n 1 |awk -F'/' '{print $1}'
warn: false
register: packet_dir_name
run_once: true

Expand Down
File renamed without changes.
29 changes: 29 additions & 0 deletions common_install/templates/common_app.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[program:{{common_svc_name}}]
command={%if project_prog_run_args is string%}{{project_prog_run_args}}{%else%}{{ project_prog_run_args | join(' ')}}{%endif%}

directory={{project_install_dir}}
#process_name=%(program_name)s_%(process_num)s
stdout_logfile={{project_log_dir}}/%(program_name)s_std.log
stdout_logfile_backups= 5
stdout_events_enabled = false
stdout_capture_maxbytes=1MB
stdout_logfile_maxbytes=200MB
stderr_logfile={{project_log_dir}}/%(program_name)s_err.log
stderr_logfile_maxbytes=200MB
stderr_logfile_backups= 5
stderr_capture_maxbytes=1MB
stderr_events_enabled = false
{%if project_prog_envs |length >0-%}
environment=
{%-for env in project_prog_envs-%}
{{env}}={{project_prog_envs[env]}}
{%-if env != project_prog_envs[-1]-%}
,
{%-endif-%}
{%-endfor-%}
{%-endif%}
numprocs=1
user = {{project_run_user}}
stopsignal=TERM
autostart=true
autorestart=true
4 changes: 3 additions & 1 deletion common_packet_install/tasks/install_common_for_tgz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
- name: get common packet dir name
local_action:
module: shell
cmd: set -o pipefail;tar tf {{common_packet}} |head -n 1 |awk -F'/' '{print $1}'
cmd: tar tf {{common_packet}} |head -n 1 |awk -F'/' '{print $1}'
warn: false
register: packet_dir_name
changed_when: packet_dir_name.rc != 0
run_once: true
when:
- common_packet is exists


- name: cp common packet to remote
Expand Down
29 changes: 22 additions & 7 deletions deploy_project/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# 这个变量一般写在 group_vars/all.yml 中,写在这里也是为了方便
jenkins_home_dir: /data/apps/data/jenkins

# docker_image role
Expand All @@ -20,9 +21,10 @@ project_user_is_system: true
project_run_group: '{{project_run_user}}'
# 部署的机器, k8s 时,可以指定为 localhost, 然后指定 kubeconfig 来决定提交至哪个集群
project_hosts:
# 如果程序是一个 jar 包,使用 supervisor 启动时的进程名称
# 如果程序是一个 jar 包,使用 supervisor 启动时的进程名称, 有时候会出现一个项目下有多个进程的情况
project_prog_name: '{{project_name}}'
# 项目打包后的包名,如果带有版本号那么须使用 myproject*.jar 这样

# 项目打包后的包名,如果带有版本号那么须使用 myproject*.jar 这样,就是可以使用通配符来进行匹配,目前来说只适用于单个包
# /data/apps/opt/maven/bin/mvn -f dmp-server/pom.xml org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.build.finalName
# /data/apps/opt/maven/bin/mvn -q org.codehaus.mojo:exec-maven-plugin:1.3.1:exec -Dexec.executable='echo' -Dexec.args='${project.build.finalName}'
# /data/apps/opt/maven/bin/mvn -f dmp-server/pom.xml -q org.codehaus.mojo:exec-maven-plugin:1.3.1:exec -Dexec.executable='echo' -Dexec.args='${project.build.finalName}'
Expand All @@ -31,12 +33,12 @@ project_packet_name:
# 主要还是用于单个文件的操作吧,目录的话,倒是可以设置顶层目录
project_packet_mode: "0644"
project_packet_set_mode: false
# tgz or jar or directory
# tgz or jar(binary) or directory
project_packet_type:
# 为项目包名创建的软链的名字,如果包名发生了版本的变化,那么就需要在 supervisor的配置文件中更新包名,而使用软链接,只需要更新软链接即可
project_packet_link_name:
# 当前为包建立软链接的时候都是使用的绝对路径如 /data/apps/opt/app1/app1.jar -> /data/apps/opt/app1/app1-1.0.jar
# 如果想为其建立相对路径的软链接就不行了,所以增加此变量来解决这个问题
# 如果想为其建立相对路径的软链接就不行了,如 /data/apps/opt/jumpserver -> jumpserver-v2.2.0
# 各个安装方式有其默认值,不指定这个的话,会使用他们各自的默认值
# 在部署一个 directory 类型的 k8s 应用时,需要在 project_k8s_work_dir 中建立相对路径的软链,
# 所以添加了此变量
Expand All @@ -45,13 +47,17 @@ project_packet_link_src_name:
# 项目名称,就是 jenkins 的项目名
#project_name: "{{lookup('env', 'JOB_NAME')}}"
project_name: "{{lookup('env', 'JOB_BASE_NAME')}}"
# 项目的工作目录,通过环境变量获取,如果是自己手动测试的话,需要在 shell 环境中 export 此变量
project_workspace: "{{lookup('env', 'WORKSPACE') | default(jenkins_home_dir + '/workspace/' + project_name, true)}}"
# 项目启动的方式, 目前可选择 supervisor, nginx, systemd, docker, k8s
# 项目启动的方式, 目前可选择 supervisor, nginx, systemd, docker, k8s, 目前支持 supervisor, nginx, k8s
project_boot_type: supervisor

# 目前前端项目的(当 project_boot_type 为 nginx 时,project_boot_file 为 nginx 的配置文件,也可以用 project_nginx_conf 来指定)
project_boot_file:
project_prog_envs: []
# 有些项目需要在 supervisor 或 pod 内配置环境变量,使用这个列表来声明,是一个字典
project_prog_envs: {}

# 一般情况下,这个是单个文件,但是有些时候,nginx 的配置可能会使用多个配置, 后面前端项目不再使用这个变量
project_boot_files:
- '{{project_boot_file}}'

Expand All @@ -60,7 +66,7 @@ project_proxy_nginx_conf:
project_proxy_nginx_confs:
- '{{project_proxy_nginx_conf}}'

# delegate_to 的主机组,即使只有一台,也应该写成列表,因为这里要进行循环
# delegate_to 的主机组,即使只有一台,也应该写成列表,因为这里要进行循环, 比如可以写成
# 默认使用当前目标主机组
project_proxy_nginx_server: '{{ansible_play_hosts_all}}'
# delegate_to 的主机的用户,有可能其与目标主机使用的是不同的 remote_user
Expand All @@ -73,6 +79,7 @@ project_nginx_conf:
project_nginx_confs:
- '{{project_nginx_conf}}'

# 应用自身的配置文件
project_conf_file:
project_conf_files:
- '{{project_conf_file}}'
Expand All @@ -87,6 +94,7 @@ project_source_dir: '{{project_workspace}}'
project_source_packet_name: '{{project_source_dir}}/{{project_packet_name}}'

project_install_dir:
project_conf_dir:
project_data_dir:
project_log_dir:
project_var_dir:
Expand Down Expand Up @@ -139,6 +147,10 @@ project_log_data:
project_prom_conf:
project_prom_file_sd_dir:

# 这个保持默认即可,
# 之前测试过将数据写入 etcd ,然后一个脚本监听 etcd 完成把数据写入文件,进行自动发现,
# 这种方法不需要知道 prometheus 的服务器
# 现在还是方便一点,直接写入 prom 的 file_sd 的相关目录即可
project_monitor_data_generate_method: file
# 目前 prometheus 只考虑单台
project_monitor_server: localhost
Expand All @@ -147,6 +159,9 @@ project_monitor_conf:
project_monitor_conf_dir:

# project log
# 指定一个 filebeat 的input配置文件,会将其复制到 filebeat 的 inputs.d 目录下,然后就自动的开始日志收集。
# 这依赖于事先部署了 filebeat
# 当越来越多的项目部署到 k8s 上,健康检测,监控,日志收集等等,这些操作已经没有意义了
project_log_data_generate_method: file
project_filebeat_conf:
project_log_collect_conf: '{{project_filebeat_conf}}'
Expand Down
4 changes: 4 additions & 0 deletions deploy_project/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
tags:
- install_project_packet

- import_tasks: project_copy_confs.yml
tags:
- project_copy_confs

- import_tasks: boot_project/boot_project.yml
tags:
- boot_project
Expand Down
18 changes: 18 additions & 0 deletions deploy_project/tasks/project_copy_confs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 复制配置文件,默认情况下会触发自动重启
- name: copy project conf files
template:
src: "{{item}}"
dest: "{{project_conf_dir}}"
owner: "{{project_run_user}}"
group: "{{project_run_group}}"
mode: "0644"
backup: yes
register: copy_proxy_nginx_file
loop: '{{project_conf_files}}'
when:
- item is not none
- item != ''
tags:
- project_copy_confs
notify: supervisorctl_restart_prog

4 changes: 2 additions & 2 deletions jdk_install/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
jdk_packet: '{{packet_base_dir}}/jdk-8u151-linux-x64.tar.gz'
# 这个变量一般取自全局变量 {{app_base_dir}}
jdk_app_name: java
jdk_install_dir: '{{app_base_dir}}'
app_base_dir: /data/apps/opt
jdk_base_dir: '{{app_base_dir}}/{{jdk_app_name}}'
jdk_install_dir: '{{app_base_dir}}'
jdk_base_dir: '{{jdk_install_dir}}/{{jdk_app_name}}'
76 changes: 76 additions & 0 deletions scripts/python/algorithm/binary_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# -*- coding: utf-8 -*-

def binary_cur(arr, item):
if not arr:
return False

mid = len(arr) / 2
if item == arr[mid]:
return item
# 如果 item > arr[mid],那么要往右侧找
# 以 item 为 7 来举例
# 7 > arr[5]
# arr[5:] = [ 6, 7, 8, 9, 10]

elif item > arr[mid]:
print("item > %d, %d" %(arr[mid], mid))
#return binary_cur(arr[mid+1:], item)
#return binary_cur(arr[mid+1:], item)
return binary_cur(arr[mid:], item)
else:
# 7 < arr[2] = 8
# arr[:2] = [6, 7]
print("item < %d, %d" %(arr[mid], mid))
return binary_cur(arr[:mid], item)

def binary_search(arr, item):
if not arr:
return False

#idx = 0
start = 0
end = len(arr)-1

# 开始和结束位置没有问题就一直循环
while start <= end:

mid = (start + end) / 2

if item == arr[mid]:
return item

# 如果数组元素比 item 大,那么说明要往左侧找
# 以 7 举例子
# mid = 4
# arr[4] < 5
# start = mid +1 = 5
# second loop
# mid = (5 + 9) / 2 = 7
# arr[7]=8 > 7
# end = 7 - 1 = 6
# third loop
# arr[6] == 7

elif arr[mid] > item:
#arr_len = arr_len / 2 - arr_len
print("item > %d, mid: %d" %(arr[mid], mid))
# 假设这里把 arr_len 长度自减了一半
end = mid - 1
else:
print("item < %d, mid: %d " %(arr[mid], mid))
start = mid + 1

return False




a = [1,2,3,4,5,6,7,8,9,10,11]
b = [ 35, 46, 57, 68, 79, 90, 101, 112, 120, 130, 146, 147, 150]

#print(binary_search(a, 8))
for i in a:
#print(binary_search(b, i))
#print(binary_cur(b, i))
print(binary_cur(a, i))

Loading

0 comments on commit 991accb

Please sign in to comment.