This repository has been archived by the owner on Nov 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpm2_manager.ps1
117 lines (111 loc) · 3.69 KB
/
pm2_manager.ps1
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
$continueLoop = $true
try {
$nodeVersion = node -v
$versionParts = $nodeVersion.Split(".")
$majorVersion = [int]$versionParts[0].TrimStart("v")
if ($majorVersion -lt 16) {
Write-Host "Node.js sürümü 16'dan küçüktür."
exit
}
npm -v
Clear-Host
}
catch {
Write-Host "Hata Oluştu: $($_.Exception.Message)"
exit
}
$moduleName = "pm2"
$command = "npm ls -g $moduleName"
$result = Invoke-Expression $command
if ($result -match "$moduleName@") {
Write-Host "$moduleName modülü yüklüdür."
} else {
Write-Host "$moduleName modülü yüklü değildir. Yükleniyor..."
Invoke-Expression "npm install -g $moduleName"
Write-Host "$moduleName modülü yüklendi."
}
while ($continueLoop) {
Clear-Host
Write-Host "1. Projeyi başlat (açılış için)" -ForegroundColor Green
Write-Host "2. Projeyi yeniden başlat" -ForegroundColor Green
Write-Host "3. Projeyi kapat" -ForegroundColor Green
Write-Host "4. Proje durumu" -ForegroundColor Green
Write-Host "5. Log" -ForegroundColor Green
Write-Host "6. Kapat" -ForegroundColor Green
Write-Host
Write-Host "Seçiminizi girin" -ForegroundColor Yellow
$choice = Read-Host ":"
switch ($choice) {
"1" {
try {
Write-Host "Başlatılacak dosya (index.js)" -ForegroundColor Blue
$path = Read-Host ":"
if ($path -eq "") {
$path = "index.js"
}
pm2 start $path --exp-backoff-restart-delay=100
} catch {
Write-Host "Hata Oluştu: $($_.Exception.Message)"
}
Write-Host "Devam etmek için Enter tuşuna basın..."
$null = [System.Console]::In.ReadLine()
}
"2" {
try {
pm2 restart all
} catch {
Write-Host "Hata Oluştu: $($_.Exception.Message)"
}
Write-Host "Devam etmek için Enter tuşuna basın..."
$null = [System.Console]::In.ReadLine()
}
"3" {
try {
pm2 stop all
} catch {
Write-Host "Hata Oluştu: $($_.Exception.Message)"
}
Write-Host "Devam etmek için Enter tuşuna basın..."
$null = [System.Console]::In.ReadLine()
}
"4" {
Write-Host "1) status" -ForegroundColor Blue
Write-Host "2) monit" -ForegroundColor Blue
$path = Read-Host ":"
try {
switch ($path) {
"1" {
pm2 status
}
"2" {
pm2 monit
}
Default {
pm2 log
}
}
} catch {
Write-Host "Hata Oluştu: $($_.Exception.Message)"
}
Write-Host "Devam etmek için Enter tuşuna basın..."
$null = [System.Console]::In.ReadLine()
}
"5" {
try {
pm2 log
} catch {
Write-Host "Hata Oluştu: $($_.Exception.Message)"
}
Write-Host "Devam etmek için Enter tuşuna basın..."
$null = [System.Console]::In.ReadLine()
}
"6" {
$continueLoop = $false
}
default {
Write-Host "Geçersiz seçenek."
Write-Host "Devam etmek için Enter tuşuna basın..."
$null = [System.Console]::In.ReadLine()
}
}
}