shell脚本管理服务

故事扮演 提交于 2020-01-15 01:09:27

本地检查端口方法

netstat -lntup ss -lntup lsof i:port

远程检查端口方法

telnet ip port /nc ip port /nmap

进程检查

ps -ef/ ps aux

测试连接

 ping -c1 -i1 -W1 ip|url /curl /wget -q --spider ip|url

centos6

mv rsyncd.sh /etc/init.d/
chmod +x /etc/init.d/rsyncd.sh
chkconfig --add rsyncd.sh
cat rsyncd.sh
#!/bin/bash
# chkconfig: 2345 99 98

choice=$1
path=/var/run/rsyncd.pid
case "$choice" in
        start)
                [ -f $path ] || rsync --daemon
        ;;
        stop)
                [ -f $path ] && kill `cat $path`
        ;;
        restart)
                [ -f $path ] && kill `cat $path`
                sleep 1
                rsync --daemon
        ;;
        *)
                echo error
esac
可以使用 chkconfig 服务名称 off/on 进行管理

centos7

[root@manager ~]# cat /usr/lib/systemd/system/rsyncd-new.service 
[Unit]
After=network.target remote-fs.target依赖服务
Description=fast remote file copy program daemon注释
ConditionPathExists=/etc/rsyncd.conf

[Service]
Type=forking服务模式守护进程
ExecStart=/root/rsyncd.sh start加执行权限
ExecStop=/root/rsyncd.sh stop
ExecRestart=/root/rsyncd.sh restart

[Install]
WantedBy=multi-user.target运行级别
可以使用systemctl 文件名称进行管理
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!