• linux开机启动服务配置


    在/usr/lib/systemd/system目录下增加tomcat8.service文件,内容如下:
    vi /usr/lib/systemd/system/tomcat8.service
    [Unit]
    Description=Tomcat
    After=syslog.target network.target remote-fs.target nss-lookup.target

    [Service]
    Type=forking

    或者在tomcat/bin/catalina.sh中添加CATALINA_PID="$CATALINA_BASE/tomcat.pid"

    PIDFile=/usr/tomcat/apache-tomcat-8.5.50/tomcat.pid
    Environment="JAVA_HOME=/usr/java/jdk1.8.0_241"
    ExecStart=/usr/tomcat/apache-tomcat-8.5.50/bin/startup.sh
    ExecStop=/usr/tomcat/apache-tomcat-8.5.50/bin/shutdown.sh
    ExecReload=/bin/kill -s HUP $MAINPID
    RemainAfterExit=yes

    [Install]
    WantedBy=multi-user.target

    ————————————————————————————————————

    如果[Service]节不加PIDFile=/usr/tomcat/apache-tomcat-8.5.50/tomcat.pid,

    应该在bin/catalina.sh中添加CATALINA_PID="$CATALINA_BASE/tomcat.pid"

    Copy CATALINA_BASE from CATALINA_HOME if not already set

    [ -z "$CATALINA_BASE" ] && CATALINA_BASE="$CATALINA_HOME"

    设置pid。一定要加在CATALINA_BASE定义后面,要不然pid会生成到/下面

    CATALINA_PID="$CATALINA_BASE/tomcat.pid"
    ————————————————————————————————————

    重新加载一下配置。每次改动后也要重新加载

    systemctl daemon-reload

    //执行systemctl enable tomcat使tomcat8随开机启动
    systemctl enable tomcat8.service

    设置允许开机自启动

    systemctl enable tomcat8

    启动服务

    systemctl start tomcat8

    查看状态

    systemctl status tomcat8

    查看服务是否激活

    systemctl is-active tomcat8

    其它命令

    禁止开机启动

    systemctl disable tomcat8

    停止服务

    systemctl stop tomcat8

    重启服务

    systemctl restart tomcat8

    查看所有已启动的服务

    systemctl list -units --type=service

    nginx.service自启动
    vi /usr/lib/systemd/system/nginx.service
    [Unit]
    Description=nginx
    After=network.target

    [Service]
    Type=forking
    ExecStart=/opt/nginx/sbin/nginx
    ExecReload=/opt/nginx/sbin/nginx reload
    ExecStop=/opt/nginx/sbin/nginx quit
    PrivateTmp=true

    [Install]
    WantedBy=multi-user.target

  • 相关阅读:
    【mac】homebrew国内源安装加速
    【Mac】快速删除指定文件夹下的.DS_Store文件
    【mac】Mac微信小助手安装和卸载
    如何高效的开展app的性能测试
    什么是C#?什么是DOTNET?
    Xamarin Android使用自签名证书
    产品经理的私房菜
    java并发编程2-Synchronized关键字底层实现原理详解
    VS Code 1.60 发布!竟然可以自动检测编程语言了!
    为什么'x1B'.length===1?x与u知识延伸
  • 原文地址:https://www.cnblogs.com/windlog/p/13592250.html
Copyright © 2020-2023  润新知