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的链接。

posted @   阿风小子  阅读(186)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
点击右上角即可分享
微信分享提示