This is an automated email from the ASF dual-hosted git repository.
kezhenxu94 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-terraform.git
The following commit(s) were added to refs/heads/main by this push:
new 71d3ed2 Add Ansible role for installing skywalking (#7)
71d3ed2 is described below
commit 71d3ed2820fd97b95bae1b47ee0a465cba16ed09
Author: Rahul Bajaj <[email protected]>
AuthorDate: Tue Jul 11 00:38:23 2023 -0400
Add Ansible role for installing skywalking (#7)
---
ansible/ansible.cfg | 1 +
.../install-skywalking.yml} | 26 ++++--
.../install-java/tasks/main.yml} | 18 ++--
ansible/roles/skywalking/tasks/main.yml | 96 ++++++++++++++++++++++
.../skywalking/templates/oap-service-stop.sh.j2} | 14 ++--
.../templates/skywalking-oap.service.j2} | 21 +++--
.../skywalking/templates/skywalking-ui.service.j2} | 18 ++--
.../skywalking/vars/main.yml} | 10 +--
8 files changed, 161 insertions(+), 43 deletions(-)
diff --git a/ansible/ansible.cfg b/ansible/ansible.cfg
index c11055e..6886e12 100644
--- a/ansible/ansible.cfg
+++ b/ansible/ansible.cfg
@@ -14,6 +14,7 @@
# limitations under the License.
[defaults]
+roles_path = roles/
inventory = inventory/
timeout = 60
diff --git a/ansible/ansible.cfg b/ansible/playbooks/install-skywalking.yml
similarity index 67%
copy from ansible/ansible.cfg
copy to ansible/playbooks/install-skywalking.yml
index c11055e..536e23e 100644
--- a/ansible/ansible.cfg
+++ b/ansible/playbooks/install-skywalking.yml
@@ -13,11 +13,23 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-[defaults]
-inventory = inventory/
-timeout = 60
+---
+- name: Install Java
+ hosts: skywalking-oap
+ gather_facts: true
+ roles:
+ - install-java
-[privilege_escalation]
-become = yes
-become_method = sudo
-become_flags = 'su -c'
+- name: Download and configure Apache SkyWalking APM OAP Service
+ hosts: skywalking-oap
+ gather_facts: false
+
+ roles:
+ - skywalking
+
+- name: Download and configure Apache SkyWalking APM UI Service
+ hosts: skywalking-ui
+ gather_facts: false
+
+ roles:
+ - skywalking
diff --git a/ansible/ansible.cfg b/ansible/roles/install-java/tasks/main.yml
similarity index 68%
copy from ansible/ansible.cfg
copy to ansible/roles/install-java/tasks/main.yml
index c11055e..82a9166 100644
--- a/ansible/ansible.cfg
+++ b/ansible/roles/install-java/tasks/main.yml
@@ -13,11 +13,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-[defaults]
-inventory = inventory/
-timeout = 60
+---
+- name: Install Java 11 on RHEL-based systems
+ package:
+ name: java-11-openjdk
+ state: present
+ when: ansible_distribution == 'RedHat' or ansible_distribution == 'CentOS'
or ansible_distribution == 'Fedora'
-[privilege_escalation]
-become = yes
-become_method = sudo
-become_flags = 'su -c'
+- name: Install Java 11 on Ubuntu systems
+ package:
+ name: openjdk-11-jdk
+ state: present
+ when: ansible_distribution == 'Ubuntu'
diff --git a/ansible/roles/skywalking/tasks/main.yml
b/ansible/roles/skywalking/tasks/main.yml
new file mode 100644
index 0000000..7648d91
--- /dev/null
+++ b/ansible/roles/skywalking/tasks/main.yml
@@ -0,0 +1,96 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+---
+- name: Create skywalking directory
+ file:
+ path: /usr/local/skywalking
+ state: directory
+ mode: "0755"
+ owner: root
+ group: root
+
+- name: Set ownership and permissions for skywalking directory
+ file:
+ path: /usr/local/skywalking
+ state: directory
+ recurse: yes
+ owner: root
+ group: root
+ mode: "0755"
+
+- name: Download Apache SkyWalking tar file
+ get_url:
+ url: "https://dlcdn.apache.org/skywalking/{{ skywalking_version
}}/apache-skywalking-apm-{{ skywalking_version }}.tar.gz"
+ dest: "/usr/local/skywalking/apache-skywalking-apm-{{ skywalking_version
}}.tar.gz"
+
+- name: Extract tar file
+ unarchive:
+ src: "/usr/local/skywalking/apache-skywalking-apm-{{ skywalking_version
}}.tar.gz"
+ dest: "/usr/local/skywalking"
+ remote_src: yes
+ extra_opts: [--strip-components=1]
+
+- name: Generate systemd unit file for oap service
+ template:
+ src: skywalking-oap.service.j2
+ dest: /usr/lib/systemd/system/skywalking-oap.service
+ owner: root
+ mode: "0660"
+ when: inventory_hostname in groups['skywalking-oap']
+
+- name: Generate script to stop oap service
+ template:
+ src: oap-service-stop.sh.j2
+ dest: /usr/local/skywalking/bin/oapServiceStop.sh
+ owner: root
+ mode: "0755"
+ when: inventory_hostname in groups['skywalking-oap']
+
+- name: Generate systemd unit file for webui service
+ template:
+ src: skywalking-ui.service.j2
+ dest: /usr/lib/systemd/system/skywalking-ui.service
+ owner: root
+ mode: "0660"
+ when: inventory_hostname in groups['skywalking-ui']
+
+- name: Reload systemd
+ systemd:
+ daemon_reload: yes
+
+- name: Link and enable skywalking-oap service
+ systemd:
+ name: skywalking-oap
+ enabled: yes
+ when: inventory_hostname in groups['skywalking-oap']
+
+- name: Link and enable skywalking-ui service
+ systemd:
+ name: skywalking-ui
+ enabled: yes
+ when: inventory_hostname in groups['skywalking-ui']
+
+- name: Start SkyWalking-OAP service
+ systemd:
+ name: skywalking-oap
+ state: started
+ when: inventory_hostname in groups['skywalking-oap']
+
+- name: Start SkyWalking-UI service
+ systemd:
+ name: skywalking-ui
+ state: started
+ when: inventory_hostname in groups['skywalking-ui']
diff --git a/ansible/ansible.cfg
b/ansible/roles/skywalking/templates/oap-service-stop.sh.j2
similarity index 78%
copy from ansible/ansible.cfg
copy to ansible/roles/skywalking/templates/oap-service-stop.sh.j2
index c11055e..861a1db 100644
--- a/ansible/ansible.cfg
+++ b/ansible/roles/skywalking/templates/oap-service-stop.sh.j2
@@ -1,3 +1,4 @@
+#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
@@ -13,11 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-[defaults]
-inventory = inventory/
-timeout = 60
+# Send SIGTERM to the main process
+/bin/kill -SIGTERM $MAINPID
-[privilege_escalation]
-become = yes
-become_method = sudo
-become_flags = 'su -c'
+# Find all child processes and send SIGTERM to each of them
+for child_pid in $(pgrep -P $MAINPID); do
+ /bin/kill -SIGTERM $child_pid
+done
diff --git a/ansible/ansible.cfg
b/ansible/roles/skywalking/templates/skywalking-oap.service.j2
similarity index 68%
copy from ansible/ansible.cfg
copy to ansible/roles/skywalking/templates/skywalking-oap.service.j2
index c11055e..726d8e1 100644
--- a/ansible/ansible.cfg
+++ b/ansible/roles/skywalking/templates/skywalking-oap.service.j2
@@ -13,11 +13,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-[defaults]
-inventory = inventory/
-timeout = 60
+[Unit]
+Description=Apache SkyWalking OAP Service
+After=network.target
-[privilege_escalation]
-become = yes
-become_method = sudo
-become_flags = 'su -c'
+[Service]
+Type=simple
+ExecStartPre=/usr/local/skywalking/bin/oapServiceInit.sh
+TimeoutStartSec=600
+ExecStart=/usr/local/skywalking/bin/oapService.sh
+TimeoutSec=300
+ExecStop=/bin/bash -c '/usr/local/skywalking/bin/oapServiceStop.sh'
+Restart=always
+
+[Install]
+WantedBy=multi-user.target
diff --git a/ansible/ansible.cfg
b/ansible/roles/skywalking/templates/skywalking-ui.service.j2
similarity index 76%
copy from ansible/ansible.cfg
copy to ansible/roles/skywalking/templates/skywalking-ui.service.j2
index c11055e..76e3e77 100644
--- a/ansible/ansible.cfg
+++ b/ansible/roles/skywalking/templates/skywalking-ui.service.j2
@@ -13,11 +13,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-[defaults]
-inventory = inventory/
-timeout = 60
+[Unit]
+Description=Apache SkyWalking UI Service
+After=network.target
-[privilege_escalation]
-become = yes
-become_method = sudo
-become_flags = 'su -c'
+[Service]
+Type=simple
+ExecStart=/usr/local/skywalking/bin/webappService.sh
+ExecStop=/bin/kill -SIGTERM $MAINPID
+Restart=always
+
+[Install]
+WantedBy=multi-user.target
diff --git a/ansible/ansible.cfg b/ansible/roles/skywalking/vars/main.yml
similarity index 85%
copy from ansible/ansible.cfg
copy to ansible/roles/skywalking/vars/main.yml
index c11055e..7842f3a 100644
--- a/ansible/ansible.cfg
+++ b/ansible/roles/skywalking/vars/main.yml
@@ -13,11 +13,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-[defaults]
-inventory = inventory/
-timeout = 60
-
-[privilege_escalation]
-become = yes
-become_method = sudo
-become_flags = 'su -c'
+---
+skywalking_version: "9.5.0"