光猫折腾5 进程管理

in 日常 with 0 comment

简单好用

当脱离了Debian,失去了我常年使用的systemd,我不得不使用一个脚本使用nohup大法启动程序
可是,当你想要重启服务?停止服务?好麻烦,想想就头大
于是,我爆肝写了一个最简单的进程管理程序:ctrl
260行,实现了很多好用的功能!点我下载ctrl.gz 或者简单两行

cd /usr/data
curl https://hi.imzlh.top/usr/uploads/2024/03/2789379259.gz | gunzip - > ctrl
chmod +x ctrl
./ctrl help

Service Ctrl Manager

Usage:

  • ctrl [command] [service]|all
  • SERVICE_NAME=... SERVICE_CMD=... (LOG_FILE_PATH=... PID_FILE_PATH=...) ctrl [command]

Commands:

CommandUsage
startStart the service as a Daemon
stopStop the service
restartShutdown the service and Restart
statusPrint the PID(is running) of the service
runRun the services
debugTest the services unit
tailShow the TAIL of the services output
logsPrint the full services output
infoPrint the services info
markupMarkup servicesFile(e.g For StartAll)

写service文件

与systemctl的service配置不同,只需要简单5行

# 名称,不是很有用
export SERVICE_NAME="A Demo Service"
# 启动命令,数组
export SERVICE_CMD=("./app" "--param=value")
# 工作目录
export SERVICE_WORK_DIR="/usr/data/ddns/"
# PID与日志存储位置,必须唯一
NAME="ddns"
export PID_FILE_PATH="/run/.$NAME.pid"
export LOG_FILE_PATH="/run/.$NAME.log"

接下来将写好的配置放入脚本同目录下的文件夹中,如

开机自启管理

注意到了那个markup命令吗?没错,开机自启走起!
首先标记开机自启程序:

ctrl markup aliddns
ctrl markup clash

接下来,只需要将这一行写入/usr/local/osgi/local/j2re/bin/java

cd /usr/data/ && ./ctrl start all

你可以试试看,完美自启动!(其实本质是批量启动)

Responses