我最近在机器上安装了Fedora 22,它使用的是systemd初始化系统。
我一直在阅读它,现在我需要为postgresql创建一个systemd启动脚本。
为了进行测试,我创建了以下shell脚本hello_world
#! /bin/sh
# testing systemctl script
start() {
echo "Executing Start"
echo "Testing 01"
echo "Testing 02"
echo "Testing 03"
}
stop() {
echo "Stopping Hello World Script"
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 2
start
;;
*) exit 1
esac
当我使用终端运行它时,它会执行我所期望的并回显字符串
. hello_world start
这回显“启动Hello World脚本”,然后将其放在/ usr / lib / systemd / scripts中
然后,我尝试如下创建systemd服务脚本hello_world.service
[Unit]
Description=Hello World Testing Script
[Service]
Type=oneshot
ExecStart=/usr/lib/systemd/scripts/hello_world start
ExecStop=/usr/lib/systemd/scripts/hello_world stop
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
我将其放在/ usr / lib / systemd / system中并尝试执行
systemctl start hello_world.service
它没有给出任何错误,但是我没有得到单独执行hello_world脚本时所期望的回显字符串。
所以我无法确定它是否确实有效,我错过了什么吗?为什么systemctl命令没有回显脚本中的字符串?
似乎脚本的输出未发送到终端,而是被重定向到status命令。
服务运行后
# systemctl start hello_world.service
我可以在状态中查看我的输出
# systemctl status hello_world.service
它将包括脚本的任何输出,例如波纹管
Apr 28 10:18:00 centos7.adminserv systemd[1]: Starting Hello World Testing S....
Apr 28 10:18:00 centos7.adminserv hello_world[18164]: Executing Start
Apr 28 10:18:00 centos7.adminserv hello_world[18164]: Testing 01
Apr 28 10:18:00 centos7.adminserv hello_world[18164]: Testing 02
Apr 28 10:18:00 centos7.adminserv hello_world[18164]: Testing 03
Apr 28 10:18:00 centos7.adminserv systemd[1]: Started Hello World Testing Sc....
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句