当前位置:首页 > linux > 正文内容

linux 开机自启

root5年前 (2021-10-18)linux1543

方式一:

编写脚本,

vi  /etc/rc.local

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# 在这里添加开机自启的脚本

exit 0

方式二:

编辑My.service ,内容如下,里面的路径根据自己实际情况修改

[Unit]
Description=My Server
After=syslog.target
After=network.target
After=mysql.servic

[Service]
Restart=on-failure 
ExecStart=/root/server.sh start
ExecRestart=/root/server.sh restart
ExecStop=/root/server.sh  stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target

server.sh脚本是服务的内容

#! /bin/bash
curlPath=$(readlink -f "$(dirname "$0")")
case "$1" in
start)
        $curlPath/esauto.sh start
        echo "Biz start"
        ;;

restart)
        $curlPath/esauto.sh restart
        echo "Biz restart"
        ;;

stop)
        $curlPath/esauto.sh stop
        echo "Biz stop"
        ;;
*)
    echo "start|stop|restart"
        ;;
esac
exit $?

这里是举例的es 启动


然后在将My.service放到

/usr/lib/systemd/system 下面


开启服务

systemctl start My.service


开启开机自启
systemctl enable My.service


参考文档


扫描二维码推送至手机访问。

版权声明:本文由一叶知秋发布,如需转载请注明出处。

本文链接:https://zhiqiu.top/?id=168

分享给朋友:

相关文章

死亡进程导致在办公室莫名背锅后平反昭雪艰辛之路

死亡进程导致在办公室莫名背锅后平反昭雪艰辛之路

背景:之前就有一个在我账户名下的问题程序,但是并不是我启动的,绝对不是我启动的。但是找不到原因就莫名的背起了锅。然后默默修改了密码(其实然并卵,下面详聊原理),该机器管理员把我踢出了root组(因为没啥程序在上面)起因:今日突然发现一个进程...

修改linux时区

ubuntu:rm  /etc/localtimeln -sf /usr/share/zoneinfo/Asia/Shanghai  /etc/localtimecentos echo "A...

centos切勿执行yum -y update

yum update 跟apt-get update 不一样centos的yum update相当于ubuntu的apt upgrade如果想用ubuntu的apt update,centos是yum makecache因为执行yum -y...

linux 安全策略关闭

#防火墙关闭systemctl stop firewalld.service#永久关闭防火墙systemctl disable firewalld.service#临时关闭selinuxsetenforce 0#永久关闭sed -i &qu...

实用的linux命令

查看命令运行的实时结果watch  "ls |wc -l" 能够实时的监控命令执行的结果,不过刷新时间有点长,大概2秒,可以修改为1秒iftop查看出入网流量情况nload实时查看出入网流量情况fre...

Linux下查看系统版本信息

 Linux下如何查看版本信息, 包括位数、版本信息以及CPU内核信息、CPU具体型号等等,整个CPU信息一目了然。   1、# uname -a   (Linux查看版本当前操作系统内核信息)&nb...