1 建立文件,模拟启动(端口873)
touch /etc/rsyncd.conf
rsync --daemon
2 查看pid file,通过pid进程停止rsync
cat /etc/rsyncd.conf
打开pid file
pid file=/var/run/rsyncd.pid
获取pid进程号
cat /var/run/rsyncd.pid
3 编写脚本内容
#!/bin/bash
# chkconfig: 2345 22 61
# description: start rsync and stop rsync scripts.
. /etc/init.d/functions
pidfile="/var/run/rsyncd.pid"
start_rsync(){
if [ -f $pidfile ]
then
echo "rsync is runnning"
else
rsync --daemon
action "rsync is started" /bin/true
fi
}
stop_rsync(){
if [ -f $pidfile ]
then
kill -USR2 `cat $pidfile`
rm -f ${pidfile}
action "rsync is stopped" /bin/true
else
action "rsync have already been stopped" /bin/fasle
fi
}
case "$1" in
start)
start_
本文介绍了如何创建并使用pid文件来管理Rsync服务。首先,通过建立rsyncd.conf文件并模拟启动服务。接着,查看并解析pid文件以获取rsync进程ID。然后,编写了一个启动脚本`rsyncd.sh`,并将其添加为开机启动项,确保服务能在系统启动时自动运行。最后,通过`chkconfig`命令进行配置,确保服务开机自启。
订阅专栏 解锁全文
344

被折叠的 条评论
为什么被折叠?



