- 列出系统的所有服务
Bash
root@wei:/lib/systemd# service --status-all
[ + ] acpid
[ - ] alsa-utils
[ - ] anacron
[ - ] apache-htcacheclean
[ - ] apache2
[ + ] apparmor
[ + ] apport
[ + ] avahi-daemon
[ - ] bluetooth
[ - ] cgroupfs-mount
[ - ] console-setup.sh
[ + ] cron
[ + ] cups
[ + ] cups-browsed
[ + ] dbus
[ + ] gdm3
[ + ] grub-common
[ - ] hwclock.sh
[ + ] irqbalance
[ + ] kerneloops
[ - ] keyboard-setup.sh
[ + ] kmod
[ - ] mysql
[ + ] network-manager
[ + ] open-vm-tools
[ + ] openvpn
[ - ] plymouth
[ - ] plymouth-log
[ - ] pppd-dns
[ + ] procps
[ - ] pulseaudio-enable-autospawn
[ - ] rsync
[ + ] rsyslog
[ - ] saned
[ - ] speech-dispatcher
[ - ] spice-vdagent
[ + ] ssh
[ + ] sysstat
[ + ] ubuntu-fan
[ + ] udev
[ + ] ufw
[ + ] unattended-upgrades
[ - ] uuidd
[ - ] vmware-tools
[ - ] vmware-tools-thinprint
[ - ] wei_serverd
[ + ] whoopsie
[ - ] x11-common
root@wei:/lib/systemd#
复制代码
- 查看服务文件的路径
Bash
root@wei:/lib/systemd# systemctl status wei_serverd
● wei_serverd.service - LSB: Start wangwei daemon at boot time
Loaded: loaded (/etc/init.d/wei_serverd; generated)
Active: active (exited) since Thu 2021-07-15 11:01:54 CST; 1h 57min ago
Docs: man:systemd-sysv-generator(8)
Process: 868 ExecStart=/etc/init.d/wei_serverd start (code=exited, status=0/SUCCESS)
7月 15 11:01:45 wei systemd[1]: Starting LSB: Start wangwei daemon at boot time...
7月 15 11:01:54 wei systemd[1]: Started LSB: Start wangwei daemon at boot time.
root@wei:/lib/systemd#
复制代码
- 查看我编写的服务
Bash
root@wei:/lib/systemd# cat /etc/init.d/wei_serverd
#! /bin/bash
### BEGIN INIT INFO
# Provides: wangwei
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start wangwei daemon at boot time
# Description: Start wangwei daemon at boot time
### END INIT INFO
#start yakuake
start(){
/root/wangwei/wstart > /tmp/wstart.log 2>&1
/root/wangwei/gitstart > /tmp/gitstart.log 2>&1
}
#stop
stop(){
/root/wangwei/wstop > /tmp/wstop.log 2>&1
/root/wangwei/gitstop > /tmp/gitstop.log 2>&1
}
#show the status
status(){
echo ""
echo ""
echo "检查blog服务是否正常:"
/root/wangwei/wstat
echo ""
echo ""
echo "检查gitlab服务是否正常:"
/root/wangwei/gitstat
}
#restart
restart(){
stop
start
}
#execute by input command
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 1
esac
root@wei:/lib/systemd#
复制代码
\
2.4 设置权限
- chmod 777 /etc/init.d/wei_serverd
2.5 利用service启动hello
- service wei_serverd start
2.6 设置开机自动启动
- chkconfig --add wei_serverd
- chkconfig --list