Skip to content

Commit 98c3894

Browse files
Merge branch 'develop'
2 parents d328852 + f10416f commit 98c3894

36 files changed

+855
-239
lines changed

README.md

+79-52
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
[![Testing](https://github.com/joe-at-startupmedia/pmon3/actions/workflows/testing.yml/badge.svg)](https://github.com/joe-at-startupmedia/pmon3/actions/workflows/testing.yml)
33

44

5-
6-
75
`pmon3` is a process manager for Golang applications. It allows you to keep applications alive forever and to reload them without downtime.
86

97
<img width="537" alt="pmon3_ls" src="https://github.com/joe-at-startupmedia/pmon3/assets/13522698/5d79ad53-664d-4ee7-bfac-f3fc94c2b316">
@@ -41,7 +39,7 @@ The systemd installation process entails the following steps:
4139
1. create the bash completion profile (requires the bash-completion package)
4240
1. enable and start the `pmond` system service
4341

44-
```shell
42+
```bash
4543
#build the project
4644
make build
4745
#install on systemd-based system
@@ -52,14 +50,14 @@ make systemd_install
5250
### Using Release Installer
5351

5452
```bash
55-
wget -O - https://raw.githubusercontent.com/joe-at-startupmedia/pmon3/master/release-installer.bash | bash -s 1.14.13
53+
wget -O - https://raw.githubusercontent.com/joe-at-startupmedia/pmon3/master/release-installer.bash | bash -s 1.15.0
5654
```
5755

5856
:exclamation::exclamation: Note :exclamation::exclamation:
5957

6058
After installing `pmon3` for the first time, both installation methods provided above should automatically enable and start the service. if the `pmond` service does not start automatically, you need to manually start the service.
6159

62-
```shell
60+
```bash
6361
sudo systemctl start pmond
6462

6563
# Others
@@ -69,7 +67,7 @@ sudo /usr/local/pmon3/bin/pmond &
6967
<a name="section_commands"></a>
7068
## Commands
7169

72-
#### Help
70+
### Help
7371

7472
```
7573
Usage:
@@ -79,29 +77,30 @@ Available Commands:
7977
completion Generate completion script
8078
del Delete process by id or name
8179
desc Show process extended details
80+
dgraph Show the process queue order
8281
drop Delete all processes
8382
exec Spawn a new process
8483
help Help about any command
85-
init Restart all stopped processes
84+
init initialize all stopped processes
8685
kill Terminate all processes
8786
log Display process logs by id or name
8887
logf Tail process logs by id or name
8988
ls List all processes
90-
restart Restart a process by id or name
89+
restart (re)start a process by id or name
9190
stop Stop a process by id or name
9291
topn Shows processes using the native top
9392
version
9493
9594
Flags:
9695
-h, --help help for pmon3
9796
98-
Use "pmon3 [command] --help" for more information about a command
97+
Use "pmon3 [command] --help" for more information about a command.
9998
```
10099

101100
<a name="pmon3_exec"></a>
102-
#### Running process [run/exec]
101+
### Running process [run/exec]
103102

104-
```
103+
```bash
105104
pmon3 exec [application_binary] [flags]
106105
```
107106

@@ -113,7 +112,7 @@ The starting process accepts several parameters. The parameter descriptions are
113112
--name
114113
115114
// Where to store logs. It will override the confuration files `logs_dir` property
116-
--log-dir -d
115+
--log-dir
117116
118117
// The absolute path of a custom log file
119118
--log -l
@@ -129,49 +128,52 @@ The starting process accepts several parameters. The parameter descriptions are
129128
130129
// Do not restart automatically. It will automatically restart by default.
131130
--no-autorestart -n
131+
132+
// Provide a list of process names that this process will depend on
133+
--dependency parent-process-name [--dependency parent-process-name2]...
132134
```
133135

134136
#### Example:
135137

136-
```
138+
```bash
137139
pmon3 exec ./bin/gin --args "-prjHome=`pwd`" --user ntt360
138140
```
139141

140142
:exclamation::exclamation: Note :exclamation::exclamation:
141143

142144
Parameter arguments need to use the absolute path.
143145

144-
#### View List [ list/ls ]
146+
### View List [ list/ls ]
145147

146-
```
148+
```bash
147149
pmon3 ls
148150
```
149151

150-
#### Top Native [ topn ]
152+
### Top Native [ topn ]
151153

152154
This will output the resource utilization of all processes using the native `top` command that is pre-installed on most unix-based operating systems. It will only show those processes managed by (and including) the `pmond` process. The output is updated every few seconds until the process is terminated using Ctrl+C.
153155

154-
```
156+
```bash
155157
pmon3 topn
156158
```
157159
<img width="559" alt="pmon3_topn" src="https://github.com/joe-at-startupmedia/pmon3/assets/13522698/a77cce0f-55b0-479f-8489-d6aaf9fcdd6b">
158160

159-
#### (re)start the process [ restart/start ]
161+
### (re)start the process [ restart/start ]
160162

161-
```
163+
```bash
162164
pmon3 restart [id or name]
163165
```
164166

165167
<a name="pmon3_stop"></a>
166-
#### Stop the process [ stop ]
168+
### Stop the process [ stop ]
167169

168-
```
170+
```bash
169171
pmon3 stop [id or name]
170172
```
171173

172-
#### Process logging
174+
### Process logging
173175

174-
```
176+
```bash
175177
# view logs of the process specified
176178
pmon3 log [id or name]
177179

@@ -182,38 +184,55 @@ pmon3 log -a [id or name]
182184
pmon3 logf [id or name]
183185
```
184186

185-
#### Delete the process [ del/delete ]
187+
### Delete the process [ del/delete ]
186188

187-
```
189+
```bash
188190
pmon3 del [id or name]
189191
```
190192

191-
#### View details [ show/desc ]
193+
### View details [ show/desc ]
192194

193-
```
195+
```bash
194196
pmon3 show [id or name]
195197
```
196198

197199
<img width="475" alt="pmon3_show" src="https://github.com/joe-at-startupmedia/pmon3/assets/13522698/6b564a1c-0e26-468c-bd01-6dabce0c7620">
198200

199201
<a name="pmon3_kill"></a>
200-
#### Terminate all running process [ kill ]
201-
```
202+
### Terminate all running process [ kill ]
203+
```bash
202204
pmon3 kill [--force]
203205
```
204206

205207
<a name="pmon3_init"></a>
206-
#### Restart all stopped process or start processes specified in the app config [ init ]
207-
```
208+
### (re)start all stopped process [ init ]
209+
```bash
210+
#(re)start processes specified in the Apps Config only
211+
pmon3 init --apps-config-only
212+
213+
#(re)start processes specified in the Apps Config and those which already exist in the database
208214
pmon3 init
209215
```
210216

211217
<a name="pmon3_drop"></a>
212-
#### Terminate and delete all processes [drop]
213-
```
218+
### Terminate and delete all processes [drop]
219+
```bash
214220
pmon3 drop [--force]
215221
```
216222

223+
<a name="pmon3_dgraph"></a>
224+
### Display the dependency graph [dgraph/order]
225+
226+
This command is useful to debug dependency resolution without (re)starting processes
227+
228+
```bash
229+
#processes specified in the Apps Config only
230+
pmon3 dgraph --apps-config-only
231+
232+
#processes specified in the Apps Config and the database
233+
pmon3 dgraph
234+
```
235+
217236
<a name="section_config"></a>
218237
## Configuration
219238
The default path of the configuration file is `/etc/pmon3/config/config.yml`. This value can be overridden with the `PMON3_CONF` environment variable.
@@ -233,6 +252,8 @@ The following configuration options are available:
233252
#cmd_exec_response_wait: 1500
234253
# wait [n] milliseconds after connecting to IPC client before issuing commands
235254
#ipc_connection_wait: 0
255+
# wait [n] milliseconds after enqueueing a dependent process
256+
#dependent_process_enqueued_wait: 2000
236257
# a script to execute when a process is restarted which accepts the process details json as the first argument
237258
#on_process_restart_exec:
238259
# a script to execute when a process fails (--no-autorestart) which accepts the process details json as the first argument
@@ -249,6 +270,8 @@ The following configuration options are available:
249270
#apps_config_file: /etc/pmon3/config/app.config.json
250271
```
251272

273+
All configuration changes are effective when the next command is issued - restarting pmond is unnecessary.
274+
252275
The configuration values can be overridden using environment variables:
253276

254277

@@ -258,6 +281,7 @@ The configuration values can be overridden using environment variables:
258281
* `CONFIGOR_HANDLEINTERRUPTS`
259282
* `CONFIGOR_CMDEXECRESPONSEWAIT`
260283
* `CONFIGOR_IPCCONNECTIONWAIT`
284+
* `CONFIGOR_DEPENDENTPROCESSENQUEUEDWAIT`
261285
* `CONFIGOR_ONPROCESSRESTARTEXEC`
262286
* `CONFIGOR_ONPROCESSFAILUREEXEC`
263287
* `CONFIGOR_POSIXMESSAGEQUEUEDIR`
@@ -270,15 +294,9 @@ The configuration values can be overridden using environment variables:
270294
## Application(s) Config
271295

272296
By default, when `pmond` is restarted from a previously stopped state, it will load all processes in the database that were previously running, have been marked as stopped as a result of pmond closing and have `--no-autorestart` set to false (default value).
297+
If applications are specified in the Apps Config, they will overwrite matching processes which already exist in the database.
273298

274-
#### Criteria
275-
When an application config is provided `pmond` will instead refer to the `apps` array specified based on the following criteria:
276-
1. When `pmond` is starting from a fresh install
277-
2. When `pmon3` successfully executes a [drop](#pmon3_drop) command followed by running an [init](#pmon3_init) command.
278-
279-
If [init](#pmon3_init) is ran while there are still stopped process in the database (resulting from `pmond` daemon restart or [kill](#pmon3_kill), the Application config will *NOT* be used, and instead the previously-stopped process will be restarted.
280-
281-
#### Configuration
299+
### Configuration
282300

283301
#### /etc/pmon3/config/config.yml
284302
```yaml
@@ -297,6 +315,7 @@ apps_config_file: /etc/pmon3/config/apps.config.json
297315
"args": "-h startup-patroni-1.node.consul -p 5555 -r 5000",
298316
"user": "vagrant",
299317
"log_dir": "/var/log/custom/",
318+
"dependencies": ["happac2"]
300319
}
301320
},
302321
{
@@ -305,7 +324,7 @@ apps_config_file: /etc/pmon3/config/apps.config.json
305324
"name": "happac2",
306325
"log": "/var/log/happac2.log",
307326
"args": "-h startup-patroni-1.node.consul -p 5556 -r 5001",
308-
"user": "vagrant"
327+
"user": "vagrant",
309328
"no_auto_restart": true
310329
}
311330
},
@@ -314,14 +333,21 @@ apps_config_file: /etc/pmon3/config/apps.config.json
314333
"flags": {
315334
"name": "metabase-api",
316335
"args": "/var/www/vhosts/metabase-api/index.js",
317-
"env_vars": "NODE_ENV=prod"
336+
"env_vars": "NODE_ENV=prod",
318337
"user": "dw_user"
319338
}
320339
}
321340
]
322341
}
323342
```
324343

344+
### Dependencies
345+
346+
Depenencies can be provided as a json array and determine the order in which the processes are booted. They are sorted using a directed acyclic graph meaning that there cannot be cyclical dependencies between processes (for obvious reasons). Dependecy resolution can be debugged using the [dgraph](#pmon3_dgraph) command. Parent processes can wait [n] amount of seconds between spawning dependent processes by utilziing the `dependent_process_enqueued_wait` configuration variable which currently defaults to 2 seconds.
347+
348+
349+
### Flags
350+
325351
All possible `flags` values matching those specified in the [exec](#exec_flags) command:
326352

327353
* user
@@ -331,6 +357,7 @@ All possible `flags` values matching those specified in the [exec](#exec_flags)
331357
* args
332358
* env_vars
333359
* name
360+
* dependencies
334361

335362
<a name="section_events"></a>
336363
## Event Handling With Custom Scripts
@@ -342,13 +369,13 @@ on_process_restart_exec: ""
342369
on_process_failure_exec: ""
343370
```
344371
345-
#### 1. Specify the executable script to run for the `on_process_restart_exec` value. `pmond` will pass a json-escaped string of the process details as the first argument.
372+
### 1. Specify the executable script to run for the `on_process_restart_exec` value. `pmond` will pass a json-escaped string of the process details as the first argument.
346373
#### /etc/pmond/config/config.yml
347374
```yaml
348375
on_process_restart_exec: "/etc/pmon3/bin/on_restart.bash"
349376
```
350377

351-
#### 2. create the script to accept the json-escaped process details:
378+
### 2. create the script to accept the json-escaped process details:
352379
#### /etc/pmon3/bin/on_restart.bash
353380
```bash
354381
PROCESS_JSON="$1"
@@ -357,15 +384,15 @@ PROCESS_NAME=$(echo "${PROCESS_JSON}" | jq '.name')
357384
echo "process restarted: ${PROCESS_ID} - ${PROCESS_NAME}" >> /var/log/pmond/output.log
358385
```
359386

360-
#### 3. start pmond in debug mode
387+
### 3. start pmond in debug mode
361388
```bash
362389
$ PMON3_DEBUG=true pmond
363390
INFO/vagrant/go_src/pmon3/pmond/observer/observer.go:29 pmon3/pmond/observer.HandleEvent() Received event: &{restarted 0xc0001da630}
364391
WARN/vagrant/go_src/pmon3/pmond/observer/observer.go:47 pmon3/pmond/observer.onRestartEvent() restarting process: happac3 (3)
365392
DEBU/vagrant/go_src/pmon3/pmond/observer/observer.go:70 pmon3/pmond/observer.onEventExec() Attempting event executor(restarted): /etc/pmon3/bin/on_restart.bash "{\"id\":3,\"created_at\":\"2024-05-03T05:44:25.114957302Z\",\"updated_at\":\"2024-05-03T06:09:18.71222185Z\",\"pid\":4952,\"log\":\"/var/log/pmond/acf3f83.log\",\"name\":\"happac3\",\"process_file\":\"/usr/local/bin/happac\",\"args\":\"-h startup-patroni-1.node.consul -p 5557 -r 5002\",\"status\":2,\"auto_restart\":true,\"uid\":1000,\"username\":\"vagrant\",\"gid\":1000}"
366393
```
367394

368-
#### 4. confirm the script executed successfully
395+
### 4. confirm the script executed successfully
369396
```bash
370397
$ tail /var/log/pmond/output.log
371398
process restarted: 4 - "happac4"
@@ -468,12 +495,12 @@ If there is a path in the parameters you pass, please use the absolute path. The
468495

469496
`pmon3` provides Bash automation. If you find that the command cannot be automatically provided, please install `bash-completion` and exit the terminal to re-enter:
470497

471-
```shell
498+
```bash
472499
sudo yum install -y bash-completion
473500
```
474501

475502
#### Using ZSH instead of Bash
476-
```shell
503+
```bash
477504
autoload -U +X compinit && compinit
478505
autoload -U +X bashcompinit && bashcompinit
479506
sudo sh -c "pmon3 completion zsh > /etc/profile.d/pmon3.sh"
@@ -484,7 +511,7 @@ source /etc/profile.d/pmon3.sh
484511

485512
If you encounter the error above, make sure the `pmond` service has started successfully.
486513

487-
```shell
514+
```bash
488515
sudo systemctl start pmond
489516
```
490517

@@ -493,13 +520,13 @@ sudo systemctl start pmond
493520
You should only use `sudo` to start the `pmond` process which requires superuser privileges due to the required process forking commands. However, the `pmon3` cli should be used *without* `sudo` to ensure that the spawned processes are attached to the correct parent pid. When using `sudo`, the processes will be attached to ppid 1 and as a result, will become orphaned if the `pmond` process exits prematurely. Using `sudo` also prevents non-root users from being able to access the log files. The following Makefile command applies the adequate non-root permissions to the log files.
494521

495522
#### Applying permissions
496-
```shell
523+
```bash
497524
#This is automatically called by make systemd_install
498525
make systemd_permissions
499526
```
500527

501528
#### Spawn a new process as the root user without using `sudo`
502-
```
529+
```bash
503530
pmon3 exec /usr/local/bin/happac --user root
504531
```
505532

0 commit comments

Comments
 (0)