无法启动 systemd 服务



我正在尝试创建一个运行控制台的服务,以便将来将所有 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

你好世界服务文件

[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

编辑: 由于 crontab 的问题,我需要做的是每天在特定时间执行控制台命令。 我使用此示例来检查一切是否正常,一旦正常工作,请更改命令。 下面是一个 crontab 命令的示例:

*/10 * * * * cd /usr/share/nginx/html/mywebsite.com; php wp-cron.php >/dev/null 2>&1
0 0 */3 * * date=date -I; zip -r /root/copias/copia-archivos-html-webs$date.zip /usr/share/nginx/html`
15 15 * * * wget -q -O /dev/null https://mywebsite.com/?run_plugin=key_0_0

编辑2:完成!我已经设法做到了并且现在可以工作了,我将代码留在这里,以便对其他人有用

hello-world.sh 文件

#!/usr/bin/env bash
/usr/bin/mysqldump -user -pass db_name >/root/copias/backupname.sql

你好世界.服务

[Unit]
Description=CopiaSql
[Service]
Type=oneshot
ExecStart=/bin/bash /usr/share/nginx/html/scripts-systemd/hello-world.sh
[Install]
WantedBy=multi-user.target

你好世界计时器

[Unit]
Description=Runs every 2 minutes test.sh
[Timer]
OnCalendar=*:0/2
Unit=hello-world.service
[Install]
WantedBy=timers.target

感谢大家的帮助!

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

[Unit]
After=multi-user.target
# tty getty service login promts for tty1 & tty6
# will not be seen until this install completes.
Before=getty@tty1.service getty@tty6.service
[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 执行相同的操作

最新更新