zoukankan      html  css  js  c++  java
  • 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的链接。

  • 相关阅读:
    局部类
    内部类
    程序的异常
    四种修饰符
    接口之间的多继承
    多态
    继承父类并实现多个接口
    接口内容小结
    接口的静态方法和私有方法
    顺序栈与链式栈
  • 原文地址:https://www.cnblogs.com/yoyotl/p/7751677.html
Copyright © 2011-2022 走看看