vk-ssl-auto-deploy 0.6.6 → 0.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/app.js +4 -4
- package/config.json +1 -1
- package/package.json +1 -1
- package/routes/cert.js +19 -19
package/README.md
CHANGED
|
@@ -56,8 +56,8 @@ vim config.json
|
|
|
56
56
|
- 按 ESC - 退出插入模式
|
|
57
57
|
- 输入 :wq - 保存并退出
|
|
58
58
|
- 输入 :q! - 不保存退出
|
|
59
|
-
- 输入 :w - 仅保存
|
|
60
|
-
|
|
59
|
+
- 输入 :w - 仅保存
|
|
60
|
+
|
|
61
61
|
**配置说明**
|
|
62
62
|
|
|
63
63
|
编辑 `config.json` 文件,主要修改3参数,`certSaveDir`、`nginxDir`、`key`
|
|
@@ -75,8 +75,8 @@ vim config.json
|
|
|
75
75
|
|
|
76
76
|
- `key`: 你的密钥
|
|
77
77
|
- `certSaveDir`: 证书存储目录,最终证书路径为 `${certSaveDir}/域名.crt`、`${certSaveDir}/域名.key`、`${certSaveDir}/域名.pem`
|
|
78
|
-
- `nginxDir`: 你的nginx的安装目录
|
|
79
|
-
- `domains`: 指定拉取的域名,不指定代表拉取你的所有域名证书
|
|
78
|
+
- `nginxDir`: 你的nginx的安装目录
|
|
79
|
+
- `domains`: 指定拉取的域名,不指定代表拉取你的所有域名证书
|
|
80
80
|
- `callbackCommand`: 一般不需要改
|
|
81
81
|
- `port`: 服务监听端口(默认 6001)(一般无需改动)
|
|
82
82
|
|
|
@@ -90,9 +90,9 @@ vim config.json
|
|
|
90
90
|
|
|
91
91
|
```bash
|
|
92
92
|
# 进入安装目录(需改成你的目录)
|
|
93
|
-
cd /usr/lib/node_modules/vk-ssl-auto-deploy
|
|
94
|
-
|
|
95
|
-
# 生成开机启动脚本
|
|
93
|
+
cd /usr/lib/node_modules/vk-ssl-auto-deploy
|
|
94
|
+
|
|
95
|
+
# 生成开机启动脚本
|
|
96
96
|
pm2 startup
|
|
97
97
|
|
|
98
98
|
# 启动服务
|
package/app.js
CHANGED
|
@@ -38,14 +38,14 @@ app.use((err, req, res, next) => {
|
|
|
38
38
|
res.locals.error = req.app.get('env') === 'development' ? err : {};
|
|
39
39
|
res.status(err.status || 500);
|
|
40
40
|
res.render('error');
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
|
|
44
44
|
// 启动服务器
|
|
45
45
|
const port = process.env.PORT || config.port;
|
|
46
46
|
const host = process.env.HOST || '0.0.0.0';
|
|
47
47
|
|
|
48
|
-
app.listen(port, host, () => {
|
|
48
|
+
app.listen(port, host, () => {
|
|
49
49
|
console.log('listenPort:', port)
|
|
50
50
|
});
|
|
51
51
|
|
package/config.json
CHANGED
package/package.json
CHANGED
package/routes/cert.js
CHANGED
|
@@ -44,8 +44,8 @@ let scheduledTaskTimer = null;
|
|
|
44
44
|
let lastExecutionDate = null;
|
|
45
45
|
let isTaskRunning = false;
|
|
46
46
|
let scheduledExecutionTime = null; // 固定的执行时间 { hour, minute }
|
|
47
|
-
let lastCountdownText = ''; // 上次打印的倒计时文本
|
|
48
|
-
let needWrite = false;
|
|
47
|
+
let lastCountdownText = ''; // 上次打印的倒计时文本
|
|
48
|
+
let needWrite = false;
|
|
49
49
|
|
|
50
50
|
// 文件锁路径
|
|
51
51
|
const LOCK_FILE = path.join(__dirname, '..', '.cert-deploy.lock');
|
|
@@ -584,10 +584,10 @@ async function executeDeployTask() {
|
|
|
584
584
|
|
|
585
585
|
/**
|
|
586
586
|
* 初始化定时任务
|
|
587
|
-
*
|
|
587
|
+
* 服务启动时随机确定一个执行时间
|
|
588
588
|
*/
|
|
589
589
|
function initScheduledTask() {
|
|
590
|
-
logger.info('[定时任务] 重新初始化定时任务...');
|
|
590
|
+
logger.info('[定时任务] 重新初始化定时任务...');
|
|
591
591
|
needWrite = true;
|
|
592
592
|
// 清除旧的定时器
|
|
593
593
|
if (scheduledTaskTimer) {
|
|
@@ -596,10 +596,10 @@ function initScheduledTask() {
|
|
|
596
596
|
|
|
597
597
|
// 生成固定的随机执行时间(只在服务启动时生成一次)
|
|
598
598
|
if (!scheduledExecutionTime) {
|
|
599
|
-
//
|
|
600
|
-
const randomMinute = Math.floor(Math.random() *
|
|
599
|
+
// 生成一天之间的随机分钟数(避开11:00 - 22:00)
|
|
600
|
+
const randomMinute = Math.floor(Math.random() * 780);
|
|
601
601
|
scheduledExecutionTime = {
|
|
602
|
-
hour:
|
|
602
|
+
hour: (22 + Math.floor(randomMinute / 60)) % 24,
|
|
603
603
|
minute: randomMinute % 60
|
|
604
604
|
};
|
|
605
605
|
|
|
@@ -635,7 +635,7 @@ function initScheduledTask() {
|
|
|
635
635
|
|
|
636
636
|
// 计算剩余时间(毫秒)
|
|
637
637
|
const remainingMs = targetTime - now;
|
|
638
|
-
const remainingSeconds = Math.floor(remainingMs / 1000);
|
|
638
|
+
const remainingSeconds = Math.floor(remainingMs / 1000);
|
|
639
639
|
const hours = Math.floor(remainingSeconds / 3600);
|
|
640
640
|
const minutes = Math.floor((remainingSeconds % 3600) / 60);
|
|
641
641
|
const seconds = remainingSeconds % 60;
|
|
@@ -648,7 +648,7 @@ function initScheduledTask() {
|
|
|
648
648
|
} else if (minutes > 0) {
|
|
649
649
|
// 超过1分钟:只显示分钟数
|
|
650
650
|
countdownText = `${minutes}分钟+ 后执行`;
|
|
651
|
-
} else if (seconds === 0){
|
|
651
|
+
} else if (seconds === 0) {
|
|
652
652
|
countdownText = `即将执行`;
|
|
653
653
|
} else {
|
|
654
654
|
// 1分钟内:进行秒级倒计时
|
|
@@ -657,11 +657,11 @@ function initScheduledTask() {
|
|
|
657
657
|
|
|
658
658
|
// 只有当倒计时文本发生变化时才打印
|
|
659
659
|
if (countdownText !== lastCountdownText && needWrite) {
|
|
660
|
-
if (countdownText === "即将执行") {
|
|
661
|
-
needWrite = false;
|
|
662
|
-
process.stdout.write(`\r[定时任务] ${countdownText}${' '.repeat(10)}`);
|
|
663
|
-
} else {
|
|
664
|
-
process.stdout.write(`\r[定时任务] 将在 ${countdownText}${' '.repeat(5)}`);
|
|
660
|
+
if (countdownText === "即将执行") {
|
|
661
|
+
needWrite = false;
|
|
662
|
+
process.stdout.write(`\r[定时任务] ${countdownText}${' '.repeat(10)}`);
|
|
663
|
+
} else {
|
|
664
|
+
process.stdout.write(`\r[定时任务] 将在 ${countdownText}${' '.repeat(5)}`);
|
|
665
665
|
}
|
|
666
666
|
lastCountdownText = countdownText;
|
|
667
667
|
}
|
|
@@ -671,20 +671,20 @@ function initScheduledTask() {
|
|
|
671
671
|
if (currentSecond === 0) {
|
|
672
672
|
if (currentHour === scheduledExecutionTime.hour && currentMinute === scheduledExecutionTime.minute) {
|
|
673
673
|
// 检查今天是否已经执行过
|
|
674
|
-
if (lastExecutionDate !== currentDate) {
|
|
674
|
+
if (lastExecutionDate !== currentDate) {
|
|
675
675
|
// 换行后输出触发信息
|
|
676
676
|
console.log('');
|
|
677
677
|
logger.success(
|
|
678
678
|
`[定时任务] 触发执行 - 当前时间: ${currentHour}:${currentMinute.toString().padStart(2, '0')}`
|
|
679
679
|
);
|
|
680
|
-
lastExecutionDate = currentDate;
|
|
680
|
+
lastExecutionDate = currentDate;
|
|
681
681
|
|
|
682
682
|
// 异步执行任务,使用try-catch确保异常不会影响定时器
|
|
683
683
|
executeDeployTask().catch(error => {
|
|
684
684
|
logger.error('[定时任务] 执行失败:', error);
|
|
685
|
-
}).finally(()=> {
|
|
686
|
-
needWrite = true;
|
|
687
|
-
lastCountdownText = "";
|
|
685
|
+
}).finally(() => {
|
|
686
|
+
needWrite = true;
|
|
687
|
+
lastCountdownText = "";
|
|
688
688
|
})
|
|
689
689
|
}
|
|
690
690
|
}
|