diff --git a/files/mongodb.service b/files/mongodb.service new file mode 100644 index 0000000..a73d760 --- /dev/null +++ b/files/mongodb.service @@ -0,0 +1,10 @@ +[Unit] +Description=An object/document-oriented database +Documentation=man:mongod(1) + +[Service] +User=mongodb +ExecStart=/usr/bin/mongod --config /etc/mongodb.conf + +[Install] +WantedBy=multi-user.target diff --git a/handlers/main.yml b/handlers/main.yml index c6988fb..04e3eaf 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -8,3 +8,6 @@ - name: mongodb-mms-automation-agent restart service: name=mongodb-mms-automation-agent state=restarted + +- name: reload systemd + shell: systemctl daemon-reload diff --git a/tasks/configure.yml b/tasks/configure.yml index 2f76e1b..d796c8a 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -13,9 +13,18 @@ template: src=logrotate.conf.j2 dest=/etc/logrotate.d/mongodb.conf when: mongodb_logrotate +#- name: reload systemd +# shell: systemctl daemon-reload +# when: systemd.stat.exists == true +# changed_when: false + - name: ensure mongodb started and enabled service: name={{ mongodb_daemon_name }} state=started enabled=yes +- name: wait MongoDB port is listening + wait_for: host="{{ mongodb_conf_bind_ip }}"port="{{ mongodb_conf_port }}" delay=5 state=started + when: systemd.stat.exists == true + - include: auth_initialization.yml when: mongodb_conf_auth diff --git a/tasks/install.deb.yml b/tasks/install.deb.yml index bd967ef..5bddce5 100644 --- a/tasks/install.deb.yml +++ b/tasks/install.deb.yml @@ -2,6 +2,22 @@ - include_vars: "{{ansible_distribution}}.yml" +- name: Check if systemd is present + stat: path=/lib/systemd/system/ + register: systemd + +- name: Add systemd configuration if present + copy: src=mongodb.service dest=/lib/systemd/system/mongodb.service owner=root group=root mode=0640 + when: systemd.stat.exists == true + +- name: Add symlink for systemd + file: src=/lib/systemd/system/mongodb.service dest=/etc/systemd/system/multi-user.target.wants/mongodb.service state=link + when: systemd.stat.exists == true + notify: reload systemd + +- meta: flush_handlers + when: systemd.stat.exists == true + - name: Add APT key apt_key: url=http://docs.mongodb.org/10gen-gpg-key.asc id=7F0CEB10 when: '"mongodb-org" in mongodb_package' @@ -12,6 +28,9 @@ - name: Install MongoDB package apt: pkg={{mongodb_package}} state=present + notify: reload systemd + +- meta: flush_handlers - name: Install additional packages apt: pkg={{item}}