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

linux 开机自启

root5年前 (2021-10-18)linux1579

方式一:

编写脚本,

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://www.zhiqiu.top/?id=168

分享给朋友:

相关文章

supervisor的安装使用

一、supervisor简介Supervisor是用Python开发的一套通用的进程管理程序,能将一个普通的命令行进程变为后台daemon,并监控进程状态,异常退出时能自动重启。它是通过fork/exec的方式把这些被管理的进程当作supe...

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

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

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

centos的新主机配置网络

centos的新主机配置网络

背景:公司因项目开发需要购置了两台主机。因为配置网络的大哥又是不在公司,但是又着急使用新主机。(旧的已经卡成狗腿了)急需解决问题,首先电脑刚插入网线又问题,不亮。只有一个网卡亮但是并不是Internet的网卡。其他四个网卡插入均不亮。换个网...

zabbix 中文乱码

zabbix 中文乱码

原因是因为zabbix没有支持中文的字体,在win找到一个中文字体文件名是:simkai.ttf把这个文件复制到服务器的/usr/share/zabbix/fonts  路径下然后修改zabbix的配置文件vim /us...

shell获取当前文件路径

curPath=$(readlink -f "$(dirname "$0")") echo $curPath    #或者 curPath=$(dirname $(readli...

配置机自启脚本地址/etc/rc.local ,在关机卡死 a stop job running for /etc/rc.local Compatibility (*s / no limit)

给自己的程序添加开机自启写了个脚本添加,并把执行脚本命令添加到了卡机启动中/etc/rc.local (不是一个设置开机启动的好办法)开机的时候存在失败,因为依赖的服务可能还没启动脚本就启动了 只能在脚本最上面sleep...