我试图创建一个运行控制台的服务,以便将来将来将所有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
编辑: 由于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文件
#!/usr/bin/env bash
/usr/bin/mysqldump -user -pass db_name >/root/copias/backupname.sql
hello-world.service
[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
感谢大家的帮助!
答案 0 :(得分:0)
我有一个首次启动安装服务,显示在控制台上,它看起来像:
[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做同样的事情