美文网首页工作生活
systemd系统添加自定义服务

systemd系统添加自定义服务

作者: MrSunday_8955 | 来源:发表于2019-07-12 15:26 被阅读0次

    Linux的systemd系统添加服务是在/usr/lib/systemd/system(kylin环境systemd路径可能变成了/lib/systemd/system)。无论路径如何变化,添加服务大同小异,只是配置的路径需要注意。添加自定义服务,简单配置可以如下:

    # 创建myService.service文件
    touch /usr/lib/systemd/system/myService.service
    chmod 666 /usr/lib/systemd/system/myService.service
    # 写服务配置
    echo "[Unit]
    Description=myService service
    After=sysinit.target nfs-server.service
    
    [Service]
    ExecStart=/opt/myService/myservice start  #我的服务放在/opt/myService
    Type=simple
    
    [Install]
    WantedBy=multi-user.target" > /usr/lib/systemd/system/myService.service
    # 创建软连接
    ln -s /usr/lib/systemd/system/myService.service /usr/lib/systemd/system/local-fs.target.wants/myService.service
    # 将服务加入开机启动
    systemctl enable myService > /dev/null 2>&1
    systemctl daemon-reload > /dev/null 2>&1
    
    

    相关文章

      网友评论

        本文标题:systemd系统添加自定义服务

        本文链接:https://www.haomeiwen.com/subject/rlxdhctx.html