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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM