我必须创建一个在启动时启动的 devil。它目前位于 /etc/init.d 中,由于我的运行级别为 5,因此我在 /etc/rc5.d 中创建了一个符号链接,但脚本中的“start”案例在启动期间不会启动。我做错了什么?我应该尝试一些不同于 init.d 的东西吗?提前致谢
#!/bin/bash
case "$1" in
start)
cato=$$
if [ -e devil.pid ]
then
echo "Already running"
sleep 3
else
sleep 1
echo $$ > devil.pid
echo "$datee Running service with PID: $cato" >> devil.log
while true
do
datee=$(date +"[%Y-%m-%d %H:%M:%S]")
echo "$datee I'm alive" >> devil.log
sleep 3
done
fi
;;
stop)
if [ -e devil.pid ]
then
cato=$( cat devil.pid )
echo "$datee Stopping service with PID: $cato" >> devil.log
sleep 1
kill -9 $cato
rm -rf devil.pid
else
echo "I'm dead"
sleep 2
fi
;;
restart)
if [ -e devil.pid ]
then
cato=$( cat devil.pid )
kill -9 $cato
rm -rf devil.pid
echo $$ > devil.pid
while true
do
echo "Restarting with PID $cato" >> devil.log
sleep 2
done
else
echo "I'm dead"
sleep 2
fi
;;
esac