SystemD
« tiếng Việt »
updated: 2023-04-24
Configuration
We need to tell SystemD how we want to launch WebCC daemon (I use
vim
):
vim /lib/systemd/system/webcc-profanity.service
Edit the content of the file like so:
[Unit]
Description=Web Console Chat - Profanity
Documentation=man:ttyd(1)
After=network.target systemd-tmpfiles-clean.service
[Service]
Type=simple
EnvironmentFile=/etc/webcc/profanity.conf
ExecStart=/usr/local/bin/ttyd $TTYD_OPTIONS
ExecReload=/usr/bin/kill -HUP $MAINPID
User=webcc
Group=webcc
UMask=0027
WorkingDirectory=~
Restart=on-abnormal
KillMode=process
StandardOutput=append:/var/log/webcc/webcc-profanity.log
StandardError=append:/var/log/webcc/webcc-profanity.log
[Install]
WantedBy=multi-user.target
With the above, our daemon will:
- read the configuration in
/etc/webcc/profanity.conf
- write log to
/var/log/webcc/webcc-profanity.log
- run as the
webcc
UNIX user. - see only
$HOME
ofwebcc
throughout the process. Which is/var/xmpp/webcc/
.
You should read the manual of SystemD for further details.
Also, you can use logrotate to manage logging if necessary.
Next, we need to get SystemD to load our new configuration file:
systemctl daemon-reload
Then we can start the service and make sure it runs every time we (re)boot:
systemctl enable --now webcc-profanity.service
Customization
When you make changes to /etc/webcc/example.conf
or have
new version of ttyd
, you need to restart the daemon to
update your service:
systemctl restart webcc-profanity.service
To run more WebCC services, repeat the process mention above.