• systemd创建自定义服务(Ubuntu)


    /lib/systemd/system下创建test.service文件

    vim /lib/systemd/system/test.service

    [Unit]

    Description=test

    [Service]

    Type=forking

    PIDFile=/run/test.pid

    #EnvironmentFile=/etc/systemd/test.conf

    ExecStart=/opt/systemd-sh/test.sh

    ExecReload=/bin/kill -SIGHUP $MAINPID

    ExecStop=/bin/kill -SIGINT $MAINPID

    [Install]

    WantedBy=multi-user.target graphical.target

    修改配置文件后需要重加载配置

    sudo systemctl daemon-reload

    创建test.sh

    vim /opt/systemd-sh/test.sh
    #!/bin/bash
      
    echo `date`,"ok" >>/tmp/test.log

    赋予可执行权限 

    chmod +x /opt/systemd-sh/test.sh

    设置开机启动

    systemctl enable test.service

    显示

    Created symlink /etc/systemd/system/multi-user.target.wants/test.service → /lib/systemd/system/test.service.

    重启

    reboot

    重启后,看下/tmp/test.log的内容

    vim /opt/test.log

    systemd集中式日志管理

    查看该unit的日志

    sudo journalctl -u test.service
    sudo journalctl -u test.service --since="2018-11-11 11:11:11"
    sudo journalctl -u test.service --since "30 min ago"
    sudo journalctl -u test.service --since yesterday sudo journalctl -u test.service --since "2018-11-10" --until "2018-11-11 11:11"
    sudo journalctl -u test.service --since 04:00 --until "2 hour ago"
  • 相关阅读:
    VS2010 安装MVC3
    MVC3教程之新手入门(转)
    MVC工作原理
    MVC开发人员必备的五大工具
    MVC3简介
    C#中各种字符类型的转化
    c#中设置Excel单元格格式
    浪子
    累了,再见
    利用HttpHandler处理自定义控件中需要引用大量js文件问题
  • 原文地址:https://www.cnblogs.com/wintersoft/p/9937839.html
Copyright © 2020-2023  润新知