ljzsdut
GitHubToggle Dark/Light/Auto modeToggle Dark/Light/Auto modeToggle Dark/Light/Auto modeBack to homepage

03 Alpine服务管理

参考:https://www.dotatong.cn/index.php/archives/40/

查看所有服务的状态

# rc-status
Runlevel: default
 crond                                  [  started  ]
 networking                             [  started  ]
Dynamic Runlevel: hotplugged
Dynamic Runlevel: needed/wanted
Dynamic Runlevel: manual

The default run level is called default, and it started crond and networking service for us.

查看服务列表

# rc-status --list
boot
nonetwork
default
sysinit
shutdown

修改运行级别:

# rc {runlevel}
# rc boot
# rc default
# rc shutdown
  1. boot – Generally the only services you should add to the boot runlevel are those which deal with the mounting of filesystems, set the initial state of attached peripherals and logging. Hotplugged services are added to the boot runlevel by the system. All services in the boot and sysinit runlevels are automatically included in all other runlevels except for those listed here.
  2. single – Stops all services except for those in the sysinit runlevel.
  3. reboot – Changes to the shutdown runlevel and then reboots the host.
  4. shutdown – Changes to the shutdown runlevel and then halts the host.
  5. default – Used if no runlevel is specified. (This is generally the runlevel you want to add services to.)

查看手动启动的服务:

# rc-status --manual apache2

查看crashed状态的服务:

# rc-status --crashed

查看所有可用服务

# rc-service --list
# rc-service --list | grep -i nginx

启用服务开机启动

rc-update add {service-name} {run-level-name}
# rc-update add apache2
# rc-update add apache2 default

删除服务开机启动

rc-update del {service-name-here}
# rc-update del vnstatd

启动服务

# rc-service {service-name} start
# /etc/init.d/{service-name} start

关闭服务

# rc-service {service-name} stop
# /etc/init.d/{service-name} stop

重启服务

# rc-service {service-name} restart
# /etc/init.d/{service-name} restart

示例:启动|关闭|重启Apache2服务

# rc-service apache2 stop
# rc-service apache2 start
# rc-service apache2 restart

Alpine Linux Init System Commands