• 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
  • 相关阅读:
    用js实现双色球
    nodejs_理解Buffer
    nodejs_buffer.copy
    nodejs_buffer.concat
    nodejs_buffer.alloc
    Ant Design Pro v4 最新版安装(跳过所有坑)
    python eventlet详解
    python 超时重试方法
    pycharm配置react
    Python性能优化的20条建议
  • 原文地址:https://www.cnblogs.com/haoee/p/14776439.html
Copyright © 2020-2023  润新知