设置dll程序开机自动运行
财务后台服务(caiwu.service)最终正常启动全流程
第一步:排查并获取关键路径
在终端执行
在终端执行
which dotnet,获取到了 .NET 运行环境的真实绝对路径:/usr/local/bin/dotnet。第二步:创建专属的 Shell 启动脚本
- 新建并编辑脚本文件:
nano /home/haihong/start_caiwu.sh - 填入以下内容(核心是将上一步查到的正确路径写入脚本):
bash
#!/bin/bash
# 切换到财务软件的目录
cd "/home/haihong/财务软件/20260522-财务后台"
# 使用正确的 dotnet 绝对路径来加载 dll 文件
exec /usr/local/bin/dotnet "/home/haihong/财务软件/20260522-财务后台/主程序.dll"
- 按
Ctrl + O保存,回车确认,再按Ctrl + X退出编辑器。
第三步:赋予脚本可执行权限
执行命令:
执行命令:
chmod +x /home/haihong/start_caiwu.sh。第四步:配置 systemd 服务指向该脚本
- 编辑服务配置文件:
sudo nano /etc/systemd/system/caiwu.service - 确保
[Service]部分包含以下核心配置(指定用 root 身份调用刚才写的脚本,并开启自动重启):
ini
[Service]
User=root
Group=root
ExecStart=/home/haihong/start_caiwu.sh
Restart=always
TimeoutStartSec=120
- 保存并退出编辑器。
第五步:重载系统配置并启动服务
依次执行以下三条标准命令,让修改生效并清除之前的失败记录:
依次执行以下三条标准命令,让修改生效并清除之前的失败记录:
bash
sudo systemctl daemon-reload
sudo systemctl reset-failed caiwu.service
sudo systemctl restart caiwu.service
第六步:验证服务状态
执行
执行
sudo systemctl status caiwu.service,看到绿色的 Active: active (running) 即代表服务已成功启动并稳定运行。
浙公网安备 33010602011771号