Skip to content

Commit

Permalink
Merge pull request #3817 from EnterpriseDB/contents/docs/pem/PEM-3896…
Browse files Browse the repository at this point in the history
…-update-pemagent-service-file

PEM-3896-Added content for changing agent.cfg file path in pemagent service file
  • Loading branch information
drothery-edb authored Mar 24, 2023
2 parents 8941449 + 329f1ae commit edc24e9
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 35 deletions.
47 changes: 25 additions & 22 deletions product_docs/docs/pem/9/registering_agent.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -152,30 +152,31 @@ To use a nonroot user account to register a PEM agent, you must first install th
1. Log in as edb. Create `pem` and `logs` directories and assign read, write, and execute permissions:

```shell
$ mkdir /home/edb/pem
$ mkdir /home/edb/pem/logs
$ chmod 700 /home/edb/pem
$ chmod 700 /home/edb/pem/logs
# Running as nonroot user edb
mkdir /home/edb/pem
mkdir /home/edb/pem/logs
chmod 700 /home/edb/pem
chmod 700 /home/edb/pem/logs
```

2. Register the agent with PEM server:

```shell
$ export PEM_SERVER_PASSWORD=edb
export PEM_SERVER_PASSWORD=edb

# Use the following command to create agent certificates and an agent
# configuration file (`agent.cfg`) in the `/home/edb/pem` directory.
$ /usr/edb/pem/agent/bin/pemworker --register-agent --pem-server <172.19.11.230> --pem-user postgres --pem-port 5432 --display-name non_root_pem_agent --cert-path /home/edb/pem --config-dir /home/edb/pem
/usr/edb/pem/agent/bin/pemworker --register-agent --pem-server <172.19.11.230> --pem-user postgres --pem-port 5432 --display-name non_root_pem_agent --cert-path /home/edb/pem --config-dir /home/edb/pem

# Use the following command to assign read and write permissions to
# these files:
$ chmod -R 600 /home/edb/pem/agent*
chmod -R 600 /home/edb/pem/agent*
```

3. Change the parameters of the `agent.cfg` file:

```ini
$ vi /home/edb/pem/agent.cfg
vi /home/edb/pem/agent.cfg
agent_ssl_key=/home/edb/pem/agent<id>.key
agent_ssl_crt=/home/edb/pem/agent<id>.crt
log_location=/home/edb/pem/worker.log
Expand All @@ -187,16 +188,16 @@ To use a nonroot user account to register a PEM agent, you must first install th
4. Create a `tmp` directory, set the environment variable, and start the agent:

```ini
$ mkdir /home/edb/pem/tmp
mkdir /home/edb/pem/tmp

# Create a script file, add the environment variable, give permissions, and execute:
$ vi /home/edb/pem/run_pemagent.sh
vi /home/edb/pem/run_pemagent.sh
#!/bin/bash
export TEMP=/home/edb/agent/tmp
/usr/edb/pem/agent/bin/pemagent -c /home/edb/agent/agent.cfg
$ chmod a+x /home/edb/pem/run_pemagent.sh
$ cd /home/edb/pem
$ ./run_pemagent.sh
chmod a+x /home/edb/pem/run_pemagent.sh
cd /home/edb/pem
./run_pemagent.sh
```

Your PEM agent is now registered and started with the edb user. If your machine restarts, then this agent doesn't restart automatically. You need to start it manually using the previous command.
Expand All @@ -206,7 +207,7 @@ To use a nonroot user account to register a PEM agent, you must first install th
a. Update the values for the configuration file path and the user in the `pemagent` service file as superuser:

```ini
$ sudo vi /usr/lib/systemd/system/pemagent.service
sudo vi /usr/lib/systemd/system/pemagent.service
[Service]
Type=forking
WorkingDirectory=/home/edb/pem
Expand All @@ -219,17 +220,19 @@ To use a nonroot user account to register a PEM agent, you must first install th

```shell
# Find the process id of the running pem agent and pem worker process and kill that process
$ ps -ax | grep pemagent
$ kill -9 <process_id_of_pemagent>
$ ps -ax | grep pemworker
$ kill -9 <process_id_of_pemworker>
ps -ax | grep pemagent
kill -9 <process_id_of_pemagent>
ps -ax | grep pemworker
kill -9 <process_id_of_pemworker>
# Enable and start pemagent service
$ sudo systemctl enable pemagent
$ sudo systemctl start pemagent
$ sudo systemctl status pemagent
sudo systemctl enable pemagent
sudo systemctl start pemagent
sudo systemctl status pemagent
```

6. Check the agent status on the PEM dashboard.


!!! Note
Any probes and jobs that require root permission or access to a file owned by another user (for example, enterprisedb) fail.
- Any probes and jobs that require root permission or access to a file owned by another user (for example, enterprisedb) fail.
- If you move the `agent.cfg` file from its default location to another, the PEM dashboard might display the agent status as “unknown”. See [Troubleshooting agent issues](troubleshooting_agent/#updating-configuration-file-path-agent-status-displaying-as-unknown), for more information.
1 change: 1 addition & 0 deletions product_docs/docs/pem/9/troubleshooting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,4 @@ In some situations, you might need to uninstall the PEM server, reinstall it, an
```shell
/usr/edb/pem/bin/configure-pem-server.sh
```

56 changes: 43 additions & 13 deletions product_docs/docs/pem/9/troubleshooting_agent.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,55 @@ If an agent was deleted from the PEM web client but still has an entry in the `p

The deleted agent is restored. However, the servers that were bound to that agent might appear to be down. To resolve this issue, modify the PEM agent properties of the server to add the bound agent again. After the successful modification, the servers appear as running properly.

## Using the command line to delete a PEM agent with down or unknown status

Using the PEM web interface to delete PEM agents with Down or Unknown status can be difficult if the number of such agents is large. In this situation, you can use the command line interface to delete Down or Unknown agents.
## Updating configuration file path (agent status displaying as unknown)

Use the following query to delete the agents that are Down for more than *N* number of hours:
If you move the agent configuration file (`agent.cfg`) from its default location `/usr/edb/pem/agent/etc` to another location, the PEM dashboard might display the agent status as “unknown”. In that case, you need to update the value of the agent configuration file path in the `pemagent` service file.

1. Use the following command to modify the `pemagent` service file as a superuser:

```shell
# Running as superuser
sudo vi /usr/lib/systemd/system/pemagent.service
```
UPDATE pem.agent SET active=false WHERE id IN
(SELECT a.id FROM pem.agent
a JOIN pem.agent_heartbeat b ON (b.agent_id=a.id)
WHERE a.id IN
(SELECT agent_id FROM pem.agent_heartbeat WHERE (EXTRACT (HOUR FROM now())-
EXTRACT (HOUR FROM last_heartbeat)) > <N> ));

2. Update the `agent.cfg` file path. For example, on a Redhat host, update the file path:

```shell
ExecStart=/usr/edb/pem/agent/bin/pemagent -c /usr/edb/pem/agent/etc/agent.cfg
```

Use the following query to delete the agents with an Unknown status:
3. Reload `systemd`, to update the modified service script:

```shell
sudo systemctl daemon-reload
```
UPDATE pem.agent SET active=false WHERE id IN
(SELECT id FROM pem.agent WHERE id NOT IN
(SELECT agent_id FROM pem.agent_heartbeat));

4. Restart the PEM agent:

```shell
sudo systemctl restart pemagent
```

## Using the command line to delete a PEM agent with down or unknown status

Using the PEM web interface to delete PEM agents with Down or Unknown status can be difficult if the number of such agents is large. In this situation, you can use the command line interface to delete Down or Unknown agents.

Use the following query to delete the agents that are Down for more than *N* number of hours:

```sql
UPDATE pem.agent SET active=false WHERE id IN
(SELECT a.id FROM pem.agent
a JOIN pem.agent_heartbeat b ON (b.agent_id=a.id)
WHERE a.id IN
(SELECT agent_id FROM pem.agent_heartbeat WHERE (EXTRACT (HOUR FROM now())-
EXTRACT (HOUR FROM last_heartbeat)) > <N> ));
```

Use the following query to delete the agents with an Unknown status:

```sql
UPDATE pem.agent SET active=false WHERE id IN
(SELECT id FROM pem.agent WHERE id NOT IN
(SELECT agent_id FROM pem.agent_heartbeat));
```

1 comment on commit edc24e9

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.