-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ts
More file actions
51 lines (39 loc) · 1.51 KB
/
install.ts
File metadata and controls
51 lines (39 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { execSync } from "node:child_process";
import { writeFileSync } from "node:fs";
import { resolve } from "node:path";
import { env } from "./utils/env";
const SERVICE_NAME = `bot-${env.BOT_USERNAME}`;
const description = `${env.BOT_USERNAME} service`;
const indexPath = resolve("./index.ts");
const workingDirectory = resolve(".");
const serviceContent = `
[Unit]
Description=${description}
After=network.target redis.service mysql.service telegram-bot-api.service nyx-bot-server.service nyx-bot-client-actions-server.service
[Service]
ExecStart=/usr/bin/env /root/.bun/bin/bun ${indexPath}
Restart=always
RestartSec=3
WorkingDirectory=${workingDirectory}
Environment=NODE_ENV=production
StandardOutput=journal
StandardError=journal
User=${process.env.SUDO_USER || process.env.USER || "bun"}
[Install]
WantedBy=multi-user.target
`.trim();
const serviceFilePath = `/etc/systemd/system/${SERVICE_NAME}.service`;
try {
console.log(`📝 Writing systemd service to: ${serviceFilePath}`);
writeFileSync(serviceFilePath, serviceContent);
console.log("🔄 Reloading systemd daemon...");
execSync("systemctl daemon-reexec");
execSync("systemctl daemon-reload");
console.log(`✅ Enabling ${SERVICE_NAME} service...`);
execSync(`systemctl enable ${SERVICE_NAME}`);
console.log(`🚀 Starting ${SERVICE_NAME} service...`);
execSync(`systemctl restart ${SERVICE_NAME}`);
console.log(`🎉 Service '${SERVICE_NAME}' is installed and running!`);
} catch (err) {
console.error("❌ Failed to install systemd service:", err);
}