• systemd的程序自启动脚本编写


    以FreeSWITCH的自启动脚本为例。

    一、 编写freeswitch.service文件

     1 [Unit]
     2 Description=FreeSWITCH
     3 After=syslog.target network.target
     4 After=postgresql.service mysqld.service
     5 
     6 [Service]
     7 User=root
     8 EnvironmentFile=/etc/systemd/freeswitch.conf
     9 # RuntimeDirectory is not yet supported in CentOS 7. A workaround is to use /etc/tmpfiles.d/freeswitch.conf
    10 #RuntimeDirectory=/run/freeswitch
    11 #RuntimeDirectoryMode=0750
    12 WorkingDirectory=/usr/local/freeswitch/run
    13 PIDFile=/usr/local/freeswitch/run/freeswitch.pid
    14 ExecStart=/usr/bin/freeswitch -nc -nf $FREESWITCH_PARAMS
    15 ExecReload=/usr/bin/kill -HUP $MAINPID
    16
    17 [Install]
    18 WantedBy=multi-user.target

    二、 freeswitch.service的文件路径

    可能会和具体的Linux版本有关系,给出ubuntu的例子:

    /lib/systemd/system/

    三、 编写步骤一中声明的配置文件

    1. 文件路径

    /etc/systemd/freeswitch.conf

    2. 文件内容

    1 ## Type: string
    
    2 ## Default: ""
    3 ## Config: ""
    4 ## ServiceRestart: freeswitch
    5 #
    6 # if not empty: parameters for freeswitch
    7 #
    8 FREESWITCH_PARAMS="-nonat"

    四、 自启动添加

    systemctl enable freeswitch.service

    五、 添加自启动的时候,日志提示如下

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

    在etc/systemd/system/multi-user.target.wants/目录下生成一个freeswitch.service的链接。

  • 相关阅读:
    【Struts2】 国际化
    【Struts2】进阶
    【Struts2】简介及入门
    【Distributed】互联网安全架构
    【Mac】 开启原生的 NTFS 硬盘格式支持
    swagger2简单使用
    自定义异常和异常处理
    enum简单使用
    Interceptor
    修改docker下mysql配置
  • 原文地址:https://www.cnblogs.com/yoyotl/p/7751677.html
Copyright © 2020-2023  润新知