惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
Google DeepMind News
Google DeepMind News
Hugging Face - Blog
Hugging Face - Blog
D
Docker
F
Fortinet All Blogs
博客园 - 三生石上(FineUI控件)
Project Zero
Project Zero
Engineering at Meta
Engineering at Meta
J
Java Code Geeks
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Simon Willison's Weblog
Simon Willison's Weblog
S
Security Affairs
NISL@THU
NISL@THU
T
Tor Project blog
A
About on SuperTechFans
宝玉的分享
宝玉的分享
腾讯CDC
S
Schneier on Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
P
Privacy & Cybersecurity Law Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Stack Overflow Blog
Stack Overflow Blog
P
Privacy International News Feed
雷峰网
雷峰网
C
Cyber Attacks, Cyber Crime and Cyber Security
Vercel News
Vercel News
Cisco Talos Blog
Cisco Talos Blog
D
DataBreaches.Net
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Google Online Security Blog
Google Online Security Blog
Recorded Future
Recorded Future
L
LINUX DO - 热门话题
Microsoft Security Blog
Microsoft Security Blog
Latest news
Latest news
C
Check Point Blog
有赞技术团队
有赞技术团队
T
The Exploit Database - CXSecurity.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
云风的 BLOG
云风的 BLOG
SecWiki News
SecWiki News
Application and Cybersecurity Blog
Application and Cybersecurity Blog
爱范儿
爱范儿
月光博客
月光博客
V
Vulnerabilities – Threatpost
T
Threat Research - Cisco Blogs
P
Palo Alto Networks Blog
T
The Blog of Author Tim Ferriss
C
Cisco Blogs
Webroot Blog
Webroot Blog
S
Security @ Cisco Blogs

秋实-Allenyou 的小窝

【笔记】人工智能与模式识别 复习笔记 - 秋实-Allenyou 的小窝 【教程】使用 Keyd 将 Copilot 键映射为可用的组合键并修复触摸板防误触失效问题 机械革命无界 15X 的 Arch Linux 开荒指南 我在用什么?(2026 版) - 秋实-Allenyou 的小窝 关于 Next.js SSG 生成 RSS Feed 文件的另一思路 从零开始的 NixOS 体验 - 秋实-Allenyou 的小窝 2025:迷茫中转向 - 秋实-Allenyou 的小窝 我在用什么?(2025 版) - 秋实-Allenyou 的小窝 【杂谈】关于 AIGC 的一些思考 - 秋实-Allenyou 的小窝 【记录】一种在主机通过 Docker 容器名解析容器 IP 的方法 【记录】如何在 Next.js 中优雅的调用 Matomo 统计 从信号与系统角度看 OI/XCPC 中的傅里叶变换运用 - 秋实-Allenyou 的小窝 【杂谈】答《博客作者呀,我想采访你这 9 个问题!》 - 秋实-Allenyou 的小窝 使用 Golang 重写 gh-proxy - 秋实-Allenyou 的小窝 FurryCTF 2024 寒假赛 调试窗口 题解 2024:“我”的大学生活 - 秋实-Allenyou 的小窝 【游记】CCPC 2024 重庆站尾杀记 - 秋实-Allenyou 的小窝 【游记】ICPC 2024 亚洲区域赛南京站打铁记 - 秋实-Allenyou 的小窝 【杂谈】这次 Furrygooo 结束后我的一些体验 - 秋实-Allenyou 的小窝 【教程】使用阿里云 OSS + CDN 加速 Gravatar 【记录】 一次罗技鼠标驱动冲突问题的排查经历 - 秋实-Allenyou 的小窝 【记录】我是如何用 Next.js 重构我的博客的 - 秋实-Allenyou 的小窝 【教程】如何用 Git 快速搭建简单的 CI - 秋实-Allenyou 的小窝 我的DN42 Peering信息 - 秋实-Allenyou 的小窝 【进度】博客重构计划 - 秋实-Allenyou 的小窝 这是一个正经的2023总结 - 秋实-Allenyou 的小窝 【题解】Luogu P9769 [HUSTFC 2023] 简单的加法乘法计算题 2023新年谜题总结 - 秋实-Allenyou 的小窝 【教程】浅谈Linux服务器的一些基础安全技巧 - 秋实-Allenyou 的小窝 Goodbye, 2022~ - 秋实-Allenyou 的小窝 【教程】使用 Docker 开服,优雅地隔离不同版本JDK - 秋实-Allenyou 的小窝 【旧文补档】2020年终总结 & 2021新年计划 - 秋实-Allenyou 的小窝 【旧文补档】建立自己的私人网盘!在CentOS VPS上安装NextCloud - 秋实-Allenyou 的小窝 【旧文补档】2019,再见!2020,你好! - 秋实-Allenyou 的小窝 【旧文补档】新一代USB来袭,一起捋一捋USB的“前世今生” - 秋实-Allenyou 的小窝 【旧文补档】矩阵学习笔记 - 秋实-Allenyou 的小窝
【旧文补档】写个脚本监控你的VPS SolusVM面板适用 - 秋实-Allenyou 的小窝
2020-03-29 · via 秋实-Allenyou 的小窝

【旧文补档】写个脚本监控你的VPS SolusVM面板适用

2020/3/29

本文最后修改于 2263 天前,请注意文章内容的时效性。

前言

前些天我买了一台 Virmach 的大盘鸡,1 核 512MB 内存,500G 硬盘,4T 流量。这个配置做 NextCloud 还行,但 LAMP 环境比较消耗内存,而且 Virmach 的资源监控很严格,VPS 不能在 5 分钟以上的时间内达到 95-100%的使用率,在 2 小时内的平均使用率不能超过 50%,一旦违反就会直接关机,让我经常看到 NextCloud 的“同步失败”提示。所以我要写个脚本来监控 VPS,并且在 VPS 下线时自动开机。

实现

监控

使用 nmap,扫描 80 端口是否开放,未开放即为服务器下线。

rt=`nmap $ip -p 80 | grep "open" | wc -l`
if [ $rt == 1 ]; then # Do something...
fi

启动服务器

SolusVM 提供了 API,所以我们用 curl 发送 GET 请求调用 API 开机就好了。

API 地址http(s)://SolusVM面板地址/api/client/command.php?key=你的API Key&hash=你的API HASH&action=操作

Action备注
reboot重启
boot启动
status状态
shutdown关机
info信息
curl $boot_url; # boot_url 是 API 开机地址。

完整脚本

#!/bin/bash

ip="你服务器 IP"
svm_url="你服务器 SolusVM 面板地址"
api_key="你的 API Key"
api_hash="你的 API HASH"

boot_url=""${svm_url}"/api/client/command.php?key="${api_key}"&hash="${api_hash}"&action=boot"

while true; do
rt=`nmap $ip -p 80 | grep "open" | wc -l`
echo "Checked.";
if [ $rt == 0 ]; then
echo "Booting."
curl $boot_url;
if [ $? == 1 ]; then
echo "Error:Cannot Boot Server";
exit;
else
echo "Successful booted server.";
fi
fi
sleep 5;
done

使用方法

生成 API Key 和 API HASH

打开 SolusVM,找到你的服务器,然后点击 API-Generate。

SolusVM APISolusVM API

记好 API Key 和 API HASH。

修改脚本

把脚本里面的内容修改,填入服务器 IP/SolusVM 后台地址/API Key/API HASH,保存。

修复权限

chmod +x 脚本文件名

注册服务

新建/etc/systemd/system/服务名称.service,在里面写入这些内容。

[Unit]
Description=Monitor the status of the SolusVM panel-Based VPS and enable it when the server is offline.

[Service]
ExecStart=/bin/bash 脚本文件路径

[Install]
WantedBy=multi-user.target

保存,执行以下命令载入服务。

systemctl daemon-reload
systemctl enable 服务名
systemctl start 服务名

最后,你就可以享受它了!