diff --git a/files/main.yml b/files/main.yml new file mode 100644 index 0000000..bdf984a --- /dev/null +++ b/files/main.yml @@ -0,0 +1,7 @@ +--- +- name: Restart unifi service + systemd: + state: restarted + daemon_reload: yes + name: unifi + listen: __unifi_restart diff --git a/tasks/install.yml b/tasks/install.yml index dc3e945..7bfdd61 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -49,6 +49,7 @@ src: "{{ unifi_base_dir }}/{{ unifi_version }}" dest: "{{ unifi_base_dir }}/latest" state: link + notify: __unifi_restart - name: Cleanup file: @@ -56,3 +57,20 @@ state: absent become: True become_user: "{{ unifi_user }}" + +- block: + - name: Create systemd unit files + template: + src: "etc/systemd/system/unifi.service.j2" + dest: "/etc/systemd/system/unifi.service" + mode: 0644 + notify: + - __unifi_restart + + - name: Ensure service is up and running + systemd: + state: started + daemon_reload: yes + enabled: yes + name: unifi + become: True diff --git a/templates/etc/systemd/system/unifi.service.j2 b/templates/etc/systemd/system/unifi.service.j2 new file mode 100644 index 0000000..97dc56d --- /dev/null +++ b/templates/etc/systemd/system/unifi.service.j2 @@ -0,0 +1,18 @@ +## {{ ansible_managed }} +# Systemd unit file for UniFi Controller + +[Unit] +Description=UniFi Controller +Wants=mongod.service +After=syslog.target network.target + +[Service] +ExecStart=/usr/bin/java -Xmx1024M -jar {{ unifi_base_dir }}/latest/UniFi/lib/ace.jar start +ExecStop=/usr/bin/java -jar {{ unifi_base_dir }}/latest/UniFi/lib/ace.jar stop +Type=simple +User={{ unifi_user }} +WorkingDirectory={{ unifi_base_dir }} +SuccessExitStatus=143 + +[Install] +WantedBy=multi-user.target