├── README.md
├── app.js
└── imgs
├── 1.png
├── 2.png
├── 3.png
├── 4.png
├── 5.png
├── 6.png
└── 7.png
/README.md:
--------------------------------------------------------------------------------
1 | # Serv00服务器优雅的保活方案
2 | 本项目是在CMLiussss大佬的[博客](https://blog.cmliussss.com/p/Serv00-Socks5/)基础上对保活进行的改进,在部署前,请确保已经按博客内容完成了Socks5的部署并使用正常
3 |
4 | 在Serv00上使用Cron进行进程保活的情况下,发现Cron计划任务经常被清掉,导致进程存活时间很短,因而才有了这篇文章,对进程保活进行改进
5 |
6 | 这个方案利用了Serv00自带Apache服务器的Phusion Passenger插件功能,每次访问网页时可以唤醒Nodejs程序,因而不需要借助Cron就能够进行保活,自然没有了被杀Cron计划任务的烦扰
7 |
8 | ## 部署步骤
9 | - 登录Serv00面板,删除注册后自带的网站
10 | 
11 |
12 | - 点击Delete(purge website files)清空网站文件
13 | 
14 |
15 | - 创建新网站,域名填写你想用的域名,我这里使用的是注册时自带的,网站类型设置为Node.js,程序版本选择NOde.js v22.4.1
16 | 
17 |
18 | - SSH登录Serv00,输入cd domains/你的网站域名/public_nodejs/
19 | - 由于Serv00的Apache设置的是静态优先,因而此处public文件夹下不能有index.html,否则会显示静态页面,而不会执行nodejs程序,我选择的是直接将public改名为static,执行mv public static
20 | - 执行npm22 install express
21 | 
22 |
23 | - 修改app.js的第7行,填写你自己的Serv00用户名,再将app.js上传到服务器,完整路径是/home/你的用户名/domains/你的网站域名/public_nodejs/,修改完成后public_nodejs目录下应该和我一样
24 | 
25 |
26 | - 自此部署完成
27 |
28 | ## 测试
29 | - 用浏览器输入一下你创建的网站域名,正常就能看到默认的页面
30 | 
31 |
32 | - 页面能够正常显示,返回SSH终端,输入ps aux可以看到新开了nodejs进程,稍带片刻,就能看到你的代理进程成功启动了
33 | 
34 |
35 | - Nodejs程序运行日志可以通过面板网站的log中查看,也可以在SSH终端里查看,日志文件的完整路径为/home/你的用户名/domains/你的网站域名/logs/error.log
36 |
37 | ## 后续
38 | - SOCKS代理进程由Nodejs进程负责保活,10秒钟检查一次,因此后续只需要关注Nodejs进程的保活就可以了
39 | - Nodejs进程的保活,可以手动访问网站进行,也可以通过自动化方案监控网站进行,就不再赘述了
40 | - 自动化网页监控项目推荐[upptime](https://github.com/upptime/upptime),不需要有服务器,只需要有Github账号就能够进行部署
41 | - 完结撒花~~
42 |
--------------------------------------------------------------------------------
/app.js:
--------------------------------------------------------------------------------
1 | const express = require("express");
2 | const path = require("path");
3 | const exec = require("child_process").exec;
4 | const app = express();
5 | const port = 3000;
6 |
7 | const user = "Serv00登录用户名"; //此处修改为Serv00的用户名
8 | const pName = "s5";
9 |
10 | app.use(express.static(path.join(__dirname, 'static')));
11 |
12 | function keepWebAlive() {
13 | const currentDate = new Date();
14 | const formattedDate = currentDate.toLocaleDateString();
15 | const formattedTime = currentDate.toLocaleTimeString();
16 |
17 | exec(`pgrep -laf ${pName}`, (err, stdout) => {
18 | const Process = `/home/${user}/.${pName}/${pName} -c /home/${user}/.${pName}/config.json`;
19 |
20 | if (stdout.includes(Process)) {
21 | console.log(`${formattedDate}, ${formattedTime}: Web Running`);
22 | } else {
23 | exec(`nohup ${Process} >/dev/null 2>&1 &`, (err) => {
24 | if (err) {
25 | console.log(`${formattedDate}, ${formattedTime}: Keep alive error: ${err}`);
26 | } else {
27 | console.log(`${formattedDate}, ${formattedTime}: Keep alive success!`);
28 | }
29 | });
30 | }
31 | });
32 | }
33 |
34 | setInterval(keepWebAlive, 10 * 1000);
35 |
36 | app.listen(port, () => {
37 | console.log(`Server is listening on port ${port}!`);
38 | });
39 |
--------------------------------------------------------------------------------
/imgs/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hkfires/Keep-Serv00-Alive/2f4d1568179619d4d5dd3d52cf408e50c0564abd/imgs/1.png
--------------------------------------------------------------------------------
/imgs/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hkfires/Keep-Serv00-Alive/2f4d1568179619d4d5dd3d52cf408e50c0564abd/imgs/2.png
--------------------------------------------------------------------------------
/imgs/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hkfires/Keep-Serv00-Alive/2f4d1568179619d4d5dd3d52cf408e50c0564abd/imgs/3.png
--------------------------------------------------------------------------------
/imgs/4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hkfires/Keep-Serv00-Alive/2f4d1568179619d4d5dd3d52cf408e50c0564abd/imgs/4.png
--------------------------------------------------------------------------------
/imgs/5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hkfires/Keep-Serv00-Alive/2f4d1568179619d4d5dd3d52cf408e50c0564abd/imgs/5.png
--------------------------------------------------------------------------------
/imgs/6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hkfires/Keep-Serv00-Alive/2f4d1568179619d4d5dd3d52cf408e50c0564abd/imgs/6.png
--------------------------------------------------------------------------------
/imgs/7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hkfires/Keep-Serv00-Alive/2f4d1568179619d4d5dd3d52cf408e50c0564abd/imgs/7.png
--------------------------------------------------------------------------------