deploy systemd file and create user/group
This commit is contained in:
parent
b8fffaa144
commit
bbd1314629
3
defaults/main.yml
Normal file
3
defaults/main.yml
Normal file
@ -0,0 +1,3 @@
|
||||
mosquitto_pid_file: /var/run/mosquitto.pid
|
||||
mosquitto_user: mosquitto
|
||||
mosquitto_group: mosquitto
|
@ -14,3 +14,24 @@
|
||||
with_items:
|
||||
- mosquitto
|
||||
- mosquitto-clients
|
||||
|
||||
- name: Copy systemd unit files
|
||||
template:
|
||||
src: "etc/systemd/system/mosquitto.service.j2"
|
||||
dest: "/etc/systemd/system/mosquitto.service"
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
|
||||
- name: Create group '{{ mosquitto_group }}'
|
||||
group:
|
||||
name: '{{ mosquitto_group }}'
|
||||
state: present
|
||||
|
||||
- name: Create user '{{ mosquitto_user }}'
|
||||
user:
|
||||
name: '{{ mosquitto_user }}'
|
||||
group: '{{ mosquitto_group }}'
|
||||
system: yes
|
||||
createhome: no
|
||||
shell: /sbin/nologin
|
||||
|
21
templates/etc/systemd/system/mosquitto.service.j2
Normal file
21
templates/etc/systemd/system/mosquitto.service.j2
Normal file
@ -0,0 +1,21 @@
|
||||
## {{ ansible_managed }}
|
||||
[Unit]
|
||||
Description=Mosquitto MQTT Broker daemon
|
||||
ConditionPathExists=/etc/mosquitto/mosquitto.conf
|
||||
After=network.target
|
||||
Requires=network.target
|
||||
|
||||
[Service]
|
||||
User={{ mosquitto_user }}
|
||||
Group={{ mosquitto_user }}
|
||||
Type=forking
|
||||
RemainAfterExit=no
|
||||
StartLimitInterval=0
|
||||
PIDFile={{ mosquitto_pid_file }}
|
||||
ExecStart=/bin/sh -c "/usr/local/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf -d"
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
Restart=on-failure
|
||||
RestartSec=2
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
Reference in New Issue
Block a user