bash - SHC 编译脚本无法使用 systemctl 运行
问题描述
我有一个非常简单的 bash 脚本,叫做 test。
#!/bin/bash
while true
do
currdate=$(date +%d/%m/%Y-%H:%M:%S)
echo -e "\n$currdate ..."
sleep 1
done
从命令行运行它完全符合预期。
我用 SHC 编译的如下:
shc -r -U -f test.sh -o test
从命令行运行它按预期工作。
我已经设置使用 systemctl 运行它,添加了我的配置文件/etc/init.d
和这个引用test
如果test
是我未编译的 bash 脚本,则systemclt start test
可以正常工作。如果我交换测试并将其替换为已编译的版本,则它会失败。
systemctl 状态显示:
test.service - LSB: Test
Loaded: loaded (/etc/init.d/test; generated; vendor preset: disabled)
Active: failed (Result: exit-code) since Tue 2020-02-18 15:38:05 GMT; 6s ago
Docs: man:systemd-sysv-generator(8)
Process: 18089 ExecStart=/etc/init.d/test start (code=exited, status=7)
Tasks: 2
CGroup: /system.slice/test.service
├─18096 /home/rocket/test -c >
└─18142 sleep 1
Feb 18 15:38:05 linux-c0a9 systemd[1]: test.service: Control process exited, code=exited status=7
Feb 18 15:38:05 linux-c0a9 systemd[1]: Failed to start LSB: Test.
Feb 18 15:38:05 linux-c0a9 systemd[1]: test.service: Unit entered failed state.
Feb 18 15:38:05 linux-c0a9 systemd[1]: test.service: Failed with result 'exit-code'.
journalctl 显示:
Feb 18 15:38:05 linux-c0a9 systemd[1]: Starting LSB: Test...
Feb 18 15:38:05 linux-c0a9 test[18089]: Starting test
Feb 18 15:38:05 linux-c0a9 test[18089]: 18/02/2020-15:38:05 ...
Feb 18 15:38:05 linux-c0a9 test[18089]: ..failed
Feb 18 15:38:05 linux-c0a9 systemd[1]: test.service: Control process exited, code=exited status=7
Feb 18 15:38:05 linux-c0a9 systemd[1]: Failed to start LSB: Test.
Feb 18 15:38:05 linux-c0a9 systemd[1]: test.service: Unit entered failed state.
Feb 18 15:38:05 linux-c0a9 systemd[1]: test.service: Failed with result 'exit-code'.
有谁知道为什么会失败以及如何阻止它失败?
我只是使用 SHC 来阻止用户编辑脚本,而不是为了任何安全等。
谢谢
解决方案
我想我可能已经解决了这个问题。
我在 /etc/init.d 中的脚本正在调用/home/rocket/test
当它是一个 bash 文件时它很好,当它被编译时它停止工作。
为了让它工作,我将 test 更改为始终是一个 bash 文件,该文件调用位于/home/rocket/bin/test
推荐阅读
- numpy - 即使在 cmd 中运行 pip install numpy 后,我也无法在 pycharm 中导入 numpy 并显示错误
- php - imagick 无法显示转换结果
- python - python django当我点击他的名字时如何只显示个人员工的信息
- python - 传统知识 | 制作 TTK 样式时图像“pyimage1”不存在
- javascript - 除非我刷新页面,否则 Mmenu 不会打开菜单
- unit-testing - 如何使用 DatabaseGenerated 字段对实体进行单元测试?
- firebase - Flutter 无法调用回调函数进行 Firebase 云混乱
- python - 尝试在 Mac 上使用 Python3 安装 MetaTrader5
- c# - 使用 lstListbox.Items.Add(oClass) 到另一个窗口的列表框
- node.js - 为什么我的 node.js 服务器不能在 iisnode 下运行?