debian 开机、关机启动

开机启动方法1:

  1. 在/etc/init.d/创建一个脚本:hslong.sh, 内容如下:

    #!/bin/bash
    ### BEGIN INIT INFO
    # Provides:          hslong.sh
    # Required-Start:    $network $local_fs $remote_fs
    # Required-Stop:     $network $local_fs $remote_fs
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Should-Start:      slapd cups
    # Should-Stop:       slapd cups
    # Short-Description: Hslong daemon (shell)
    # Description: hslong
    ### END INIT INFO
    
    #自己要执行的命令
    
  2. 启动文件模板说明

    	#!/bin/bash
    	### BEGIN INIT INFO
    	# Provides:          [程序名称,唯一]
    	# Required-Start:    $network $local_fs $remote_fs
    	# Required-Stop:     $network $local_fs $remote_fs
    	# Default-Start:     2 3 4 5
    	# Default-Stop:      0 1 6
    	# Should-Start:      slapd cups
    	# Should-Stop:       slapd cups
    	# Short-Description: [启动项的简短说明]
    	# Description: [启动项的完整说明]
    	### END INIT INFO
    	
    	#自己要执行的命令
    
  3. 修改权限:sudo chmod a+x hslong.sh

  4. 添加到启动:sudo update-rc.d hslong.sh defaults

  5. 删除启动项:sudo update-rc.d -f hslong.sh remove

开机/关机启动方法2:

  1. sudo vi /lib/systemd/system/rc-local.service

    找到Service添加如下:

    [Service]
    ExecStop=/etc/hslong.local stop
    ExecStop=/etc/hslong.local start
    
  2. sudo vi /etc/hslong.local

    脚本执行任务如下:

    #!bin/sh -e
    case "$1" in
    	start)
    		echo "hslong start ..."
    		;;
    	stop)
    		echo "hslong stop mysql server ..."
    		service mysql stop
    	*)
    		echo "Usage: $0 {start|stop}"
    		exit 1
    esac
    
    

你可能感兴趣的:(其它,debian,linux,运维)