Service Can';不要启动系统服务

Service Can';不要启动系统服务,service,centos,systemd,Service,Centos,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: disabl

我试图创建一个运行控制台的服务,以便将来将我的所有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
#!/usr/bin/env bash
/usr/bin/mysqldump -user -pass db_name >/root/copias/backupname.sql
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

编辑:
由于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
Edit2:完成了!我已经设法做到了这一点,目前正在工作,我将代码留在这里,以便它对其他人有用

hello-world.sh文件

#!/bin/bash

while $(sleep 30);
do
    echo "hello world"
done
#!/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
hello-world.timer

[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
#---------------------------------------------------------------------
#切换到tty6,以便允许安装问题的输入
#在此脚本末尾更改回tty1以显示正常引导
#来自systemd的消息。
#---------------------------------------------------------------------
执行官/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
#现在系统已经注册并添加了几个频道,
#我可以让安装返回到Anaconda主输出屏幕
#关于tty1
chvt 1
执行/dev/tty1
出口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
#/bin/bash
执行官/dev/tty6
chvt 6
美元(睡眠30);
做
回声“你好,世界”
完成
chvt 1
执行/dev/tty1
这对于你的尝试来说可能是过分的,但是如果你需要投入的话
在控制台中,您应该对tty6执行相同的操作。

尝试将
After=sysend user sessions.service
更改为
After=syslog.target
并查看是否有帮助。。否则,请确保您的脚本具有执行权限。。不工作:(,是的,所有文件都具有执行权限。已解决!有关信息,请参阅“Edit2”)由于crontab的问题,我需要在每天的特定时间执行控制台命令。我用这个例子来检查一切是否正常,一旦正常,就更改命令。下面是crontab命令的示例:
*/10****cd/usr/share/nginx/html/mywebsite.com;php wp-cron.php>/dev/null 2>&1
0*/3**date=date-I;zip-r/root/copias/copia archivos html网站$date.zip/usr/share/nginx/html
15***wget-q-O/dev/nullhttps://mywebsite.com/?run_plugin=key_0_0