Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add systemd support #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
language: python
env:
- ANSIBLE_VERSION="2.2.*"
- ANSIBLE_VERSION="2.1.*"
- ANSIBLE_VERSION="2.0.*"
- ANSIBLE_VERSION="1.9.*"
- ANSIBLE_VERSION="1.8.*"
# - ANSIBLE_VERSION="2.1.*"
# - ANSIBLE_VERSION="2.0.*"
# - ANSIBLE_VERSION="1.9.*"
# - ANSIBLE_VERSION="1.8.*"
# - ANSIBLE_VERSION="1.7.*"
# - ANSIBLE_VERSION="1.6.*"
# - ANSIBLE_VERSION="1.5.*"
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ client.

What this role does:

- Installs [Supervisor](http://supervisord.org/) to run The Lounge in the background
- Uses [Supervisor](http://supervisord.org/) or `systemd` to run The Lounge in the background (supervisord will be installed when selected)
- Installs [NodeSource's Node.js 4.x LTS](https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions)
- Installs [The Lounge v2.4.0](https://github.com/thelounge/lounge/blob/master/CHANGELOG.md)
- Creates a system user to own the `lounge` process
Expand All @@ -23,7 +23,7 @@ of configuration files.

## Requirements

This role should be compatible with Ansible 1.2 or higher.
This role should be compatible with Ansible 2.2 or higher.

It was written for Debian and Ubuntu distributions.

Expand Down Expand Up @@ -103,6 +103,12 @@ npm install bcryptjs
[not be saved in your `bash` history](http://askubuntu.com/a/15929/166928),
if configured accordingly).

### `lounge_init_system`

Sets the software that is used to start `lounge`.

This variable is **optional** can be set to `systemd` or `supervisord` (default).

### `lounge_version`

Installs a specific version of The Lounge. It must be one of [the official
Expand Down
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ lounge_prefetch: false
lounge_theme: example
lounge_users: []
lounge_version: "2.4.0"
lounge_init_system: "supervisord"
14 changes: 14 additions & 0 deletions files/lounge_systemd.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# {{ ansible_managed }}

[Service]
WorkingDirectory=/etc/lounge
ExecStart=/usr/bin/lounge start --home /etc/lounge/
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=lounge
User=lounge
Group=lounge

[Install]
WantedBy=multi-user.target
15 changes: 13 additions & 2 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@
supervisorctl:
name: lounge
state: restarted
sudo: yes
become: yes
listen: Restart lounge
when: lounge_init_system == "supervisord"

- name: Restart systemd lounge service
service:
name: lounge
state: restarted
daemon_reload: yes
become: yes
listen: Restart lounge
when: lounge_init_system == "systemd"

- name: Clean up npm temporary files
shell: rm -rf /tmp/npm-*
sudo: yes
become: yes
59 changes: 39 additions & 20 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
apt:
pkg: supervisor
state: present
sudo: yes
become: yes
when: lounge_init_system == "supervisord"

- name: Ensure script to install NodeSource Node.js 4.x repo has been executed
shell:
curl -sL https://deb.nodesource.com/setup_4.x | sudo bash -
creates=/etc/apt/sources.list.d/nodesource.list
sudo: yes
become: yes

- name: Ensure that the latest version of Node.js 4.x (LTS) is installed
apt:
pkg: nodejs
state: latest
sudo: yes
become: yes

- name: Ensure thelounge package is installed
npm:
Expand All @@ -25,9 +26,9 @@
production: yes
version: "{{ lounge_version }}"
state: present
sudo: yes
become: yes
notify:
- Restart supervisord program
- Restart lounge
- Clean up npm temporary files

- name: Ensure user lounge is present
Expand All @@ -37,7 +38,7 @@
comment: The Lounge IRC
system: yes
state: present
sudo: yes
become: yes

- name: Ensure JS and JSON syntax checking packages are installed
npm:
Expand All @@ -48,28 +49,28 @@
with_items:
- esprima
- jsonlint
sudo: yes
become: yes

- name: Ensure lounge configuration directory is present
file:
path: /etc/lounge
state: directory
sudo: yes
become: yes

- name: Ensure The Lounge is configured
template:
src: config.js.j2
dest: /etc/lounge/config.js
validate: 'esvalidate %s'
sudo: yes
notify: Restart supervisord program
become: yes
notify: Restart lounge

- name: Ensure user configuration directory is present
file:
path: /etc/lounge/users
state: directory
sudo: yes
notify: Restart supervisord program
become: yes
notify: Restart lounge

- name: Ensure preview storage directory is present
file:
Expand All @@ -78,8 +79,8 @@
group: lounge
mode: "0770"
state: directory
sudo: yes
notify: Restart supervisord program
become: yes
notify: Restart lounge

- name: Ensure user configuration files are present
template:
Expand All @@ -91,19 +92,37 @@
force: no # Do not overwrite existing users to not erase networks
validate: 'jsonlint -q %s'
with_items: "{{ lounge_users }}"
sudo: yes
notify: Restart supervisord program
become: yes
notify: Restart lounge

- name: Ensure program configuration for supervisord is installed
copy:
src: lounge_supervisord.conf
dest: /etc/supervisor/conf.d/lounge.conf
sudo: yes
notify: Restart supervisord program
become: yes
notify: Restart lounge
when: lounge_init_system == "supervisord"

- name: Ensure lounge supervisord program is present
supervisorctl:
name: lounge
state: present
sudo: yes
notify: Restart supervisord program
become: yes
notify: Restart lounge
when: lounge_init_system == "supervisord"

- name: Ensure systemd unit file is present
copy:
dest: /etc/systemd/system/lounge.service
src: lounge_systemd.service
become: yes
notify: Restart lounge
when: lounge_init_system == "systemd"

- name: Ensure systemd service is started
service:
name: lounge
state: started
enabled: yes
become: yes
when: lounge_init_system == "systemd"