【发布时间】:2019-08-24 01:20:03
【问题描述】:
我按照此链接中的说明进行操作: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