add sys service
This commit is contained in:
parent
53e704e0bf
commit
b343ef2ddd
26
circuit-recognition.service
Normal file
26
circuit-recognition.service
Normal file
@ -0,0 +1,26 @@
|
||||
[Unit]
|
||||
Description=Circuit Recognition Web Service
|
||||
After=network.target
|
||||
Wants=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
Group=root
|
||||
WorkingDirectory=/home/feie9454/elements_wires_congition
|
||||
Environment=PATH=/home/feie9454/elements_wires_congition/venv/bin
|
||||
ExecStart=/home/feie9454/elements_wires_congition/venv/bin/python main.py
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
SyslogIdentifier=circuit-recognition
|
||||
|
||||
# 安全设置
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
ProtectSystem=strict
|
||||
ReadWritePaths=/home/feie9454/elements_wires_congition
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
2
main.py
2
main.py
@ -77,4 +77,4 @@ if __name__ == '__main__':
|
||||
print(" - GET /static/<filename> (for static files)")
|
||||
print("=" * 50)
|
||||
|
||||
app.run(host='0.0.0.0', debug=True, port=25273)
|
||||
app.run(host='0.0.0.0', debug=True, port=12399)
|
||||
|
||||
63
manage_service.sh
Executable file
63
manage_service.sh
Executable file
@ -0,0 +1,63 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Circuit Recognition Service Management Script
|
||||
# 使用方法: ./manage_service.sh [install|start|stop|restart|status|logs|uninstall]
|
||||
|
||||
SERVICE_NAME="circuit-recognition"
|
||||
SERVICE_FILE="/home/feie9454/elements_wires_congition/circuit-recognition.service"
|
||||
SYSTEM_SERVICE_PATH="/etc/systemd/system/circuit-recognition.service"
|
||||
|
||||
case "$1" in
|
||||
install)
|
||||
echo "安装服务..."
|
||||
sudo cp "$SERVICE_FILE" "$SYSTEM_SERVICE_PATH"
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable "$SERVICE_NAME"
|
||||
echo "✅ 服务已安装并设置为开机自启"
|
||||
echo "使用 './manage_service.sh start' 启动服务"
|
||||
;;
|
||||
start)
|
||||
echo "启动服务..."
|
||||
sudo systemctl start "$SERVICE_NAME"
|
||||
echo "✅ 服务已启动"
|
||||
;;
|
||||
stop)
|
||||
echo "停止服务..."
|
||||
sudo systemctl stop "$SERVICE_NAME"
|
||||
echo "✅ 服务已停止"
|
||||
;;
|
||||
restart)
|
||||
echo "重启服务..."
|
||||
sudo systemctl restart "$SERVICE_NAME"
|
||||
echo "✅ 服务已重启"
|
||||
;;
|
||||
status)
|
||||
echo "服务状态:"
|
||||
sudo systemctl status "$SERVICE_NAME"
|
||||
;;
|
||||
logs)
|
||||
echo "查看服务日志:"
|
||||
sudo journalctl -u "$SERVICE_NAME" -f
|
||||
;;
|
||||
uninstall)
|
||||
echo "卸载服务..."
|
||||
sudo systemctl stop "$SERVICE_NAME"
|
||||
sudo systemctl disable "$SERVICE_NAME"
|
||||
sudo rm -f "$SYSTEM_SERVICE_PATH"
|
||||
sudo systemctl daemon-reload
|
||||
echo "✅ 服务已卸载"
|
||||
;;
|
||||
*)
|
||||
echo "使用方法: $0 {install|start|stop|restart|status|logs|uninstall}"
|
||||
echo ""
|
||||
echo "命令说明:"
|
||||
echo " install - 安装服务并设置开机自启"
|
||||
echo " start - 启动服务"
|
||||
echo " stop - 停止服务"
|
||||
echo " restart - 重启服务"
|
||||
echo " status - 查看服务状态"
|
||||
echo " logs - 实时查看服务日志"
|
||||
echo " uninstall - 卸载服务"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
Loading…
x
Reference in New Issue
Block a user