Skip to content

Commit a82ee38

Browse files
committed
fix: improve nginx reload and start error handling
1 parent 352b3f7 commit a82ee38

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

src/index.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,18 @@ stream {
133133

134134
let test = await exec(`sudo nginx -t`);
135135
if (test.stderr.includes('test is successful')) {
136-
await exec(`sudo systemctl reload nginx`);
137-
console.log('Nginx is running!');
136+
try {
137+
await exec(`sudo systemctl.reload nginx`);
138+
console.log('Nginx is running!');
139+
} catch (reloadErr) {
140+
console.warn('Nginx reload failed, attempting to start service:', reloadErr);
141+
try {
142+
await exec(`sudo systemctl start nginx`);
143+
console.log('Nginx started successfully');
144+
} catch (startErr) {
145+
console.error('Failed to start Nginx after reload failure:', startErr);
146+
}
147+
}
138148
} else {
139149
console.log('Nginx config test failed')
140150
}
@@ -202,9 +212,21 @@ server {
202212

203213
let test = await exec(`sudo nginx -t`);
204214
if (test.stderr.includes('test is successful')) {
205-
await exec(`sudo systemctl reload nginx`);
206-
console.log(`Nginx reloaded successfully for ${host}!`)
207-
response[host] = true
215+
try {
216+
await exec(`sudo systemctl.reload nginx`);
217+
console.log(`Nginx reloaded successfully for ${host}!`)
218+
response[host] = true
219+
} catch (reloadErr) {
220+
console.warn(`Reload failed for ${host}, attempting to start nginx:`, reloadErr);
221+
try {
222+
await exec(`sudo systemctl start nginx`);
223+
console.log(`Nginx started successfully for ${host}!`)
224+
response[host] = true
225+
} catch (startErr) {
226+
console.error(`Failed to start nginx for ${host}:`, startErr);
227+
response[host] = false
228+
}
229+
}
208230
} else {
209231
console.log(host, `Nginx config test failed for ${host}`)
210232
response[host] = false

0 commit comments

Comments
 (0)