python - 如何从系统服务运行 bash 脚本?
问题描述
所以我试图从一个 bash 脚本启动一个 tmux 屏幕,然后它将托管一个(python)discordbot。反过来,该 bash 脚本应该从系统服务启动,以便 discordbot 始终与物理服务器本身一起启动。似乎由于某种原因它卡在了某个地方……我一直在寻找解决方案,但一直找不到。
这是系统服务输出:
● ubuntubot.service - UbuntuBot
Loaded: loaded (/etc/systemd/system/ubuntubot.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2021-08-13 18:39:26 CEST; 1min 58s ago
Main PID: 27366 (tmux: server)
Tasks: 2 (limit: 19060)
Memory: 4.9M
CGroup: /system.slice/ubuntubot.service
├─27366 /usr/bin/tmux new-session -d -s ubuntubot
└─27367 -bash
这是我的服务文件:
[Unit]
Description=UbuntuBot
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
Type=simple
ExecStart=/usr/bin/bash /home/flynn/Minecraft/CreativeServer/DiscordBot/launchbot.sh start
Restart=always
RestartSec=5
这是我的 bash 脚本:
#!/bin/bash
#This script launches the Ubuntubot in a different tmux screen
#Start tmux ubuntu-session:
/usr/bin/tmux new-session -d -s ubuntubot
#Start UbuntuBot
/usr/bin/tmux send-keys -t ubuntubot "python3 ~/Minecraft/CreativeServer/DiscordBot/Ubuntubot.py" Enter
也许这是一种可怕的方法,我真的不知道......我只需要一些帮助,因为这让我自己很长时间:)
解决方案
推荐阅读
- python - 重新打包一个原来通过pip安装的修改库
- c# - 当文本框有焦点时,有没有办法让一些代码工作?
- python - Pandas:添加显示前一天、一周、一个月的值的列
- c# - 从 C# XML 函数返回字节 []
- javascript - 哪种 React 生命周期方法最适合在 prop 更改时进行 API 调用
- java - 如何在 Spring Mvc 中集成 instamojo 支付网关,实际上缺少集成代码
- entity-framework - EntityFramework 似乎在 AccountController 中缓存服务
- javascript - Three.js 中的模态弹出窗口没有响应
- python - 将一些 JSON 键转换为 Python 对象
- google-maps - Google 是否提供了他们在 Places API 中拥有的所有城市的导出功能?