Linux上服务的启动,停止和重启
(1)查看所有的服务service
Usage: service < option > | --status-all | [ service_name [ command | --full-restart ] ]
service --status-all
[ + ]acpid
[ - ]anacron
[ - ]apparmor
[ ? ]apport
[ + ]avahi-daemon
[ + ]bluetooth
[ - ]brltty
[ ? ]console-setup
[ + ]cron
[ + ]cups
[ + ]cups-browsed
[ - ]dbus
[ ? ]dns-clean
[ + ]friendly-recovery
[ - ]grub-common
[ ? ]irqbalance
[ + ]kerneloops
[ ? ]killprocs
[ ? ]kmod
[ ? ]lightdm
[ ? ]networking
[ ? ]ondemand
[ ? ]pppd-dns
[ - ]procps
[ - ]pulseaudio
[ ? ]rc.local
[ + ]resolvconf
[ - ]rsync
[ + ]rsyslog
[ + ]saned
[ ? ]sendsigs
[ ? ]speech-dispatcher
[ - ]sudo
[ ? ]thermald
[ - ]udev
[ ? ]umountfs
[ ? ]umountnfs.sh
[ ? ]umountroot
[ - ]unattended-upgrades
[ - ]urandom
[ + ]vboxadd
[ + ]vboxadd-service
[ - ]vboxadd-x11
[ +]vpnagentd
[ - ]x11-common
可以看出vpnagetd服务是启动起来的。
ps -elf | grep vpnagentd
5 S root 67161553080 0 - 10845 futex_ 21:43 ? 00:00:00 /opt/cisco/anyconnect/bin/vpnagentd
0 S berry 69662122080 0 -1172 pipe_w 21:48 pts/5 00:00:00 grep --color=auto vpnagentd
ps -elf | grep vpnagentd | grep -v berry
5 S root 67161553080 0 - 10845 futex_ 21:43 ? 00:00:00 /opt/cisco/anyconnect/bin/vpnagentd
berry那一条是运行当前命令出现的。
查看当前vpnagentd这个服务所占用的端口号和相关ip地址和pid和服务名称
sudo netstat -anp | grep 6716
tcp 0 0 127.0.0.1:29754 0.0.0.0:* LISTEN 6716/vpnagentd
unix2 [ ] DGRAM 75522 6716/vpnagentd
利用service+服务名称+start/stop/restart对服务进行启动,停止和重启
(1)一种是可以使用service脚本来调度,如:
service 服务名 start
service 服务名 stop
service 服务名 restart
service vpnagentd status
vpnagentd is stopped
sudo service vpnagentd start
Starting up Cisco AnyConnect Secure Mobility Client Agent
service vpnagentd status
vpnagentd (pid 7000) is running
service vpnagentd restart
Shutting down Cisco AnyConnect Secure Mobility Client Agent
Starting up Cisco AnyConnect Secure Mobility Client Agent
service vpnagentd status
vpnagentd (pid 7020) is running
(2)一种是直接执行某个服务自己的管理脚本,以vpnagetd服务为例
/etc/init.d/vpnagentdstart
/etc/init.d/vpnagentd stop
/etc/init.d/vpnagentd restart
service vpnagentd status
vpnagentd (pid 7393) is running
sudo /etc/init.d/vpnagentd stop
Shutting down Cisco AnyConnect Secure Mobility Client Agent
service vpnagentd status
vpnagentd is stopped
sudo /etc/init.d/vpnagentd start
Starting up Cisco AnyConnect Secure Mobility Client Agent
service vpnagentd status
vpnagentd (pid 7707) is running
sudo netstat -anp | grep 7707
tcp 0 0 127.0.0.1:29754 0.0.0.0:* LISTEN 7707/vpnagentd
unix2 [ ] DGRAM 78741 7707/vpnagentd
端口号仍然是29754。
页:
[1]