gpt4 book ai didi

service - Centos 7 - 来自/etc/systemd/system/san.service 的服务未使用 systemctl start san.service 运行

转载 作者:行者123 更新时间:2023-12-04 19:36:29 26 4
gpt4 key购买 nike

我按照此链接的说明进行操作:https://www.thegeekdiary.com/centos-rhel-7-how-to-make-custom-script-to-run-automatically-during-boot/

但我有问题,因为我的服务没有运行。

我创建了一个脚本 startSanic2.sh 调用 startSanic.sh 脚本(我需要这个,因为当我用 & 手动启动它时,只有在这种情况下 session 没有过期)

这是我的脚本 startSanic2.sh

# cat /opt/horses/startSanic2.sh 
#!/bin/bash
cd /opt/horses
./startSanic.sh &

这是我的脚本 startSanic.sh
# cat /opt/horses/startSanic.sh 
#!/bin/bash
gunicorn horses.server:app --bind 0.0.0.0:9000 --worker-class sanic.worker.GunicornWorker --reload

运行后(./startSanic2.sh),它正在端口 9000 上成功运行。

startSanic.sh 和 startSanic2.sh 的权限为 755

然后我创建了新的 san.service
[root@testnn2 system]# cat /etc/systemd/system/san.service
[Unit]
Description=Description for sample script goes here
After=network.target

[Service]
Type=simple
ExecStart=/opt/horses/startSanic2.sh
TimeoutStartSec=0

[Install]
WantedBy=default.target

我运行这个命令:
systemctl daemon-reload

我运行这个命令
# systemctl enable san.service
Created symlink from /etc/systemd/system/default.target.wants/san.service to /etc/systemd/system/san.service

当我运行它时 - 没有任何 react :(
systemctl start san.service

我检查了 /etc/systemd/system我的 san.service 看起来像这样:
-rw-r--r--  1 root root  193 Apr  2 18:07 san.service

请在这个问题上帮助我,为什么什么都没有运行。

更新:环境变量
/etc/systemd/system/san.service的内容:
[Unit]
Description=Description for sample script goes here
After=network.target

[Service]
Type=simple
ExecStart=/opt/horses/startSanic2.sh
TimeoutStartSec=0
Environment="var1=value1"

[Install]
WantedBy=default.target

最佳答案

更改startSanic2.sh至:

#!/bin/bash

/opt/horses/startSanic.sh

确保它是可执行的:
$ sudo chmod +x /opt/horses/startSanic2.sh

还要确保 startSanic.sh是可执行的:
$ sudo chmod +x /opt/horses/startSanic.sh

重新加载守护进程并启用它:
$ sudo systemctl daemon-reload
$ sudo systemctl enable san.service
$ sudo systemctl start san.service

重启机器。

更新:

san.service 中设置环境变量:
[Unit]
Description=Description for sample script goes here
After=network.target

[Service]
Type=simple
ExecStart=/opt/horses/startSanic2.sh
TimeoutStartSec=0
Environment="REDIS_HOST=192.168.150.220"
Environment="REDIS_PORT=6379"

[Install]
WantedBy=default.target

关于service - Centos 7 - 来自/etc/systemd/system/san.service 的服务未使用 systemctl start san.service 运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55479450/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com