Merge branch 'ver1.0' into 'main'

exemONE Host Agent Installer Container Image

See merge request sa_8001/exemone_agent_installer!2
This commit is contained in:
정훈 변
2024-08-22 14:49:26 +09:00
71 changed files with 5241 additions and 1 deletions

14
Dockerfile Normal file
View File

@@ -0,0 +1,14 @@
FROM python:3.11.9-alpine3.20
LABEL version="1.0"
LABEL agent_list="host,container,ndm"
RUN \
pip3 install ansible && \
apk add openssh
WORKDIR /installer
COPY ./installer ./
CMD ["ansible-playbook", "-i", "/installer/inventory", "/installer/agent.yml"]

64
installer/README.md Normal file
View File

@@ -0,0 +1,64 @@
# exemONE Agent Installer
현재 공개된 exemONE의 host-agent , container-agent 인스톨러 같은 경우<br>
각각의 서버에서 인스톨러를 실행하여 설치를 하게 되어 있어, 소수의 서버일 경우에는 문제가 없지만<br>
설치를 해야하는 서버의 대수가 많을 경우 번거로우며, 각 서버에 파일 반입, 실헹을 해야하는 등 시간 낭비가 발생함<br>
이를 해결하기 위해 ansible을 통해 설치 과정을 자동으로 수행하도록 제작하였음.
# 사용 방법
본 인스톨러를 사용하는 방법은 아래와 같음<br>
## inventory 작성 (inventory 파일)
```
byeonjunghun@JHMacMini exemone % vi inventory
[all:children]
host_agent
container_agent
[host_agent]
10.10.54.150 # host-agent를 설치할 서버 IP 입력
10.10.54.105
[container_agent]
10.10.54.105 # container-agent를 설치할 서버 IP 입력
[ndm_agent]
10.10.54.150
host-agent와 container-agent 둘 모두를 설치하고 싶을 경우 10.10.54.105 서버 처럼 두군대 모두 입력
```
## playbook 작성 (agent.yml 파일)
```
byeonjunghun@JHMacMini exemone % vi agent.yml
---
- hosts: all
become: true
gather_facts: true
roles:
- role: one_agent
vars:
EXEM_HOME: /home/exem
RECEIVER_ADDR: 10.10.38.132
#RECEIVER_PORT: 9010
#RECEIVER_CONTAINER_PORT: 9009
# port 설정이 필요할 경우 위 주석을 해제하고 설정
# RECEIVER_PORT 와 RECEIVER_CONTAINER_PORT 같은 경우 변수를 설정하지 않을 경우 default 값으로 각각 9010 , 9009 으로 설정 됨
agent_list: ['host-agent', 'container-agent', 'ndm-agent']
agent_list 부분에 설치하고자 하는 agent 목록 작성
현재는 host-agent 와 container-agent, ndm-agent 만 지원
```
## ssh key copy
```
ssh-keygen -t rsa # ansible을 실행하는 서버에 ssh key가 없을 경우 생성
ssh-copy-id user@ip # agent를 설치하고자 하는 서버에 key 등록 (ansible을 실행하는 서버도 등록)
user 같은 경우 root 권한을 가지고 있어야 함
```
## playbook 실행
`ansible-playbook -i inventory agent.yml` 명령어로 실행

8
installer/ansible.cfg Normal file
View File

@@ -0,0 +1,8 @@
[defaults]
inventory = inventory
roles_path = roles
deprecation_warnings = False
display_skipped_hosts = no
ansible_home = .
stdout_callback = debug
host_key_checking = False

View File

@@ -0,0 +1,25 @@
Task
-----------
| Task | 설명 | 비고 |
| ------ | ------ | ------ |
| host-agent.yml | exemONE의 host-agent를 설치하는 Task | - |
| container-agnet.yml | exemONE의 container-agent를 설치하는 Task | - |
| ndm-agent.yml | exemONE의 ndm-agent를 설치하는 Task | - |
| rsync.yml | rsync를 설치하는 Task | copy 모듈로 변경 되어 사용하지 않는 Task |
File
-----------
| 디렉토리 | 설명 | 비고 |
| ----- | ----- | ----- |
| host | host-agent 설치 파일 | - |
| container | contaienr-agent 설치 파일 | - |
| ndm | ndm-agent 설치 파일 | - |
| rpm | rsync 설치용 rpm | 현재는 사용하지 않음 |
Template
----------
각 Agent 실행에 필요한 파일 생성을 위한 Template
그 외
----------
사용하지 않는 기본 디렉토리

View File

@@ -0,0 +1,2 @@
---
# defaults file for one_agent

View File

@@ -0,0 +1,7 @@
#!/bin/sh
PRODUCT_NAME=exemONE
MODULE_NAME=exem-host-agent
VERSION=1.2.2
echo ${PRODUCT_NAME} ${MODULE_NAME} ver ${VERSION}

View File

@@ -0,0 +1,3 @@
#!/bin/sh
service exem-host-agent start

View File

@@ -0,0 +1,3 @@
#!/bin/sh
service exem-host-agent stop

View File

@@ -0,0 +1,25 @@
#!/bin/sh
SYSTEMCTL=$(which systemctl 2> /dev/null)
SERVICE=$(which service 2> /dev/null)
CHKCONFIG=$(which chkconfig 2> /dev/null)
if [ -n "${SYSTEMCTL}" ]; then
systemctl stop exem-host-agent
systemctl disable exem-host-agent
systemctl daemon-reload
if [ -e "/etc/systemd/system/exem-host-agent.service" ]; then
rm -f /etc/systemd/system/exem-host-agent.service
systemctl daemon-reload
fi
if [ -e "/etc/systemd/system/default.target.wants/exem-host-agent.service" ]; then
rm -f /etc/systemd/system/default.target.wants/exem-host-agent.service
systemctl daemon-reload
fi
echo "exem-host-agent is disabled"
fi

View File

@@ -0,0 +1,3 @@
#!/bin/sh
sudo systemctl start exem-host-agent

View File

@@ -0,0 +1,7 @@
#!/bin/sh
PRODUCT_NAME=exemONE
MODULE_NAME=exem-container-agent
VERSION=1.1.2
echo ${PRODUCT_NAME} ${MODULE_NAME} ver ${VERSION}

View File

@@ -0,0 +1,16 @@
#!/bin/sh
docker load -i __INST__EXEM_HOME__/container/image/exem-container-agent_image_1.1.2.tar
docker run -d \
--cap-add SYS_PTRACE \
--restart=always \
-v /:/host:ro \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
-v /run/containerd/containerd.sock:/run/containerd/containerd.sock:ro \
--env EXEM_HOME="__INST__EXEM_HOME__" \
--env EXEM_CONTAINER_HOME="__INST__EXEM_HOME__/container" \
--env COMMON_RECEIVER_IP="__INST__RECEIVER_IP__" \
--env COMMON_RECEIVER_PORT="__INST__RECEIVER_PORT__" \
--env CONTAINER_LOG_LEVEL="info" \
--name exem-container-agent exem-container-agent:1.1.2

View File

@@ -0,0 +1,4 @@
#!/bin/sh
docker stop exem-container-agent
docker rm exem-container-agent

View File

@@ -0,0 +1,25 @@
#!/bin/sh
SYSTEMCTL=$(which systemctl 2> /dev/null)
SERVICE=$(which service 2> /dev/null)
CHKCONFIG=$(which chkconfig 2> /dev/null)
if [ -n "${SYSTEMCTL}" ]; then
systemctl stop exem-container-agent
systemctl disable exem-container-agent
systemctl daemon-reload
if [ -e "/etc/systemd/system/exem-container-agent.service" ]; then
rm -f /etc/systemd/system/exem-container-agent.service
systemctl daemon-reload
fi
if [ -e "/etc/systemd/system/default.target.wants/exem-container-agent.service" ]; then
rm -f /etc/systemd/system/default.target.wants/exem-container-agent.service
systemctl daemon-reload
fi
echo "exem-container-agent is disabled"
fi

View File

@@ -0,0 +1,35 @@
#!/bin/sh
SYSTEMCTL=$(which systemctl 2> /dev/null)
SERVICE=$(which service 2> /dev/null)
CHKCONFIG=$(which chkconfig 2> /dev/null)
# root 권한 없는 경우 불가능
if [ "$(id -u)" -ne 0 ]; then
echo "Not a root user. Not support service registration"
echo "Use binary mode or image mode"
exit 1
fi
if [ -n "${SYSTEMCTL}" ]; then
# SELinux setting
SELINUX_OPTION=$(awk -F= '/^SELINUX=/{print $2}' /etc/selinux/config)
if [ ${SELINUX_OPTION} != "disabled" ]; then
chcon -t bin_t __INST__EXEM_HOME__/container/script/binary_mode/start.sh
chcon -R -t var_run_t __INST__EXEM_HOME__/container/data
fi
if [ ! -e "/etc/systemd/system/exem-container-agent.service" ]; then
systemctl enable __INST__EXEM_HOME__/container/data/service/exem-container-agent.service
fi
systemctl daemon-reload
echo "exem-container-agent is enabled"
else
echo "this OS version that does not support service registration"
echo "Use binary mode or image mode"
exit 1
fi

View File

@@ -0,0 +1,3 @@
#!/bin/sh
sudo systemctl start exem-container-agent

View File

@@ -0,0 +1,5 @@
#!/bin/sh
sudo __INST__EXEM_HOME__/container/script/binary_mode/stop.sh
sudo systemctl stop exem-container-agent

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@@ -0,0 +1,53 @@
#!/bin/sh
INTERVAL=3
if [ -n "$1" ];then
INTERVAL="$1"
fi
PROCESS_NAME="exem-ndm-agent"
HEAD=`ps -eo user,pid,pcpu,pmem,rss,sz,size,vsize,cmd | sed -n '1p'`
echo " ${HEAD}"
PEAK=0
while :
do
CUR_DATE=`date +%d' '%H:%M:%S`
PROCESS_PID=`ps -ef | grep -v grep | grep -v vi | grep -v tail | grep -v ctl | grep -v svc | grep ${PROCESS_NAME} | awk -F' ' '{print $2}'`
if [ -n "${PROCESS_PID}" ];then
RESULT=`ps -p ${PROCESS_PID} -o user,pid,pcpu,pmem,rss,sz,size,vsize,cmd --no-heading`
RSS=`echo ${RESULT} | awk -F' ' '{print $5}'`
if [ ${RSS} -gt ${PEAK} ];then
OUT_PEAK=" PEAK:${PEAK}/${RSS}"
PEAK=${RSS}
PEAK_STAT="peak"
else
OUT_PEAK=" PEAK:${PEAK}"
PEAK_STAT=""
fi
echo "${CUR_DATE} ${RESULT}${OUT_PEAK}"
if [ -n "${PEAK_STAT}" ];then
echo "${CUR_DATE} ${RESULT}${OUT_PEAK}" >> peak.log
fi
else
echo "${CUR_DATE} ${PROCESS_NAME} is not running."
PEAK=0
fi
sleep ${INTERVAL}
done

View File

@@ -0,0 +1,69 @@
[ndm-agent]
directory = ${EXEM_NDM_HOME}/log
filename = ndm-agent.log
output_type = stdout,file
#file_permission = <permission>
#xmlogger_ip = <xmlogger ip>
#xmlogger_port = <xmlogger port>
level = info
include_us_in_time = true
header_flag = time,pid,thread_id,level
#limit_file_size = <megabyte>
#backup_directory = <backup directory>
backup_file_count = 10
[syslog]
directory = ${EXEM_NDM_HOME}/log
filename = ndm-syslog.log
output_type = file
#file_permission = <permission>
#xmlogger_ip = <xmlogger ip>
#xmlogger_port = <xmlogger port>
level = info
include_us_in_time = true
header_flag = time
#limit_file_size = <megabyte>
#backup_directory = <backup directory>
#backup_file_count = <backup file count>
[syslog-dump]
directory = ${EXEM_NDM_HOME}/log/dump
filename = syslog.dump
output_type = file
#file_permission = <permission>
#xmlogger_ip = <xmlogger ip>
#xmlogger_port = <xmlogger port>
level = trace
include_us_in_time = true
header_flag = time
#limit_file_size = <megabyte>
#backup_directory = <backup directory>
#backup_file_count = <backup file count>
[snmp_trap]
directory = ${EXEM_NDM_HOME}/log
filename = ndm-snmptrap.log
output_type = file
#file_permission = <permission>
#xmlogger_ip = <xmlogger ip>
#xmlogger_port = <xmlogger port>
level = trace
include_us_in_time = true
header_flag = time
#limit_file_size = <megabyte>
#backup_directory = <backup directory>
#backup_file_count = <backup file count>
[snmp_trap-dump]
directory = ${EXEM_NDM_HOME}/log/dump
filename = snmptrap.dump
output_type = file
#file_permission = <permission>
#xmlogger_ip = <xmlogger ip>
#xmlogger_port = <xmlogger port>
level = trace
include_us_in_time = true
#header_flag = time,pid,level
#limit_file_size = 10
#backup_directory = <backup directory>
#backup_file_count = <backup file count>

View File

@@ -0,0 +1,7 @@
#!/bin/sh
# /lib64/libcrypto.so.10 -> libcrypto.so.1.0.2k
ln -s libcrypto.so.1.0.2k libcrypto.so.10
# /lib64/libssl.so.10 -> libssl.so.1.0.2k
ln -s libssl.so.1.0.2k libssl.so.10

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,7 @@
#!/bin/sh
# /lib64/libcrypto.so.10 -> libcrypto.so.1.0.2k
ln -s libcrypto.so.1.0.2k libcrypto.so.10
# /lib64/libssl.so.10 -> libssl.so.1.0.2k
ln -s libssl.so.1.0.2k libssl.so.10

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,2 @@
---
# handlers file for one_agent

View File

@@ -0,0 +1,52 @@
galaxy_info:
author: your name
description: your role description
company: your company (optional)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
min_ansible_version: 2.1
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

View File

@@ -0,0 +1,24 @@
---
- name: Create exemONE Agent Directory
ansible.builtin.file:
path: "{{ EXEM_HOME }}"
state: directory
mode: '0755'
- name: Copy exemONE Container-Agent File
# ansible.posix.synchronize:
ansible.builtin.copy:
src: "{{ role_path }}/files/container"
dest: "{{ EXEM_HOME }}"
- name: Create Agent Script
ansible.builtin.template:
src: "{{ item }}.j2"
dest: "{{ EXEM_HOME }}/container/script/binary_mode/{{ item }}"
mode: '0755'
with_items:
- start.sh
- stop.sh
- name: exem-container-agent start
ansible.builtin.shell: "nohup {{ EXEM_HOME }}/container/script/binary_mode/start.sh"

View File

@@ -0,0 +1,22 @@
---
- name: Create exemONE Agent Directory
ansible.builtin.file:
path: "{{ EXEM_HOME }}"
state: directory
mode: '0755'
- name: Copy exemONE Host-Agent File
ansible.builtin.copy:
src: "{{ role_path }}/files/host"
dest: "{{ EXEM_HOME }}"
mode: '0755'
- name: Install Start exemONE Host-Agent
ansible.builtin.shell: |
{{ EXEM_HOME }}/host/setup_exem-host-agent_1.2.10.1.bin {{ RECEIVER_ADDR }} {{ RECEIVER_PORT | default('9010') }}
args:
chdir: "{{ EXEM_HOME }}/host"
- name: exem-host-agent start and enable
ansible.builtin.shell: |
{{ EXEM_HOME }}/host/exem/host/start.sh

View File

@@ -0,0 +1,59 @@
---
- name: Create exemONE Agent Directory
ansible.builtin.file:
path: "{{ EXEM_HOME }}"
state: directory
mode: '0755'
- name: Copy exemONE Host-Agent File
ansible.builtin.copy:
src: "{{ role_path }}/files/host"
dest: "{{ EXEM_HOME }}"
- name: Create Agent Script
ansible.builtin.template:
src: "{{ item }}.j2"
dest: "{{ EXEM_HOME }}/host/script/{{ item }}"
mode: '0755'
with_items:
- binary_start.sh
- binary_stop.sh
- systemctl_stop.sh
- systemctl_enable.sh
- name: Create Service Script
ansible.builtin.template:
src: "{{ item }}.j2"
dest: "{{ EXEM_HOME }}/host/service/{{ item }}"
mode: '0755'
with_items:
- exem-host-agent
- exem-host-agent.service
- name: Move exem-host-agent Binary
ansible.builtin.copy:
src: "{{ EXEM_HOME }}/host/os_binary/exem-host-agent_linux-2.6-x86_64-64"
dest: "{{ EXEM_HOME }}/host/bin/exem-host-agent"
remote_src: yes
mode: '0755'
- name: Setting SELinux
ansible.builtin.shell: |
chcon -t bin_t {{ EXEM_HOME }}/host/script/binary_start.sh
chcon -R -t var_run_t {{ EXEM_HOME }}/host/data/
chcon -R -t var_run_t {{ EXEM_HOME }}/host/service/
- name: Create Symbolic link
ansible.builtin.file:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
state: link
loop:
- { src: "{{ EXEM_HOME }}/host/service/exem-host-agent.service", dest: /etc/systemd/system/exem-host-agent.service }
- { src: "{{ EXEM_HOME }}/host/service/exem-host-agent", dest: /usr/bin/exem-host-agent }
- name: exem-host-agent start and enable
ansible.builtin.service:
name: exem-host-agent
state: started
enabled: yes

View File

@@ -0,0 +1,18 @@
---
# - include_tasks: rsync.yml
# 더이상 사용하지 않는 task, 기존 synchronize 모듈을 copy 모듈로 변경
- include_tasks: host-agent.yml
when:
- agent_list | select('search', 'host-agent') | list | count > 0
- "'host_agent' in group_names"
- include_tasks: container-agent.yml
when:
- agent_list | select('search', 'container-agent') | list | count > 0
- "'container_agent' in group_names"
- include_tasks: ndm-agent.yml
when:
- agent_list | select('search', 'ndm-agent') | list | count > 0
- "'ndm_agent' in group_names"

View File

@@ -0,0 +1,38 @@
---
- name: Create exemONE Agent Directory
ansible.builtin.file:
path: "{{ EXEM_HOME }}"
state: directory
mode: '0755'
- name: Copy exemONE NDM-Agent File
# ansible.posix.synchronize:
ansible.builtin.copy:
src: "{{ role_path }}/files/ndm"
dest: "{{ EXEM_HOME }}"
- name: Create Agent Script
ansible.builtin.template:
src: "{{ item }}.j2"
dest: "{{ EXEM_HOME }}/ndm/bin/{{ item }}"
mode: '0740'
with_items:
- ndm-ctl
- ndm-svc
- reg.env
- start
- stop
- name: Create Agent Conf
ansible.builtin.template:
src: "{{ item }}.j2"
dest: "{{ EXEM_HOME }}/ndm/conf/{{ item }}"
mode: '0755'
with_items:
- ndm.conf
- name: chmod change
ansible.builtin.shell: "chmod -R 740 {{ EXEM_HOME }}/ndm"
- name: exem-ndm-agent start
ansible.builtin.shell: "nohup {{ EXEM_HOME }}/ndm/bin/start"

View File

@@ -0,0 +1,39 @@
---
- name: Create exemONE Agent Directory
ansible.builtin.file:
path: "{{ EXEM_HOME }}"
state: directory
mode: '0755'
- name: Copy rsync install rpm OS - 7
ansible.builtin.copy:
src: "{{ role_path }}/files/rpm/rhel7.rpm"
dest: "{{ EXEM_HOME }}/rhel7.rpm"
mode: '0755'
when: ansible_distribution_major_version == '7'
- name: install rsync os version 7
ansible.builtin.shell: "yum localinstall -y {{ EXEM_HOME }}/rhel7.rpm"
when: ansible_distribution_major_version == '7'
- name: Copy rsync install rpm OS - 8
ansible.builtin.copy:
src: "{{ role_path }}/files/rpm/rhel8.rpm"
dest: "{{ EXEM_HOME }}/rhel8.rpm"
mode: '0755'
when: ansible_distribution_major_version == '8'
- name: install rsync os version 8
ansible.builtin.shell: "yum localinstall -y {{ EXEM_HOME }}/rhel8.rpm"
when: ansible_distribution_major_version == '8'
- name: Copy rsync install rpm OS - 9
ansible.builtin.copy:
src: "{{ role_path }}/files/rpm/rhel9.rpm"
dest: "{{ EXEM_HOME }}/rhel9.rpm"
mode: '0755'
when: ansible_distribution_major_version == '9'
- name: install rsync os version 9
ansible.builtin.shell: "yum localinstall -y {{ EXEM_HOME }}/rhel9.rpm"
when: ansible_distribution_major_version == '9'

View File

@@ -0,0 +1,26 @@
#!/bin/sh
# EXPORT
export EXEM_HOME={{ EXEM_HOME }}
export EXEM_HOST_HOME={{ EXEM_HOME }}/host
export RECEIVER_ADDR={{ RECEIVER_ADDR }}:{{ RECEIVER_PORT | default('9010') }}
# START
PIDFILE=${EXEM_HOST_HOME}/data/host_agent_pid
if [ -f "${PIDFILE}" ]; then
PID=$(echo -n | cat ${PIDFILE})
IS_RUNNING=$(ps -fp "${PID}" | grep -c exem-host-agent)
if [ "${IS_RUNNING}" -ne 0 ]; then
echo "exem-host-agent is already running (${PID})"
exit
fi
fi
chmod 755 ${EXEM_HOST_HOME}/bin/exem-host-agent
ulimit -n 1024
${EXEM_HOST_HOME}/bin/exem-host-agent -D

View File

@@ -0,0 +1,39 @@
#!/bin/sh
# EXPORT
export EXEM_HOME={{ EXEM_HOME }}
export EXEM_HOST_HOME={{ EXEM_HOME }}/host
# STOP
PIDFILE=${EXEM_HOST_HOME}/data/host_agent_pid
if [ -f "${PIDFILE}" ]; then
PID=$(echo -n | cat ${PIDFILE})
mv ${PIDFILE} ${PIDFILE}.stopped
# WAITING
LIMIT_CNT=10
CNT=0
while [ ${CNT} -lt ${LIMIT_CNT} ];
do
IS_RUNNING=$(ps -fp "${PID}" | grep -c exem-host-agent)
if [ "${IS_RUNNING}" -ne 0 ]; then
CNT=$((CNT+1))
echo "exem-host-agent is stopping (${PID}) ..."
sleep 1
else
break
fi
done
if [ ${CNT} -ge ${LIMIT_CNT} ]; then
echo "Something is wrong. Check exem-host-agent (${PID})"
exit 1
fi
echo "exem-host-agent is stopped (${PID})"
else
echo "exem-host-agent is not running"
fi

View File

@@ -0,0 +1,29 @@
#!/bin/bash
# Startup script for exemONE exem-host-agent
# chkconfig: 345 50 50
# description: exemONE exem-host-agent
# processname: exem-host-agent
# directory : EXEM_HOST_HOME={{ EXEM_HOME }}
source /etc/profile
case "$1" in
start)
echo "Starting exem-host-agent: "
{{ EXEM_HOME }}/host/script/binary_start.sh
;;
stop)
echo "Shutting down exem-host-agent: "
{{ EXEM_HOME }}/host/script/binary_stop.sh
;;
restart)
echo "Restarting exem-host-agent: "
{{ EXEM_HOME }}/host/script/binary_stop.sh
{{ EXEM_HOME }}/host/script/binary_start.sh
;;
*)
echo "Usage: service exem-host-agent { start | stop | restart }"
exit 1
esac
exit 0

View File

@@ -0,0 +1,15 @@
[Unit]
Description=exem-host-agent
Wants=network-online.target
After=network-online.target
[Service]
Type=forking
PIDFile={{ EXEM_HOME }}/host/data/host_agent_pid
ExecStart={{ EXEM_HOME }}/host/script/binary_start.sh
ExecStartPost=/bin/sleep 1
Restart=on-failure
RestartSec=10
[Install]
WantedBy=default.target

View File

@@ -0,0 +1,198 @@
#!/bin/sh
#EXEM_NDM_HOME="/{{ EXEM_HOME }}/ndm"
source /{{ EXEM_HOME }}/ndm/bin/reg.env
NDM_STOP_TIMEOUT=10
Usage()
{
echo "Usage : ndm-ctl [version|start|restart|stop]"
echo ""
exit $1
}
CMD_ARGUMENT=$@
BASE_NAME=`basename $0`
case "${BASE_NAME}" in
start)
CMD_ARGUMENT="start"
;;
stop)
CMD_ARGUMENT="stop"
;;
restart)
CMD_ARGUMENT="restart"
;;
version)
CMD_ARGUMENT="version"
;;
mongomonctl)
;;
*)
echo "unknown link. please check link name[$0]."
Usage 1
;;
esac
# option process
if [ -n "${CMD_ARGUMENT}" ];
then
for i in ${CMD_ARGUMENT}
do
# echo "$i"
case "$i" in
start)
ENV_RUN_MODE="start"
RUN_LIST="start"
;;
restart)
ENV_RUN_MODE="restart"
RUN_LIST="stop start"
;;
stop)
ENV_RUN_MODE="stop"
RUN_LIST="stop"
;;
version)
ENV_RUN_MODE="version"
RUN_LIST="version"
;;
help)
Usage 0
;;
*)
Usage 1
;;
esac
done
fi
if [ ! -d "${EXEM_NDM_HOME}" ];then
echo "agent home directory is not exist.[${EXEM_NDM_HOME}]"
exit 1
fi
cd ${EXEM_NDM_HOME} || exit 1
PROCESS_NAME="exem-ndm-agent"
SVC_FILE="ndm-svc"
SVC_PID_FILE="data/svc.pid"
AGENT_PID_FILE="data/ndm-agent.pid"
echo "${PROCESS_NAME} ${ENV_RUN_MODE} --- "
for MODE in ${RUN_LIST}; do
case "${MODE}" in
version)
bin/exem-ndm-agent -v
;;
start)
if [ -f "${SVC_PID_FILE}" ];then
SVC_PID=`cat ${SVC_PID_FILE}`
PROC_COMM=`cat /proc/${SVC_PID}/comm`
if [ $? -ne 0 ];then
PROC_COMM="none"
fi
if [ "${PROC_COMM}" = "${SVC_FILE}" ];then
echo "${PROCESS_NAME} is running."
exit 1
fi
rm -rf ${SVC_PID_FILE}
fi
if [ ! -f "bin/${SVC_FILE}" ];then
echo "bin/${SVC_FILE} is not exist."
exit 2
fi
bin/${SVC_FILE} >> ${EXEM_NDM_HOME}/log/svc.log 2>&1 &
# bin/${SVC_FILE} > /dev/null 2>&1 &
SVC_PID="$!"
echo "SVC_PID[${SVC_PID}]"
echo "${SVC_PID}" > ${SVC_PID_FILE}
;;
stop)
SVC_PID=`cat ${SVC_PID_FILE}`
if [ $? -ne 0 ] || [ "${SVC_PID}" = "" ];then
echo "${PROCESS_NAME} Service is not running."
exit 1
fi
PS_SVC_PID=`ps -ef | grep -v grep | grep ${SVC_PID} | grep ${SVC_FILE}`
if [ ! "${PS_SVC_PID}" = "" ];then
kill -9 ${SVC_PID}
echo "${PROCESS_NAME} Service terminate."
else
echo "${PROCESS_NAME} Service pid is not match[${PS_SVC_PID}/${SVC_PID}]"
fi
rm -rf ${SVC_PID_FILE}
if [ -f "${AGENT_PID_FILE}" ];then
RUN_NDM_PID=`cat ${AGENT_PID_FILE} | tr '\0' '\n'`
rm -rf ${AGENT_PID_FILE}
echo -n "Waiting for ${PROCESS_NAME} process(${RUN_NDM_PID}) exit."
NUM="0"
while [ ${NUM} -lt ${NDM_STOP_TIMEOUT} ]
do
PS_NDM_PID=`ps -ef | grep -v grep | grep ${RUN_NDM_PID} | grep mongomon`
if [ "${PS_NDM_PID}" = "" ];then
break
fi
NUM=`expr ${NUM} + 1`
sleep 1
echo -n "."
done
echo ""
if [ ${NUM} -eq ${NDM_STOP_TIMEOUT} ];then
echo "${PROCESS_NAME} process shutdown wait timed out."
else
echo "${PROCESS_NAME} process terminated."
fi
else
echo "${PROCESS_NAME} process is not running."
fi
;;
*)
Usage 2
;;
esac
done

View File

@@ -0,0 +1,125 @@
#!/bin/sh
source /{{ EXEM_HOME }}/ndm/bin/reg.env
#source /root/test2/bin/reg.env
func_check_log_file()
{
LOG_CHK_SIZE=1048576
if [ -n "$2" ];then
LOG_CHK_SIZE=$2
fi
if [ -f "$1" ];then
LOG_SIZE=`ls -la $1 | awk -F' ' '{print $5}'`
if [ $? -eq 0 ]; then
if [ ${LOG_SIZE} -gt ${LOG_CHK_SIZE} ]; then
rm -rf $1
# echo "log size is over. remove log file.[size:${LOG_SIZE},file:$1]"
fi
fi
fi
}
PROCESS_NAME="exem-ndm-agent"
PROCESS_PATH="${PROCESS_NAME}"
PID_FILE="ndm-agent.pid"
if [ ! -d "${EXEM_NDM_HOME}" ];then
echo "exem ndm home directory is not exist.[${EXEM_NDM_HOME}]"
exit 1
fi
# working directory is ${EXEM_NDM_HOME}/bin
cd ${EXEM_NDM_HOME} || exit 1
if [ -f "${EXEM_NDM_HOME}/data/${PID_FILE}" ]; then
RUN_PID=`cat ${EXEM_NDM_HOME}/data/${PID_FILE} | tr '\0' '\n' || echo "none"`
else
RUN_PID="none"
fi
PEAK=0
while :
do
# log manage
func_check_log_file "${EXEM_NDM_HOME}/log/svc.log" 1048576
if [ "${RUN_PID}" = "none" ];then
PATH=${EXEM_NDM_HOME}/bin:$PATH ${PROCESS_PATH} > /dev/null 2>&1 &
RUN_PID="$!"
echo "execute ${PROCESS_PATH} process.[${RUN_PID}]"
sleep 3
fi
if [ ! "${RUN_PID}" = "none" ] && [ -f "/proc/${RUN_PID}/cmdline" ];then
# PROC_COMM=`cat /proc/${RUN_PID}/comm || echo "none"`
PROC_COMM=`cat /proc/${RUN_PID}/cmdline | tr '\0' ' ' | awk -F' ' '{print $1}' || echo "none"`
# echo "PROC_COMM[${PROC_COMM}]"
else
PROC_COMM="none"
fi
if [ ! "${PROC_COMM}" = "${PROCESS_PATH}" ];then
echo "${PROCESS_NAME} process is not running.[pid:${RUN_PID}],comm[${PROC_COMM}]"
RUN_PID="none"
fi
##########################################
# check memory peak
CUR_DATE=`date +%d' '%H:%M:%S`
# MONGOMON_PID=`ps -ef | grep -v grep | grep -v vi | grep -v tail | grep -v ctl | grep -v svc | grep ${PROCESS_NAME} | awk -F' ' '{print $2}'`
# if [ -n "${MONGOMON_PID}" ];then
if [ ! "${RUN_PID}" = "none" ];then
# RESULT=`ps -p ${RUN_PID} -o user,pid,pcpu,pmem,rss,sz,size,vsize,cmd --no-heading`
RESULT=`ps -p ${RUN_PID} -o user,pid,pcpu,pmem,rss,sz,size,vsize,cmd --no-heading`
if [ -z "${RESULT}" ];then
echo "${CUR_DATE} get process stat has failed.[${RUN_PID}]"
PEAK=0
fi
RSS=`echo ${RESULT} | awk -F' ' '{print $5}'`
if [ ${RSS} -gt ${PEAK} ];then
OUT_PEAK=" PEAK:${PEAK}/${RSS}"
PEAK=${RSS}
PEAK_STAT="peak"
else
OUT_PEAK=" PEAK:${PEAK}"
PEAK_STAT=""
fi
# echo "${CUR_DATE} ${RESULT}${OUT_PEAK}"
if [ -n "${PEAK_STAT}" ];then
func_check_log_file "peak.log" 1024
echo "${CUR_DATE} ${RESULT}${OUT_PEAK}" >> peak.log
fi
else
echo "${CUR_DATE} ${PROCESS_NAME} is not running."
PEAK=0
fi
sleep 3
done

View File

@@ -0,0 +1,13 @@
#app_name="exem-ndm-agent"
receiver_ip={{ RECEIVER_ADDR }}
receiver_port={{ RECEIVER_PORT | default('9010') }}
#disconnect_exit=no
#syslog_port=514
#snmptrap_port=162
[Debug]
#write_recv_packet=no
#write_send_packet=no

View File

@@ -0,0 +1,9 @@
export EXEM_NDM_HOME=/{{ EXEM_HOME }}/ndm
if [ -z ${LD_LIBRARY_PATH} ];then
LD_LIBRARY_PATH=${EXEM_NDM_HOME}/lib64
else
LD_LIBRARY_PATH=${EXEM_NDM_HOME}/lib64:${LD_LIBRARY_PATH}
fi
export LD_LIBRARY_PATH

View File

@@ -0,0 +1,198 @@
#!/bin/sh
#EXEM_NDM_HOME="/{{ EXEM_HOME }}/ndm"
source /{{ EXEM_HOME }}/ndm/bin/reg.env
NDM_STOP_TIMEOUT=10
Usage()
{
echo "Usage : ndm-ctl [version|start|restart|stop]"
echo ""
exit $1
}
CMD_ARGUMENT=$@
BASE_NAME=`basename $0`
case "${BASE_NAME}" in
start)
CMD_ARGUMENT="start"
;;
stop)
CMD_ARGUMENT="stop"
;;
restart)
CMD_ARGUMENT="restart"
;;
version)
CMD_ARGUMENT="version"
;;
mongomonctl)
;;
*)
echo "unknown link. please check link name[$0]."
Usage 1
;;
esac
# option process
if [ -n "${CMD_ARGUMENT}" ];
then
for i in ${CMD_ARGUMENT}
do
# echo "$i"
case "$i" in
start)
ENV_RUN_MODE="start"
RUN_LIST="start"
;;
restart)
ENV_RUN_MODE="restart"
RUN_LIST="stop start"
;;
stop)
ENV_RUN_MODE="stop"
RUN_LIST="stop"
;;
version)
ENV_RUN_MODE="version"
RUN_LIST="version"
;;
help)
Usage 0
;;
*)
Usage 1
;;
esac
done
fi
if [ ! -d "${EXEM_NDM_HOME}" ];then
echo "agent home directory is not exist.[${EXEM_NDM_HOME}]"
exit 1
fi
cd ${EXEM_NDM_HOME} || exit 1
PROCESS_NAME="exem-ndm-agent"
SVC_FILE="ndm-svc"
SVC_PID_FILE="data/svc.pid"
AGENT_PID_FILE="data/ndm-agent.pid"
echo "${PROCESS_NAME} ${ENV_RUN_MODE} --- "
for MODE in ${RUN_LIST}; do
case "${MODE}" in
version)
bin/exem-ndm-agent -v
;;
start)
if [ -f "${SVC_PID_FILE}" ];then
SVC_PID=`cat ${SVC_PID_FILE}`
PROC_COMM=`cat /proc/${SVC_PID}/comm`
if [ $? -ne 0 ];then
PROC_COMM="none"
fi
if [ "${PROC_COMM}" = "${SVC_FILE}" ];then
echo "${PROCESS_NAME} is running."
exit 1
fi
rm -rf ${SVC_PID_FILE}
fi
if [ ! -f "bin/${SVC_FILE}" ];then
echo "bin/${SVC_FILE} is not exist."
exit 2
fi
bin/${SVC_FILE} >> ${EXEM_NDM_HOME}/log/svc.log 2>&1 &
# bin/${SVC_FILE} > /dev/null 2>&1 &
SVC_PID="$!"
echo "SVC_PID[${SVC_PID}]"
echo "${SVC_PID}" > ${SVC_PID_FILE}
;;
stop)
SVC_PID=`cat ${SVC_PID_FILE}`
if [ $? -ne 0 ] || [ "${SVC_PID}" = "" ];then
echo "${PROCESS_NAME} Service is not running."
exit 1
fi
PS_SVC_PID=`ps -ef | grep -v grep | grep ${SVC_PID} | grep ${SVC_FILE}`
if [ ! "${PS_SVC_PID}" = "" ];then
kill -9 ${SVC_PID}
echo "${PROCESS_NAME} Service terminate."
else
echo "${PROCESS_NAME} Service pid is not match[${PS_SVC_PID}/${SVC_PID}]"
fi
rm -rf ${SVC_PID_FILE}
if [ -f "${AGENT_PID_FILE}" ];then
RUN_NDM_PID=`cat ${AGENT_PID_FILE} | tr '\0' '\n'`
rm -rf ${AGENT_PID_FILE}
echo -n "Waiting for ${PROCESS_NAME} process(${RUN_NDM_PID}) exit."
NUM="0"
while [ ${NUM} -lt ${NDM_STOP_TIMEOUT} ]
do
PS_NDM_PID=`ps -ef | grep -v grep | grep ${RUN_NDM_PID} | grep mongomon`
if [ "${PS_NDM_PID}" = "" ];then
break
fi
NUM=`expr ${NUM} + 1`
sleep 1
echo -n "."
done
echo ""
if [ ${NUM} -eq ${NDM_STOP_TIMEOUT} ];then
echo "${PROCESS_NAME} process shutdown wait timed out."
else
echo "${PROCESS_NAME} process terminated."
fi
else
echo "${PROCESS_NAME} process is not running."
fi
;;
*)
Usage 2
;;
esac
done

View File

@@ -0,0 +1,26 @@
#!/bin/sh
# EXPORT
export EXEM_HOME={{ EXEM_HOME }}
export EXEM_CONTAINER_HOME={{ EXEM_HOME }}/container
export COMMON_RECEIVER_IP={{ RECEIVER_ADDR }}
export COMMON_RECEIVER_PORT={{ RECEIVER_CONTAINER_PORT | default('9009') }}
export CONTAINER_LOG_LEVEL=info
# START
PIDFILE=${EXEM_CONTAINER_HOME}/data/container_agent_pid
if [ -f "${PIDFILE}" ]; then
PID=$(echo -n | cat ${PIDFILE})
IS_RUNNING=$(ps -fp "${PID}" | grep -c exem-container-agent)
if [ "${IS_RUNNING}" -ne 0 ]; then
echo "exem-container-agent is already running (${PID})"
exit
fi
fi
chmod 755 ${EXEM_CONTAINER_HOME}/bin/exem-container-agent
${EXEM_CONTAINER_HOME}/bin/exem-container-agent run

View File

@@ -0,0 +1,198 @@
#!/bin/sh
#EXEM_NDM_HOME="/{{ EXEM_HOME }}/ndm"
source /{{ EXEM_HOME }}/ndm/bin/reg.env
NDM_STOP_TIMEOUT=10
Usage()
{
echo "Usage : ndm-ctl [version|start|restart|stop]"
echo ""
exit $1
}
CMD_ARGUMENT=$@
BASE_NAME=`basename $0`
case "${BASE_NAME}" in
start)
CMD_ARGUMENT="start"
;;
stop)
CMD_ARGUMENT="stop"
;;
restart)
CMD_ARGUMENT="restart"
;;
version)
CMD_ARGUMENT="version"
;;
mongomonctl)
;;
*)
echo "unknown link. please check link name[$0]."
Usage 1
;;
esac
# option process
if [ -n "${CMD_ARGUMENT}" ];
then
for i in ${CMD_ARGUMENT}
do
# echo "$i"
case "$i" in
start)
ENV_RUN_MODE="start"
RUN_LIST="start"
;;
restart)
ENV_RUN_MODE="restart"
RUN_LIST="stop start"
;;
stop)
ENV_RUN_MODE="stop"
RUN_LIST="stop"
;;
version)
ENV_RUN_MODE="version"
RUN_LIST="version"
;;
help)
Usage 0
;;
*)
Usage 1
;;
esac
done
fi
if [ ! -d "${EXEM_NDM_HOME}" ];then
echo "agent home directory is not exist.[${EXEM_NDM_HOME}]"
exit 1
fi
cd ${EXEM_NDM_HOME} || exit 1
PROCESS_NAME="exem-ndm-agent"
SVC_FILE="ndm-svc"
SVC_PID_FILE="data/svc.pid"
AGENT_PID_FILE="data/ndm-agent.pid"
echo "${PROCESS_NAME} ${ENV_RUN_MODE} --- "
for MODE in ${RUN_LIST}; do
case "${MODE}" in
version)
bin/exem-ndm-agent -v
;;
start)
if [ -f "${SVC_PID_FILE}" ];then
SVC_PID=`cat ${SVC_PID_FILE}`
PROC_COMM=`cat /proc/${SVC_PID}/comm`
if [ $? -ne 0 ];then
PROC_COMM="none"
fi
if [ "${PROC_COMM}" = "${SVC_FILE}" ];then
echo "${PROCESS_NAME} is running."
exit 1
fi
rm -rf ${SVC_PID_FILE}
fi
if [ ! -f "bin/${SVC_FILE}" ];then
echo "bin/${SVC_FILE} is not exist."
exit 2
fi
bin/${SVC_FILE} >> ${EXEM_NDM_HOME}/log/svc.log 2>&1 &
# bin/${SVC_FILE} > /dev/null 2>&1 &
SVC_PID="$!"
echo "SVC_PID[${SVC_PID}]"
echo "${SVC_PID}" > ${SVC_PID_FILE}
;;
stop)
SVC_PID=`cat ${SVC_PID_FILE}`
if [ $? -ne 0 ] || [ "${SVC_PID}" = "" ];then
echo "${PROCESS_NAME} Service is not running."
exit 1
fi
PS_SVC_PID=`ps -ef | grep -v grep | grep ${SVC_PID} | grep ${SVC_FILE}`
if [ ! "${PS_SVC_PID}" = "" ];then
kill -9 ${SVC_PID}
echo "${PROCESS_NAME} Service terminate."
else
echo "${PROCESS_NAME} Service pid is not match[${PS_SVC_PID}/${SVC_PID}]"
fi
rm -rf ${SVC_PID_FILE}
if [ -f "${AGENT_PID_FILE}" ];then
RUN_NDM_PID=`cat ${AGENT_PID_FILE} | tr '\0' '\n'`
rm -rf ${AGENT_PID_FILE}
echo -n "Waiting for ${PROCESS_NAME} process(${RUN_NDM_PID}) exit."
NUM="0"
while [ ${NUM} -lt ${NDM_STOP_TIMEOUT} ]
do
PS_NDM_PID=`ps -ef | grep -v grep | grep ${RUN_NDM_PID} | grep mongomon`
if [ "${PS_NDM_PID}" = "" ];then
break
fi
NUM=`expr ${NUM} + 1`
sleep 1
echo -n "."
done
echo ""
if [ ${NUM} -eq ${NDM_STOP_TIMEOUT} ];then
echo "${PROCESS_NAME} process shutdown wait timed out."
else
echo "${PROCESS_NAME} process terminated."
fi
else
echo "${PROCESS_NAME} process is not running."
fi
;;
*)
Usage 2
;;
esac
done

View File

@@ -0,0 +1,39 @@
#!/bin/sh
# EXPORT
export EXEM_HOME={{ EXEM_HOME }}
export EXEM_CONTAINER_HOME={{ EXEM_HOME }}/container
# STOP
PIDFILE=${EXEM_CONTAINER_HOME}/data/container_agent_pid
if [ -f "${PIDFILE}" ]; then
PID=$(echo -n | cat ${PIDFILE})
mv ${PIDFILE} ${PIDFILE}.stopped
# WAITING
LIMIT_CNT=10
CNT=0
while [ ${CNT} -lt ${LIMIT_CNT} ];
do
IS_RUNNING=$(ps -fp "${PID}" | grep -c exem-container-agent)
if [ "${IS_RUNNING}" -ne 0 ]; then
CNT=$((CNT+1))
echo "exem-container-agent is stopping (${PID}) ..."
sleep 1
else
break
fi
done
if [ ${CNT} -ge ${LIMIT_CNT} ]; then
echo "Something is wrong. Check exem-container-agent (${PID})"
exit 1
fi
echo "exem-container-agent is stopped (${PID})"
else
echo "exem-container-agent is not running"
fi

View File

@@ -0,0 +1,32 @@
#!/bin/sh
SYSTEMCTL=$(which systemctl 2> /dev/null)
SERVICE=$(which service 2> /dev/null)
CHKCONFIG=$(which chkconfig 2> /dev/null)
if [ "$(id -u)" -ne 0 ]; then
echo "Not a root user. Not support service registration"
echo "Use binary mode"
exit 1
fi
if [ -n "${SYSTEMCTL}" ]; then
# SELinux setting
chcon -t bin_t {{ EXEM_HOME }}/host/script/binary_start.sh
chcon -R -t var_run_t {{ EXEM_HOME }}/host/data
chcon -R -t var_run_t {{ EXEM_HOME }}/host/service
if [ ! -e "/etc/systemd/system/exem-host-agent.service" ]; then
systemctl enable {{ EXEM_HOME }}/host/service/exem-host-agent.service
fi
systemctl daemon-reload
echo "exem-host-agent is enabled"
else
echo "this OS version that does not support service registration"
echo "Use binary mode"
exit 1
fi

View File

@@ -0,0 +1,5 @@
#!/bin/sh
sudo {{ EXEM_HOME }}/host/script/binary_stop.sh
sudo systemctl stop exem-host-agent

View File

@@ -0,0 +1,2 @@
localhost

View File

@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- one_agent

View File

@@ -0,0 +1,2 @@
---
# vars file for one_agent

View File

@@ -3,7 +3,7 @@ host_agent
container_agent container_agent
[host_agent] [host_agent]
10.10.55.102 10.10.55.109 ansible_user=root
[container_agent] [container_agent]