无法启动系统服务

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

[我正在尝试创建一个运行控制台的服务,将来将所有crontab命令转换为systemd,但我总是会收到此错误,我尝试了不同的教程和相同的问题。

# systemctl status hello-world.service
● hello-world.service - Hello World Service
   Loaded: loaded (/usr/lib/systemd/system/hello-world.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since mié 2019-10-09 10:06:59 CEST; 4s ago
  Process: 26080 ExecStart=/usr/share/nginx/html/scripts-systemd/hello-world.sh (code=exited, status=203/EXEC)
 Main PID: 26080 (code=exited, status=203/EXEC)

oct 09 10:06:59 ns37 systemd[1]: Started Hello World Service.
oct 09 10:06:59 ns37 systemd[1]: hello-world.service: main process exited, code=exited, status=203/EXEC
oct 09 10:06:59 ns37 systemd[1]: Unit hello-world.service entered failed state.
oct 09 10:06:59 ns37 systemd[1]: hello-world.service failed.

hello-world.sh文件

#!/bin/bash

while $(sleep 30);
do
    echo "hello world"
done

hello-world.service文件

[Unit]
Description=Hello World Service
After=systend-user-sessions.service

[Service]
Type=simple
ExecStart=/usr/share/nginx/html/scripts-systemd/hello-world.sh

[Install]
WantedBy=multi-user.target

我正在使用Centos 7

service centos systemd
1个回答
0
投票

我有一个首次启动安装服务,显示在控制台上,它看起来像:

[Unit]
After=multi-user.target
# tty getty service login promts for tty1 & tty6
# will not be seen until this install completes.
[email protected] [email protected]

[Service]
Type=oneshot
ExecStart=/bin/bash -c "export TERM=vt100;/var/ssi/firstboot_install.sh"
StandardOutput=tty
StandardInput=tty

[Install]
WantedBy=multi-user.target

我运行的脚本也要启动此代码

#---------------------------------------------------------------------
# Switch to tty6 so input is allowed from installation questions
# Change back to tty1 at end of this script to show normal booting
# messages from systemd.
#---------------------------------------------------------------------
exec < /dev/tty6 > /dev/tty6
chvt 6

在此脚本的结尾,我将其改回了

# Now that the system has been registered and has a few channels added,
# I can have the installation go back to the main Anaconda output screen
# on tty1
chvt 1
exec < /dev/tty1 > /dev/tty1

exit 0

这可能不是您想要的,但是您可以根据需要进行调整。此处的目标是在控制台上显示在引导序列期间开始的内容。我的脚本询问了许多安装问题,其中tty1(控制台)上不允许输入,这就是为什么我更改为tty6以便在首次引导安装期间允许输入的原因。

您的脚本尝试:

#!/bin/bash

exec < /dev/tty6 > /dev/tty6
chvt 6

while $(sleep 30);
do
  echo "hello world"
done

chvt 1
exec < /dev/tty1 > /dev/tty1

对于您想做的事情,这可能是多余的,但是如果您需要输入在控制台上,您应该使用tty6

执行相同操作
© www.soinside.com 2019 - 2024. All rights reserved.