zoukankan      html  css  js  c++  java
  • Linux服务加入systemctl|service管理


    Linux服务加入systemctl|service管理

    一.加入systemctl

    1.添加

    vim /usr/lib/systemd/system/user_timejob.service
    
    # copy to /usr/lib/systemd/system
    # systemctl enable customservice.service
    [Unit]
    Description=customservice Service
     
    [Service]
    Type=forking
    User=root
    ExecStart=/etc/init.d/customservice.sh
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStop=/bin/kill -s QUIT $MAINPID
    PrivateTmp=True
     
    [Install]
    WantedBy=multi-user.target

    解释:

    [Unit]部分主要是对这个服务的说明,内容包括Description和After,Description 用于描述服务,After用于描述服务类别

    [Service]部分是服务的关键,是服务的一些具体运行参数的设置.

    Type=forking是后台运行的形式,

    User=users是设置服务运行的用户,

    Group=users是设置服务运行的用户组,

    PIDFile为存放PID的文件路径,

    ExecStart为服务的具体运行命令,

    ExecReload为重启命令,

    ExecStop为停止命令,

    PrivateTmp=True表示给服务分配独立的临时空间

    注意:[Service]部分的启动、重启、停止命令全部要求使用绝对路径,使用相对路径则会报错!

    [Install]部分是服务安装的相关设置,可设置为多用户的

    2.启动

    systemctl restart user_timejob
    systemctl enable user_timejob

    二.加入service

    1.编写启动脚本,这里主要注意配置文件路径以及主程序路径,在/etc/init.d/中新建文件 nginx这个文件下的所有软件启动文件都要加755权限,否则会启动失败

    vim /etc/init.d/user_timejob
    
    #!/bin/bash
    # nginx Startup script for the Nginx HTTP Server
    # it is v.0.0.2 version.
    # chkconfig: - 85 15
    # description: Nginx is a high-performance web and proxy server.
    #              It has a lot of features, but it's not for everyone.
    # processname: nginx
    nginxd=/usr/local/nginx/sbin/nginx
    # See how we were called.
    case "$1" in
    start)
            $nginxd
            ;;
    stop)
            $nginxd -s quit
            ;;
    reload)
            reload
            ;;
    restart)
            $nginxd -s reload
            ;;
    *)
            echo $"Usage: $prog {start|stop|restart|reload|status|help}"
            exit 1
    esac

    2.加入自启动

    chkconfig --add user_timejob
  • 相关阅读:
    链接Caffe,程序报错应用程序无法正常启动(0xc000007b)
    C++ 11的移动语义
    C++ 11的右值引用
    (持续更新)Qt3D 学习资源
    Qt3D 设置窗口背景颜色和图案
    C++ chrono 库中的 steady_clock 和 system_clock
    VS2017+CMake+OpenCV下报错 set OpenCV_FOUND to FALSE
    C++可继承的单例基类模板
    AngularJS的基础知识
    gulp入门详情
  • 原文地址:https://www.cnblogs.com/haoee/p/14776439.html
Copyright © 2011-2022 走看看