zoukankan      html  css  js  c++  java
  • Centos7利用systemctl添加自定义系统服务

    1.创建启动服务的shell脚本,如下start.sh

    #!/bin/sh
    export JAVA_HOME=/usr/local/java/jdk1.8.0_91
    export PATH=$JAVA_HOME/bin:$PATH
    
    cd /dwgj/services/gps-consume-service
    java -jar ./lib/gps-consume-service.jar &
    echo $! > /var/run/gps-consume-service.pid

    2.创建停止服务的shell脚本,如下stop.sh

    #!/bin/sh
    PID=$(cat /var/run/gps-consume-service.pid)
    kill -9 $PID

    3.进入/usr/lib/systemd/system或者/etc/systemd/system下,创建服务的systemctl脚本,如下gps-consume.service

    [Unit]
    Description=the service description
    After=network.target
    
    [Service]
    Type=forking
    ExecStart=/dwgj/services/gps-consume-service/start.sh
    ExecStop=/dwgj/services/gps-consume-service/stop.sh
    
    [Install]
    WantedBy=multi-user.target

    4.systemctl常用命令systemctl status gps-consume 查看服务状态

    systemctl start gps-consume       启动服务
    systemctl stop gps-consume        停止服务
    systemctl restart gps-consume    重启服务
    systemctl enable gps-consume    设置开机自启
    systemctl kill gps-consume       杀死服务
    systemctl list-units --type=service    查找所有服务
  • 相关阅读:
    各大公司 Java 后端开发面试题总结
    java程序开发工具集的使用
    删数
    能量项链//区间DP
    合并傻子//区间dp
    P1005 采药
    表达式计算系列
    进制转换
    最长公共子序列
    乘法游戏
  • 原文地址:https://www.cnblogs.com/Mr-kevin/p/12461829.html
Copyright © 2011-2022 走看看