exemONE Agent Installer 작성

This commit is contained in:
ByeonJungHun
2024-03-15 13:14:57 +09:00
commit 62999578d9
33 changed files with 461 additions and 0 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

14
agent.yml Normal file
View File

@@ -0,0 +1,14 @@
---
- 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']

8
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

10
inventory Normal file
View File

@@ -0,0 +1,10 @@
[all:children]
host_agent
container_agent
[host_agent]
10.10.54.150
10.10.54.105
[container_agent]
10.10.54.105

BIN
roles/.DS_Store vendored Normal file

Binary file not shown.

BIN
roles/one_agent/.DS_Store vendored Normal file

Binary file not shown.

38
roles/one_agent/README.md Normal file
View File

@@ -0,0 +1,38 @@
Role Name
=========
A brief description of the role goes here.
Requirements
------------
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
Role Variables
--------------
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
Dependencies
------------
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
Example Playbook
----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
License
-------
BSD
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).

View File

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

BIN
roles/one_agent/files/.DS_Store vendored Normal file

Binary file not shown.

Binary file not shown.

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,3 @@
#!/bin/sh
sudo systemctl start exem-host-agent

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,23 @@
---
- name: Create exemONE Agent Directory
ansible.builtin.file:
path: "{{ EXEM_HOME }}"
state: directory
mode: '0755'
- name: Copy exemONE Container-Agent File
ansible.posix.synchronize:
src: "{{ role_path }}/files/container"
dest: "{{ EXEM_HOME }}"
- name: Create Agent Script
ansible.builtin.template:
src: "{{ item }}.j2"
dest: "{{ EXEM_HOME }}/container/{{ item }}"
mode: '0755'
with_items:
- start.sh
- stop.sh
- name: exem-container-agent start
ansible.builtin.shell: "{{ EXEM_HOME }}/container/start.sh"

View File

@@ -0,0 +1,57 @@
---
- name: Create exemONE Agent Directory
ansible.builtin.file:
path: "{{ EXEM_HOME }}"
state: directory
mode: '0755'
- name: Copy exemONE Host-Agent File
ansible.posix.synchronize:
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
- 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"
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,13 @@
---
- include_tasks: rsync.yml
- 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"

View File

@@ -0,0 +1,45 @@
---
- 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.yum:
name: "{{ EXEM_HOME }}/rhel7.rpm"
state: present
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.yum:
name: "{{ EXEM_HOME }}/rhel8.rpm"
state: present
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.yum:
name: "{{ role_path }}/files/rpm/rhel9.rpm"
state: present
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,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,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,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