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

问题描述 投票:0回答:1

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

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

我创建了一个脚本startSanic2.sh,它调用startSanic.sh脚本(我需要这个,因为当我手动启动它时,仅在这种情况下会话未过期)

这是我的脚本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

当我运行它 - 没有任何反应:(

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
service centos systemd init.d systemctl
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.