knowledge/docs/freeswitch/debian-service.md
2023-07-24 21:27:07 +08:00

71 lines
1.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Debian11中注册FreeSWITCH为系统服务
Debian 11使用了systemd作为启动管理器而不再使用sysvinit所以我们不去`/etc/init.d/`目录中去搞,而是在`/etc/systemd/system/`里面搞。
假设FreeSWITCH的安装目录是`/usr/local/freeswitch`。
## 创建freeswitch.service文件
```sh
touch /etc/systemd/system/freeswitch.service
vim /etc/systemd/system/freeswitch.service
```
文件内容参考如下:
```ini
[Unit]
Description=FreeSWITCH
After=network.target network-online.target
Wants=network-online.target
[Service]
User=freeswitch
Group=freeswitch
WorkingDirectory=/usr/local/freeswitch
ExecStart=/usr/local/freeswitch/bin/freeswitch
ExecStop=/usr/local/freeswitch/bin/freeswitch -stop
ExecStartPre=/bin/sleep 3
Restart=always
[Install]
WantedBy=default.target
```
其中`[Service]`段的`ExecStartPre=/bin/sleep 3`表示在启动FreeSWITCH前先等待3秒这一句可根据实际环境酌情使用。
保存`freeswitch.service`文件并退出。
## 创建freeswitch启动用户和组
```sh
## 创建freeswith用户组
groupadd -r freeswitch
## 创建freeswitch用户
useradd -r -g freeswitch -s /bin/false -d /usr/local/freeswitch -c "FreeSWITCH" freeswitch
## 更改freeswitch程序目录的权限
sudo chown -R freeswitch:freeswitch /usr/local/freeswitch
```
## 注册系统服务并实现开机自启
```sh
## 注册freeswitch服务
sudo systemctl daemon-reload
## 让freeswitch随系统自动启动
sudo systemctl enable freeswitch
```
现在名为freeswitch的系统服务已经注册完成可以使用下面的系统命令管理freeswitch的启动与停止了
```sh
## 启动服务
sudo systemctl start freeswitch
## 重新启动服务(停止再启动)
sudo systemctl restart freeswitch
## 停止服务
sudo systemctl stop freeswitch
## 查看服务状态
sudo systemctl status freeswitch
```