contos中freeswitch通过写服务的方式配置开机自启动

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值