比较老的linux系统版本配置自定义服务的实践

  • 列出系统的所有服务

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值