Skip to content

Commit adae76b

Browse files
committed
feat: Add agent restart script with dynamic service naming and port management
1 parent 859b9fc commit adae76b

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

ecosystem.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const path = require('path');
2-
const serviceName = path.basename(__dirname);
2+
const namePrefix = path.basename(__dirname);
33

44
module.exports = {
55
apps: [{
6-
name: serviceName,
6+
name: `${namePrefix}-agent`,
77
script: 'pnpm start',
88
instances: 1,
99
autorestart: true,

packages/adapter-postgres/postgres.pre.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ postgres=>
22
-- create user
33
CREATE USER eliza WITH PASSWORD 'your_password';
44

5+
-- add CREATEDB permission to database user
6+
ALTER USER eliza WITH CREATEDB;
7+
58
-- switch to eliza role
69
SET ROLE eliza;
710

@@ -22,9 +25,6 @@ GRANT ALL PRIVILEGES ON DATABASE eliza TO eliza;
2225
GRANT USAGE ON SCHEMA public TO eliza;
2326
GRANT CREATE ON SCHEMA public TO eliza;
2427

25-
-- add CREATEDB permission to database user
26-
ALTER USER eliza WITH CREATEDB;
27-
2828
-- grant all permissions to specific schema (usually public)
2929
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO eliza;
3030
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO eliza;

scripts/restart-agent.sh

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
# switch to project root directory
4+
cd "$(dirname "$0")/.."
5+
6+
# load service port configurations from .env file
7+
if [ -f .env ]; then
8+
echo "Loading service port configurations from .env file..."
9+
export $(cat .env | grep "SERVER_PORT" | grep -v '^#' | xargs)
10+
else
11+
echo "Warning: .env file not found!"
12+
fi
13+
14+
# get project name prefix
15+
namePrefix=$(basename $(pwd))
16+
if [ ! -z "$APP_PREFIX" ]; then
17+
namePrefix=$APP_PREFIX
18+
fi
19+
20+
21+
cleanup_port() {
22+
# if get port failed, return directly
23+
if [ -z "$SERVER_PORT" ]; then
24+
echo "Skipping port cleanup for $service due to port not found"
25+
return
26+
fi
27+
28+
echo "Checking port $SERVER_PORT"
29+
30+
# find process using this port
31+
# pid can only get the first line of losf value
32+
local pid=$(lsof -ti:$SERVER_PORT | head -n 1)
33+
if [ ! -z "$pid" ]; then
34+
echo "Found process $pid using port $SERVER_PORT, killing it..."
35+
kill -9 $pid
36+
sleep 1
37+
fi
38+
}
39+
40+
41+
echo "Stopping agent..."
42+
pm2 stop "${namePrefix}-agent" | grep "${namePrefix}-agent"
43+
sleep 2
44+
cleanup_port
45+
46+
echo "Starting agent..."
47+
pm2 start "${namePrefix}-agent"

0 commit comments

Comments
 (0)