shell编写rsync启动脚本(shell脚本基本命令)
admin2024-08-14 10:15:38Linux运维
[root@shnne ~]# cat rsync_start.sh
#!/bin/bash
# chkconfig: 2345 58 80
# description: start and stop service for rsync
. /etc/init.d/functions
RSYNCBIN="/usr/bin/rsync"
PIDFILE="/var/run/rsyncd.pid"
start(){
if [ -f "$PIDFILE" ]
then
action "Rsync service is running." /bin/false
else
$RSYNCBIN --daemon
sleep 1
action "Starting rsync service." /bin/true
fi
}
stop(){
if [ -f $PIDFILE ]
then
kill -USR2 `cat $PIDFILE`
rm -f $PIDFILE
sleep 1
action "Stopping rsync service." /bin/true
else
action "Rsync service has been stopped." /bin/false
fi
}
case "$1" in
start)
start
RETVAL=$?
;;
stop)
stop
RETVAL=$?
;;
restart)
stop
start
RETVAL=$?
;;
*)
echo "USAGE:$0 {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL