contos中freeswitch配置开机自启动
服务文件说明
[Unit]:服务的说明
Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
注意:启动、重启、停止命令全部求使用绝对路径
[Install]服务安装的相关设置,可设置为多用户
编写服务文件
再freeswitch的源码下 freeswitch/build/freeswitch.service
有官方提供的开机自启动服务文件内容如下
[Unit]
[Unit]
Description=FreeSWITCH
After=syslog.target network.target
After=postgresql.service postgresql-9.3.service postgresql-9.4.service mysqld.service httpd.service
[Service]
# You can use Type=notify only if you compile FreeSWITCH with --enable-systemd configure option
# In this case you have to run FreeSWITCH in foreground mode (-nf option)!
#Type=notify
#NotifyAccess=main
User=freeswitch
EnvironmentFile=-/etc/sysconfig/freeswitch
# RuntimeDirectory is not yet supported in CentOS 7. A workaround is to use /etc/tmpfiles.d/freeswitch.conf
#RuntimeDirectory=/run/freeswitch
#RuntimeDirectoryMode=0750
WorkingDirectory=/run/freeswitch
ExecStart=/usr/bin/freeswitch -nc -nf $FREESWITCH_PARAMS
ExecReload=/usr/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
但是使用这个服务文件笔者在使用过程中测试了几次感觉不能完美的实现自启动功能(大家有功夫可以尝试一下),而且启动成功后不能使用fs_cil
指令进入freeswitch控制,所以笔者将服务文件修改为以下形式
[Unit]
Description=FreeSWITCH
Requires=network.target
After= mysqld.service
[Service]
# You can use Type=notify only if you compile FreeSWITCH with --enable-systemd configure option
# In this case you have to run FreeSWITCH in foreground mode (-nf option)!
#NotifyAccess=main
User=root
EnvironmentFile=-/etc/sysconfig/freeswitch
# RuntimeDirectory is not yet supported in CentOS 7. A workaround is to use /etc/tmpfiles.d/freeswitch.conf
#RuntimeDirectory=/run/freeswitch
#RuntimeDirectoryMode=0750
WorkingDirectory=/run/freeswitch
ExecStart=/usr/bin/freeswitch -nc -nf $FREESWITCH_PARAMS
ExecReload=/usr/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
1、在目录/etc/sysconfig下创建文件freeswitch,内容如下
## Type: string
## Default: ""
## Config: ""
## ServiceRestart: freeswitch
#
# if not empty: parameters for freeswitch
#
FREESWITCH_PARAMS=""
2、创建centos服务的启动文件
在目录/usr/lib/systemd/system下创建文件freeswitch.service,内容为刚才编辑的服务文件
保存后修改文件的权限
chmod +x //usr/lib/systemd/system/freeswitch.service
执行:
systemctl daemon-reload
修改
cd /usr/local/
chown -R root:root freeswitch
chmod -R g+w freeswitch
3、常用的启动命令
1. 设置开机自启动
任意目录下执行
systemctl enable freeswitch.service
2. 其他命令
启动freeswitch服务
systemctl start freeswitch.service
设置开机自启动
systemctl enable freeswitch.service
停止开机自启动
systemctl disable freeswitch.service
查看服务当前状态
systemctl status freeswitch.service
重新启动服务
systemctl restart freeswitch.service
查看所有已启动的服务
systemctl list-units --type=service
设置开机自启动
[root@localhost ~]# systemctl enable freeswitch.service
停止开机自启动
[root@localhost ~]# systemctl disable freeswitch.service
验证一下是否为开机启动
[root@localhost ~]# systemctl is-enabled freeswitch