commit 62999578d9008b52ba20cbff5abb4f65539f9fe2 Author: ByeonJungHun Date: Fri Mar 15 13:14:57 2024 +0900 exemONE Agent Installer 작성 diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..befb646 Binary files /dev/null and b/.DS_Store differ diff --git a/agent.yml b/agent.yml new file mode 100644 index 0000000..a5e3349 --- /dev/null +++ b/agent.yml @@ -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'] \ No newline at end of file diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..3480d3f --- /dev/null +++ b/ansible.cfg @@ -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 \ No newline at end of file diff --git a/inventory b/inventory new file mode 100644 index 0000000..2655f87 --- /dev/null +++ b/inventory @@ -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 \ No newline at end of file diff --git a/roles/.DS_Store b/roles/.DS_Store new file mode 100644 index 0000000..6faba1d Binary files /dev/null and b/roles/.DS_Store differ diff --git a/roles/one_agent/.DS_Store b/roles/one_agent/.DS_Store new file mode 100644 index 0000000..8fe2d0c Binary files /dev/null and b/roles/one_agent/.DS_Store differ diff --git a/roles/one_agent/README.md b/roles/one_agent/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/one_agent/README.md @@ -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). diff --git a/roles/one_agent/defaults/main.yml b/roles/one_agent/defaults/main.yml new file mode 100644 index 0000000..88ad63d --- /dev/null +++ b/roles/one_agent/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for one_agent diff --git a/roles/one_agent/files/.DS_Store b/roles/one_agent/files/.DS_Store new file mode 100644 index 0000000..030d20c Binary files /dev/null and b/roles/one_agent/files/.DS_Store differ diff --git a/roles/one_agent/files/container/bin/exem-container-agent b/roles/one_agent/files/container/bin/exem-container-agent new file mode 100755 index 0000000..25ccf3a Binary files /dev/null and b/roles/one_agent/files/container/bin/exem-container-agent differ diff --git a/roles/one_agent/files/host/os_binary/exem-host-agent_linux-2.6-x86_64-64 b/roles/one_agent/files/host/os_binary/exem-host-agent_linux-2.6-x86_64-64 new file mode 100755 index 0000000..ba10ff5 Binary files /dev/null and b/roles/one_agent/files/host/os_binary/exem-host-agent_linux-2.6-x86_64-64 differ diff --git a/roles/one_agent/files/host/script/service_start.sh b/roles/one_agent/files/host/script/service_start.sh new file mode 100755 index 0000000..7751a43 --- /dev/null +++ b/roles/one_agent/files/host/script/service_start.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +service exem-host-agent start diff --git a/roles/one_agent/files/host/script/service_stop.sh b/roles/one_agent/files/host/script/service_stop.sh new file mode 100755 index 0000000..dc13cc0 --- /dev/null +++ b/roles/one_agent/files/host/script/service_stop.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +service exem-host-agent stop diff --git a/roles/one_agent/files/host/script/systemctl_start.sh b/roles/one_agent/files/host/script/systemctl_start.sh new file mode 100755 index 0000000..5e7cbd6 --- /dev/null +++ b/roles/one_agent/files/host/script/systemctl_start.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +sudo systemctl start exem-host-agent diff --git a/roles/one_agent/files/rpm/rhel7.rpm b/roles/one_agent/files/rpm/rhel7.rpm new file mode 100755 index 0000000..bc2457d Binary files /dev/null and b/roles/one_agent/files/rpm/rhel7.rpm differ diff --git a/roles/one_agent/files/rpm/rhel8.rpm b/roles/one_agent/files/rpm/rhel8.rpm new file mode 100755 index 0000000..ad6c9e3 Binary files /dev/null and b/roles/one_agent/files/rpm/rhel8.rpm differ diff --git a/roles/one_agent/files/rpm/rhel9.rpm b/roles/one_agent/files/rpm/rhel9.rpm new file mode 100755 index 0000000..34924af Binary files /dev/null and b/roles/one_agent/files/rpm/rhel9.rpm differ diff --git a/roles/one_agent/handlers/main.yml b/roles/one_agent/handlers/main.yml new file mode 100644 index 0000000..6c99927 --- /dev/null +++ b/roles/one_agent/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for one_agent diff --git a/roles/one_agent/meta/main.yml b/roles/one_agent/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/roles/one_agent/meta/main.yml @@ -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. diff --git a/roles/one_agent/tasks/container-agent.yml b/roles/one_agent/tasks/container-agent.yml new file mode 100644 index 0000000..c755d7e --- /dev/null +++ b/roles/one_agent/tasks/container-agent.yml @@ -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" \ No newline at end of file diff --git a/roles/one_agent/tasks/host-agent.yml b/roles/one_agent/tasks/host-agent.yml new file mode 100644 index 0000000..d8052f8 --- /dev/null +++ b/roles/one_agent/tasks/host-agent.yml @@ -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 \ No newline at end of file diff --git a/roles/one_agent/tasks/main.yml b/roles/one_agent/tasks/main.yml new file mode 100644 index 0000000..626ac65 --- /dev/null +++ b/roles/one_agent/tasks/main.yml @@ -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" + diff --git a/roles/one_agent/tasks/rsync.yml b/roles/one_agent/tasks/rsync.yml new file mode 100644 index 0000000..23ef790 --- /dev/null +++ b/roles/one_agent/tasks/rsync.yml @@ -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' \ No newline at end of file diff --git a/roles/one_agent/templates/binary_start.sh.j2 b/roles/one_agent/templates/binary_start.sh.j2 new file mode 100644 index 0000000..d7afb23 --- /dev/null +++ b/roles/one_agent/templates/binary_start.sh.j2 @@ -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 \ No newline at end of file diff --git a/roles/one_agent/templates/binary_stop.sh.j2 b/roles/one_agent/templates/binary_stop.sh.j2 new file mode 100644 index 0000000..40e9bef --- /dev/null +++ b/roles/one_agent/templates/binary_stop.sh.j2 @@ -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 diff --git a/roles/one_agent/templates/exem-host-agent.j2 b/roles/one_agent/templates/exem-host-agent.j2 new file mode 100644 index 0000000..981f12d --- /dev/null +++ b/roles/one_agent/templates/exem-host-agent.j2 @@ -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 diff --git a/roles/one_agent/templates/exem-host-agent.service.j2 b/roles/one_agent/templates/exem-host-agent.service.j2 new file mode 100644 index 0000000..825665f --- /dev/null +++ b/roles/one_agent/templates/exem-host-agent.service.j2 @@ -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 diff --git a/roles/one_agent/templates/start.sh.j2 b/roles/one_agent/templates/start.sh.j2 new file mode 100644 index 0000000..4a8822e --- /dev/null +++ b/roles/one_agent/templates/start.sh.j2 @@ -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 \ No newline at end of file diff --git a/roles/one_agent/templates/stop.sh.j2 b/roles/one_agent/templates/stop.sh.j2 new file mode 100644 index 0000000..548c64c --- /dev/null +++ b/roles/one_agent/templates/stop.sh.j2 @@ -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 \ No newline at end of file diff --git a/roles/one_agent/templates/systemctl_stop.sh.j2 b/roles/one_agent/templates/systemctl_stop.sh.j2 new file mode 100644 index 0000000..f430dfc --- /dev/null +++ b/roles/one_agent/templates/systemctl_stop.sh.j2 @@ -0,0 +1,5 @@ +#!/bin/sh + +sudo {{ EXEM_HOME }}/host/script/binary_stop.sh + +sudo systemctl stop exem-host-agent \ No newline at end of file diff --git a/roles/one_agent/tests/inventory b/roles/one_agent/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/one_agent/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/one_agent/tests/test.yml b/roles/one_agent/tests/test.yml new file mode 100644 index 0000000..1c2b31c --- /dev/null +++ b/roles/one_agent/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - one_agent diff --git a/roles/one_agent/vars/main.yml b/roles/one_agent/vars/main.yml new file mode 100644 index 0000000..fdba859 --- /dev/null +++ b/roles/one_agent/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for one_agent