Linux服务查看 启动 停止 和重启

Linux上服务的启动,停止和重启

(1)查看所有的服务

复制代码

[berry@berry:practice] service
Usage: service < option > | --status-all | [ service_name [ command | --full-restart ] ]
[berry@berry:practice] 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
 [ + ]  agentd
 [ - ]  x11-common

复制代码

可以看出agetd服务是启动起来的。

复制代码

[berry@berry:practice] ps -elf | grep agentd
5 S root      6716  1553  0  80   0 - 10845 futex_ 21:43 ?        00:00:00 /opt/cisco/anyconnect/bin/agentd
0 S berry     6966  2122  0  80   0 -  1172 pipe_w 21:48 pts/5    00:00:00 grep --color=auto agentd
[berry@berry:practice] ps -elf | grep agentd | grep -v berry
5 S root      6716  1553  0  80   0 - 10845 futex_ 21:43 ?        00:00:00 /opt/cisco/anyconnect/bin/agentd

复制代码

berry那一条是运行当前命令出现的。
查看当前agentd这个服务所占用的端口号和相关ip地址和pid和服务名称

[berry@berry:practice] sudo netstat -anp | grep 6716
tcp        0      0 127.0.0.1:29754         0.0.0.0:*               LISTEN      6716/agentd  
unix  2      [ ]         DGRAM                    75522    6716/agentd  

利用service+服务名称+start/stop/restart对服务进行启动,停止和重启

(1)一种是可以使用service脚本来调度,如:

service 服务名 start

service 服务名 stop

service 服务名 restart

复制代码

[berry@berry:practice] service agentd status
agentd is stopped 
[berry@berry:practice] sudo service agentd start
Starting up Cisco AnyConnect Secure Mobility Client Agent
[berry@berry:practice] service agentd status
agentd (pid 7000) is running
[berry@berry:practice] service agentd restart
Shutting down Cisco AnyConnect Secure Mobility Client Agent
Starting up Cisco AnyConnect Secure Mobility Client Agent
[berry@berry:practice] service agentd status
agentd (pid 7020) is running

复制代码

(2)一种是直接执行某个服务自己的管理脚本,以agetd服务为例

/etc/init.d/agentd  start

/etc/init.d/agentd stop

/etc/init.d/agentd restart

 

复制代码

[berry@berry:practice] service agentd status
agentd (pid 7393) is running
[berry@berry:practice] sudo /etc/init.d/agentd stop
Shutting down Cisco AnyConnect Secure Mobility Client Agent
[berry@berry:practice] service agentd status
agentd is stopped 
[berry@berry:practice] sudo /etc/init.d/agentd start
Starting up Cisco AnyConnect Secure Mobility Client Agent
[berry@berry:practice] service agentd status
agentd (pid 7707) is running
[berry@berry:practice] sudo netstat -anp | grep 7707
tcp        0      0 127.0.0.1:29754         0.0.0.0:*               LISTEN      7707/agentd  
unix  2      [ ]         DGRAM                    78741    7707/agentd      
[berry@berry:practice] 

复制代码

端口号仍然是29754。

 

你可能感兴趣的:(Linux服务查看 启动 停止 和重启)