Skip to content

Commit

Permalink
Merge pull request #47 from sansible/GITHUB-45-systemd
Browse files Browse the repository at this point in the history
[GITHUB-45] Adds SystemD service
  • Loading branch information
wojtek-oledzki committed Mar 5, 2019
2 parents d2aaa3b + d943342 commit f84a737
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 127 deletions.
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---

group: stable
dist: trusty
dist: xenial
sudo: required

language: python
Expand All @@ -15,10 +15,9 @@ branches:
- master

env:
- ANSIBLE_INSTALL_VERSION=2.4.6.0
- ANSIBLE_INSTALL_VERSION=2.5.11
- ANSIBLE_INSTALL_VERSION=2.6.7
- ANSIBLE_INSTALL_VERSION=2.7.1
- ANSIBLE_INSTALL_VERSION=2.5.14
- ANSIBLE_INSTALL_VERSION=2.6.13
- ANSIBLE_INSTALL_VERSION=2.7.7

services:
- docker
Expand All @@ -28,7 +27,7 @@ before_install:
- sudo apt-get install -o Dpkg::Options::="--force-confold" --force-yes -y docker-ce

install:
- make .venv
- make deps

script:
- make test
Expand Down
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v3.1
v3.2
19 changes: 15 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
ANSIBLE_INSTALL_VERSION ?= 2.6.7
ANSIBLE_INSTALL_VERSION ?= 2.7.7
PATH := $(PWD)/.venv_ansible$(ANSIBLE_INSTALL_VERSION)/bin:$(shell printenv PATH)
SHELL := env PATH=$(PATH) /bin/bash

ifeq ($(SCENARIO), all)
SCENARIO_OPT = "--all"
else
SCENARIO_OPT = "--scenario-name=$(SCENARIO)"
endif

.DEFAULT_GOAL := help
.PHONY: all clean destroy help test



## Make deps, test
all: deps test

## Setup dependencies
deps: .venv_ansible$(ANSIBLE_INSTALL_VERSION)


## Activate the virtualenv
activate: .venv_ansible$(ANSIBLE_INSTALL_VERSION)
Expand Down Expand Up @@ -44,10 +54,10 @@ login_%: .venv_ansible$(ANSIBLE_INSTALL_VERSION)

## Run 'molecule test --destroy=never' (run 'make destroy' to destroy containers)
test: .venv_ansible$(ANSIBLE_INSTALL_VERSION)
@.venv_ansible$(ANSIBLE_INSTALL_VERSION)/bin/molecule test --destroy=never
@.venv_ansible$(ANSIBLE_INSTALL_VERSION)/bin/molecule test $(SCENARIO_OPT) --destroy=never


# shortcut for creating virtualenv
# shortcut for creating venv
.venv: .venv_ansible$(ANSIBLE_INSTALL_VERSION)


Expand All @@ -72,11 +82,12 @@ watch: .venv_ansible$(ANSIBLE_INSTALL_VERSION)
done


## Print this help
help:
@awk -v skip=1 \
'/^##/ { sub(/^[#[:blank:]]*/, "", $$0); doc_h=$$0; doc=""; skip=0; next } \
skip { next } \
/^#/ { doc=doc "\n" substr($$0, 2); next } \
/:/ { sub(/:.*/, "", $$0); \
printf "\033[34m%-30s\033[0m\033[1m%s\033[0m %s\n\n", $$0, doc_h, doc; skip=1 }' \
$(MAKEFILE_LIST)
$(MAKEFILE_LIST)
8 changes: 4 additions & 4 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---

galaxy_info:
authod: sansible
description: "Install Kafka server."
license: MIT
# SAnsible only supports Ansible 2.4+
min_ansible_version: 2.4
min_ansible_container_version: 2.4
min_ansible_version: 2.5
min_ansible_container_version: 2.5
platforms:
- name: Ubuntu
versions:
- trusty
- xenial
- bionic
categories:
galaxy_tags:
- development

dependencies:
Expand Down
60 changes: 0 additions & 60 deletions molecule/default/create.yml

This file was deleted.

28 changes: 0 additions & 28 deletions molecule/default/destroy.yml

This file was deleted.

19 changes: 16 additions & 3 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,26 @@ platforms:
- name: sansible_kafka-trusty
image: ubuntu:trusty
- name: sansible_kafka-xenial
image: ubuntu:xenial
image: solita/ubuntu-systemd:xenial
command: /sbin/init
capabilities:
- SYS_ADMIN
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: sansible_kafka-bionic
image: ubuntu:bionic
image: solita/ubuntu-systemd:bionic
command: /sbin/init
capabilities:
- SYS_ADMIN
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro

provisioner:
name: ansible
config_options:
defaults:
# Fix for issue https://github.com/ansible/ansible/issues/43884
gather_timeout: 30
lint:
name: ansible-lint
inventory:
Expand Down Expand Up @@ -47,7 +61,6 @@ lint:
dependency:
name: galaxy
options:
ignore-certs: true
role-file: requirements.yml

scenario:
Expand Down
1 change: 1 addition & 0 deletions molecule/default/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@

roles:
- role: sansible.zookeeper
sansible_zookeeper_version: 3.4.13

- role: kafka
9 changes: 4 additions & 5 deletions molecule/default/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
- name: Install apt-transport-https, lsb-release, net-tools
become: yes
apt:
name: "{{ item }}"
name:
- apt-transport-https
- lsb-release
- net-tools
update_cache: yes
with_items:
- apt-transport-https
- lsb-release
- net-tools
29 changes: 23 additions & 6 deletions tasks/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,34 @@
src: "/home/{{ sansible_kafka_user }}/kafka/config"
state: link

- name: Create Kafka service
- name: Create Kafka service for SysV
become: yes
template:
dest: /etc/init.d/kafka
owner: root
mode: 0755
src: kafka_sysv.j2
when: ansible_service_mgr != "systemd"

- name: Create kafka startup links
- name: Add Kafka SystemD script
become: yes
command: update-rc.d kafka defaults
args:
creates: "/etc/rc0.d/K??kafka"
when: ansible_distribution_release == "bionic"
template:
dest: /etc/systemd/system/kafka.service
mode: u+rw,g+rw,o+r
src: kafka.service.j2
when: ansible_service_mgr == "systemd"

- name: Ensure Kafka is enabled for SysV
become: yes
service:
name: kafka
enabled: yes
when: ansible_service_mgr != "systemd"

- name: Ensure Kafka is enabled for SystemD
become: yes
systemd:
daemon_reload: yes
name: kafka
enabled: yes
when: ansible_service_mgr == "systemd"
10 changes: 0 additions & 10 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
---

# Needed to ensure some services start properly
- name: Set hostname
become: yes
lineinfile:
dest: /etc/hosts
line: "127.0.0.1 {{ ansible_hostname }}"
notify:
- restart kafka
when: ansible_virtualization_type != 'docker'

- name: Assigned ID EC2 fact hunt
action: ec2_metadata_facts
register: ec2_vars
Expand Down
16 changes: 16 additions & 0 deletions templates/kafka.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=kafka stream-processing software
After=network.target network-online.target remote-fs.target

[Service]
Type=simple
User=kafka
Group=kafka
EnvironmentFile=-/home/{{ sansible_kafka_user }}/etc/environment
ExecStart=/home/{{ sansible_kafka_user }}/kafka/bin/kafka-server-start.sh /home/{{ sansible_kafka_user }}/kafka/config/server.properties
ExecStop=/home/{{ sansible_kafka_user }}/kafka/bin/kafka-server-stop.sh
PIDFile=/var/run/kafka.pid
LimitNOFILE={{ sansible_kafka_max_open_files }}

[Install]
WantedBy=multi-user.target

0 comments on commit f84a737

Please sign in to comment.