Skip to content

Commit edd9915

Browse files
committed
fixing service fail with systemd
1 parent 6633edc commit edd9915

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

files/mongodb.service

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[Unit]
2+
Description=An object/document-oriented database
3+
Documentation=man:mongod(1)
4+
5+
[Service]
6+
User=mongodb
7+
ExecStart=/usr/bin/mongod --config /etc/mongodb.conf
8+
9+
[Install]
10+
WantedBy=multi-user.target

handlers/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@
88

99
- name: mongodb-mms-automation-agent restart
1010
service: name=mongodb-mms-automation-agent state=restarted
11+
12+
- name: reload systemd
13+
shell: systemctl daemon-reload

tasks/configure.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,18 @@
1313
template: src=logrotate.conf.j2 dest=/etc/logrotate.d/mongodb.conf
1414
when: mongodb_logrotate
1515

16+
#- name: reload systemd
17+
# shell: systemctl daemon-reload
18+
# when: systemd.stat.exists == true
19+
# changed_when: false
20+
1621
- name: ensure mongodb started and enabled
1722
service: name={{ mongodb_daemon_name }} state=started enabled=yes
1823

24+
- name: wait MongoDB port is listening
25+
wait_for: host="{{ mongodb_conf_bind_ip }}"port="{{ mongodb_conf_port }}" delay=5 state=started
26+
when: systemd.stat.exists == true
27+
1928
- include: auth_initialization.yml
2029
when: mongodb_conf_auth
2130

tasks/install.deb.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22

33
- include_vars: "{{ansible_distribution}}.yml"
44

5+
- name: Check if systemd is present
6+
stat: path=/lib/systemd/system/
7+
register: systemd
8+
9+
- name: Add systemd configuration if present
10+
copy: src=mongodb.service dest=/lib/systemd/system/mongodb.service owner=root group=root mode=0640
11+
when: systemd.stat.exists == true
12+
13+
- name: Add symlink for systemd
14+
file: src=/lib/systemd/system/mongodb.service dest=/etc/systemd/system/multi-user.target.wants/mongodb.service state=link
15+
when: systemd.stat.exists == true
16+
notify: reload systemd
17+
18+
- meta: flush_handlers
19+
when: systemd.stat.exists == true
20+
521
- name: Add APT key
622
apt_key: url=http://docs.mongodb.org/10gen-gpg-key.asc id=7F0CEB10
723
when: '"mongodb-org" in mongodb_package'
@@ -12,6 +28,9 @@
1228

1329
- name: Install MongoDB package
1430
apt: pkg={{mongodb_package}} state=present
31+
notify: reload systemd
32+
33+
- meta: flush_handlers
1534

1635
- name: Install additional packages
1736
apt: pkg={{item}}

0 commit comments

Comments
 (0)