diff --git a/molecule.yml b/molecule.yml index 8b894b1..7c636d8 100644 --- a/molecule.yml +++ b/molecule.yml @@ -7,12 +7,18 @@ docker: image: atosatto/centos image_version: 7-systemd privileged: True - # - name: minio-ubuntu-16.04 - # image: atosatto/ubuntu - # image_version: 16.04 + - name: minio-ubuntu-16.04 + image: atosatto/ubuntu + image_version: 16.04 + privileged: True + # TODO: Find a workaround to + # https://github.com/ansible/ansible/issues/18894 + # and add ubuntu-14.04 to CI. + # - name: minio-ubuntu-14.04 + # image: ubuntu + # image_version: 14.04 # privileged: True - # Unfortunately, upstart does not run in Docker containers, - # so no Ubuntu 14.04 docker tests :/ + # vagrant driver configuration (development) vagrant: @@ -31,6 +37,10 @@ vagrant: cpus: 2 instances: - name: ansible-minio-01 + interfaces: + - network_name: private_network + type: dhcp + auto_config: true options: append_platform_to_hostname: yes diff --git a/tasks/main.yml b/tasks/main.yml index d22f2a8..449aaab 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -3,6 +3,19 @@ - name: include os-specific variables include_vars: "{{ ansible_os_family }}.yml" + # add the python sni support to legacy python installations +- include: python_sni.yml + when: ansible_os_family == 'Debian' + and ansible_python_version | version_compare('2.6.0', '>=') + and ansible_python_version | version_compare('2.7.9', '<') + + # install additional ansible dependencies +- name: install ansible support packages + package: + name: "{{ item }}" + state: present + with_items: "{{ ansible_support_packages }}" + - name: create minio group group: name: "{{ minio_group }}" diff --git a/tasks/python_sni.yml b/tasks/python_sni.yml new file mode 100644 index 0000000..26ffb5f --- /dev/null +++ b/tasks/python_sni.yml @@ -0,0 +1,24 @@ +--- + +# with_indexed_items is required as a workaround for this issue: +# https://github.com/ansible/ansible-modules-core/issues/1178 +- name: install python-pip + package: + name: "{{ item.1 }}" + state: present + with_indexed_items: "{{ python_pip_packages }}" + +- name: install the Python SNI support packages + package: + name: "{{ item }}" + state: present + with_items: "{{ python_sni_support_packages }}" + +# There extra pip dependencies are needed to add SSL SNI support to +# Python version prior to 2.7.9. SNI support is needed by the Ansible +# get_url module in server.yml and client.yml. +- name: install the Python SNI python-pip dependencies. + pip: + name: "{{ item }}" + state: present + with_items: "{{ python_sni_pip_dependencies }}" diff --git a/tasks/server.yml b/tasks/server.yml index c47d4ed..0555c08 100644 --- a/tasks/server.yml +++ b/tasks/server.yml @@ -10,7 +10,7 @@ - name: generate the minio server envfile template: - src: minio_env.j2 + src: minio.env.j2 dest: "{{ minio_server_envfile }}" notify: restart minio @@ -20,11 +20,12 @@ dest: "{{ systemd_units_dir }}/minio.service" when: ansible_service_mgr == "systemd" -- name: create the minio server upstart config +- name: create the minio server init.d config template: - src: minio.upstart.j2 - dest: "{{ upstart_conf_dir }}/minio.conf" - when: ansible_service_mgr == "upstart" + src: minio.init.j2 + dest: "{{ initd_conf_dir }}/minio" + mode: 0755 + when: ansible_service_mgr != "systemd" - name: enable and start the minio service service: diff --git a/templates/minio_env.j2 b/templates/minio.env.j2 similarity index 100% rename from templates/minio_env.j2 rename to templates/minio.env.j2 diff --git a/templates/minio.init.j2 b/templates/minio.init.j2 new file mode 100644 index 0000000..b2a88d2 --- /dev/null +++ b/templates/minio.init.j2 @@ -0,0 +1,131 @@ +#! /bin/sh +### BEGIN INIT INFO +# Provides: minio +# Required-Start: $syslog $network +# Required-Stop: $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Distributed object storage server built for cloud applications and devops. +# Description: Distributed object storage server built for cloud applications and devops. +### END INIT INFO + +# Do NOT "set -e" + +# PATH should only include /usr/* if it runs after the mountnfs.sh script +PATH=/sbin:/usr/sbin:/bin:/usr/bin +NAME=minio +SERVICEVERBOSE=yes +PIDFILE=/var/run/$NAME.pid +SCRIPTNAME=/etc/init.d/$NAME +WORKINGDIR=/usr/local/ +DAEMON="{{ minio_server_bin }}" +USER="{{ minio_user }}" + +# Read configuration variable file if it is present +[ -r "{{ minio_server_envfile }}" ] && . {{ minio_server_envfile }} + +# Make sure the MINIO_VOLUMES variable is defined +[ -n "${MINIO_VOLUMES}" ] || log_daemon_msg "Variable MINIO_VOLUMES not set in {{ minio_server_envfile }}" + +# Set the DAEMON_ARGS variable +DAEMON_ARGS="server $MINIO_OPTS $MINIO_VOLUMES" + +# Specifies the maximum file descriptor number that can be opened by this process +ulimit -n 65536 + +# Exit if the package is not installed +[ -x "$DAEMON" ] || exit 0 + +# Load the VERBOSE setting and other rcS variables +. /lib/init/vars.sh + +# Define LSB log_* functions. +# Depend on lsb-base (>= 3.2-14) to ensure that this file is present +# and status_of_proc is working. +. /lib/lsb/init-functions + +# +# Function that starts the daemon/service +# +do_start() +{ + # Return + # 0 if daemon has been started + # 1 if daemon was already running + # 2 if daemon could not be started + sh -c "USER=$USER start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile \\ + --test --chdir $WORKINGDIR --chuid $USER \\ + --exec $DAEMON -- $DAEMON_ARGS > /dev/null \\ + || return 1" + sh -c "USER=$USER start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile \\ + --background --chdir $WORKINGDIR --chuid $USER \\ + --exec $DAEMON -- $DAEMON_ARGS \\ + || return 2" +} + +# +# Function that stops the daemon/service +# +do_stop() +{ + # Return + # 0 if daemon has been stopped + # 1 if daemon was already stopped + # 2 if daemon could not be stopped + # other if a failure occurred + start-stop-daemon --stop --quiet --retry=TERM/1/KILL/5 --pidfile $PIDFILE --name $NAME + RETVAL="$?" + [ "$RETVAL" = 2 ] && return 2 + start-stop-daemon --stop --quiet --oknodo --retry=0/1/KILL/5 --exec $DAEMON + [ "$?" = 2 ] && return 2 + # Many daemons don't delete their pidfiles when they exit. + rm -f $PIDFILE + return "$RETVAL" +} + + +case "$1" in + start) + [ "$SERVICEVERBOSE" != no ] && log_daemon_msg "Starting" "$NAME" + do_start + case "$?" in + 0|1) [ "$SERVICEVERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$SERVICEVERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + stop) + [ "$SERVICEVERBOSE" != no ] && log_daemon_msg "Stopping" "$NAME" + do_stop + case "$?" in + 0|1) [ "$SERVICEVERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$SERVICEVERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + status) + status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? + ;; + restart|force-reload) + log_daemon_msg "Restarting" "$NAME" + do_stop + case "$?" in + 0|1) + do_start + case "$?" in + 0) log_end_msg 0 ;; + 1) log_end_msg 1 ;; # Old process is still running + *) log_end_msg 1 ;; # Failed to start + esac + ;; + *) + # Failed to stop + log_end_msg 1 + ;; + esac + ;; + *) + echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 + exit 3 + ;; +esac + +: diff --git a/templates/minio.upstart.j2 b/templates/minio.upstart.j2 deleted file mode 100644 index c326189..0000000 --- a/templates/minio.upstart.j2 +++ /dev/null @@ -1,36 +0,0 @@ -description "minio" - -start on (local-filesystems and net-device-up IFACE!=lo) -stop on shutdown - -# Maximum file descriptor number that can be opened -limit nofile 65536 65536 - -# Set the kill signal and timeout -kill signal SIGTERM - -pre-start script - # enable the dash allexport feature - set -a - - # stop job from continuing if no config file found for daemon - [ ! -f {{ minio_server_envfile }} ] && { stop; exit 0; } - - # source the config file - . {{ minio_server_envfile }} - - # stop job from continuing if MINIO_VOLUMES not set - [ -n "$MINIO_VOLUMES" ] || { echo "Variable MINIO_VOLUMES not set in {{ minio_server_envfile }}"; stop; exit 0; } - -end script - -script - # enable the dash allexport feature - set -a - - # source the environment config file - . {{ minio_server_envfile }} - - # start the minio server - exec sudo -u {{ minio_user }} {{ minio_server_bin }} server $MINIO_OPTS $MINIO_VOLUMES -end script diff --git a/vars/Debian.yml b/vars/Debian.yml index 56f7f1a..9843211 100644 --- a/vars/Debian.yml +++ b/vars/Debian.yml @@ -1,4 +1,18 @@ --- +# systemd unit files location systemd_units_dir: /lib/systemd/system -upstart_conf_dir: /etc/init + +# packages providing python-pip +python_pip_packages: + - python-pip + +# extra packages required to add SNI support to legacy python versions +python_sni_support_packages: + - python-dev + - libssl-dev + - libffi-dev + +# extra packages needed by ansible to correctly configure the system +ansible_support_packages: + - ca-certificates diff --git a/vars/RedHat.yml b/vars/RedHat.yml index 565d01d..d596637 100644 --- a/vars/RedHat.yml +++ b/vars/RedHat.yml @@ -1,3 +1,15 @@ --- +# systemd unit files location systemd_units_dir: /etc/systemd/system + +# packages providing python-pip +python_pip_packages: + - epel-release + - python-pip + +# extra packages required to add SNI support to legacy python versions +python_sni_support_packages: [ ] + +# extra packages needed by ansible to correctly configure the system +ansible_support_packages: [ ] diff --git a/vars/main.yml b/vars/main.yml index 1dc9b27..21f7299 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -3,3 +3,12 @@ # Minio and MC download urls minio_server_download_url: https://dl.minio.io/server/minio/release/linux-amd64/minio minio_client_download_url: https://dl.minio.io/client/mc/release/linux-amd64/mc + +# default init scripts location +initd_conf_dir: /etc/init.d + +# python pip packages required to support SNI certificates +python_sni_pip_dependencies: + - pyopenssl + - ndg-httpsclient + - pyasn1