linux M4 配置管理

本文介绍如何利用M4工具简化OpenSIPS配置文件的维护工作。通过创建不同的参数文件,可以在不同环境下轻松切换配置,如家庭和办公室。文中详细展示了如何设置这些参数文件,并提供了一个bash脚本来自动完成这一过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


摘自http://www.opensips.org/Resources/DocsTools,opensips学习。

m4

Included on most Linuxes. This is a simple way to set up and use separate parameter files or even a good way of accomplishing INCLUDE's in your configs. Example of usage is provided by Iñaki Baz Castillo;

I strongly recommend you to use M4 to compile your opensips.cfg file:

file /etc/opensips/opensips.cfg.m4:
---------------------------------------------
debug=3
log_stderror=no
log_facility=LOG_LOCAL7
fork=yes
...
listen=MY_IP:MY_PORT
...
    rewritehost("MEDIA_SERVER_IP:MEDIA_SERVER_PORT");
...
---------------------------------------------

file /etc/opensips/defines.m4 (at your home):
---------------------------------------------
divert(-1)
define(`MY_IP',		`192.168.10.23')
define(`MY_PORT',		`5060')
define(`MEDIA_SERVER_IP',   `192.168.10.23')
define(`MEDIA_SERVER_PORT', `5065')
divert(0)dnl
---------------------------------------------

file /etc/opensips/defines.m4 (at your office):
---------------------------------------------
divert(-1)
define(`MY_IP',		`123.123.123.123')
define(`MY_PORT',		`5060')
define(`MEDIA_SERVER_IP',	`22.22.22.22')
define(`MEDIA_SERVER_PORT',	`5065')
divert(0)dnl
---------------------------------------------

Create a bash script:
/usr/local/bin/op-restart.sh:
----------------------------------------------
#!/bin/bash
DIR="/etc/opensips"
m4 $DIR/defines.m4 $DIR/opensips.cfg.m4 > $DIR/opensips.cfg
/etc/init.d/opensips restart
----------------------------------------------

So you just must change the /etc/opensips/opensips.cfg.m4 file and the
defines.m4 (this last file will be different depending on your location).
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值