Skip to content

Commit

Permalink
Release 1.1.0 (#2)
Browse files Browse the repository at this point in the history
* refactor(restart-reload): use process.name instead of option

* feat(options): * name option to match all processes

* docs(options): * as name option

* docs: version 1.1.0
  • Loading branch information
just1not2 authored Jan 20, 2022
1 parent c648d76 commit 4f3df2c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## 1.1.0 (2022-01-20)

### Features
- Adds "*" as reserved name option for the pm2_process module to match all PM2 processes


## 1.0.1 (2022-01-20)

### Documentation
Expand Down
6 changes: 6 additions & 0 deletions docs/pm2_process_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Parameters
</td>
<td>
<div>The name of the process.</div>
<div>If this option is set to *, the module will match all processes.</div>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -213,6 +214,11 @@ Examples
name: example
state: stopped

- name: Restart all PM2 processes
just1not2.pm2.pm2_process:
name: "*"
state: restarted



Return Values
Expand Down
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
namespace: just1not2
name: pm2
version: 1.0.1
version: 1.1.0
readme: README.md
authors:
- Justin Béra <[email protected]>
Expand Down
18 changes: 13 additions & 5 deletions plugins/module_utils/pm2.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def run(self, command):
def get_matching_processes(self, name):
''' Returns the list of processes whose name matches the name module parameter '''

# Returns every processes for specified reserved name "*"
if name == "*":
return self.processes

return [process for process in self.processes if process.name == name]

def create_ecosystem_file(self, process_json):
Expand Down Expand Up @@ -119,7 +123,11 @@ def delete_ecosystem_file(self, ecosystem_file_path):
def create_process(self, name, file):
''' Create a PM2 process '''

if not self.module.check_mode:
# Raises an error if the specified name is "*" (reserved)
if name == "*":
self.module.fail_json(msg="Cannot create PM2 process with name '*': reserved name")

elif not self.module.check_mode:
process_json = dict(
name=name,
script=file
Expand Down Expand Up @@ -181,15 +189,15 @@ def execute_ecosystem_action(self, action, name, file):

return delete_and_restart

def restart(self, name, file):
def restart(self, file):
''' Restarts the process '''

return self.execute_ecosystem_action("restart", name, file)
return self.execute_ecosystem_action("restart", self.name, file)

def reload(self, name, file):
def reload(self, file):
''' Reloads the process '''

return self.execute_ecosystem_action("reload", name, file)
return self.execute_ecosystem_action("reload", self.name, file)

def stop(self):
''' Stops the process '''
Expand Down
7 changes: 4 additions & 3 deletions plugins/modules/pm2_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
name:
description:
- The name of the process.
- If this option is set to *, the module will match all processes.
type: str
required: true
state:
Expand Down Expand Up @@ -125,7 +126,7 @@ def main():
(module.params["file"] and module.params["file"] != process.file)
)]
for process in diff_processes:
process.restart(module.params["name"], file=module.params["file"])
process.restart(module.params["file"])
diff["before"] += "'%s' state: %s\n" % (process.name, process.status)
diff["after"] += "'%s' state: restarted\n" % process.name
changed = True
Expand All @@ -146,7 +147,7 @@ def main():
else:
# Restarts all matching processes
for process in processes:
delete_and_restart = process.restart(module.params["name"], module.params["file"])
delete_and_restart = process.restart(module.params["file"])
diff["before"] += "'%s' state: %s\n" % (process.name, process.status)
diff["after"] += "'%s' state: %s\n" % (process.name, "deleted and restarted" if delete_and_restart else "restarted")
changed = True
Expand All @@ -167,7 +168,7 @@ def main():
else:
# Reloads all matching processes
for process in processes:
delete_and_restart = process.reload(module.params["name"], module.params["file"])
delete_and_restart = process.reload(module.params["file"])
diff["before"] += "'%s' state: %s\n" % (process.name, process.status)
diff["after"] += "'%s' state: %s\n" % (process.name, "deleted and restarted" if delete_and_restart else "reloaded")
changed = True
Expand Down

0 comments on commit 4f3df2c

Please sign in to comment.