Open coolaj86 opened 8 months ago
logrotate
should be used to make sure that the logs don't fill up the disk.
A specific /etc/logrotate.d/MY_SERVICE_NAME
should be created for the service.
The copytruncate
option will work for "dumb" services that don't have a signal (such as SIGHUP
or USR2
to cause them to close and reopen their file handle. It keeps the same file handle without restarting the process.
crond
and /etc/periodic/
should already exist.
sudo apk --no-cache add logrotate
ls -lAhF /etc/periodic/*/*logrotate*
sudo rc-service crond status
echo '/var/log/MY_SERVICE_NAME/log.txt {
daily
missingok
rotate 7
compress
delaycompress
notifempty
copytruncate
}' | sudo tee /etc/logrotate.d/MY_SERVICE_NAME
sudo logrotate /etc/logrotate.d/MY_SERVICE_NAME --debug
Alpine 19 is a little bit different. Not sure how yet, but here's a working config:
#!/sbin/openrc-run
name="x5c"
description="x5c API service"
command="/home/app/srv/x5c/x5c-server"
command_args="--port 3080"
command_user="app:app"
supervisor="supervise-daemon"
output_log="/var/log/x5c"
error_log="/var/log/x5c"
depend() {
need net
}
start_pre() {
checkpath --directory --owner root /var/log/
checkpath --file --owner ${command_user} ${output_log} ${error_log}
}
start() {
ebegin "Starting ${name}"
supervise-daemon ${name} --start \
--stdout ${output_log} \
--stderr ${error_log} \
--pidfile /run/${RC_SVCNAME}.pid \
--respawn-delay 5 \
--respawn-max 10 \
-- \
${command} \
${command_args} \
eend $?
}
stop() {
ebegin "Stopping ${name}"
supervise-daemon ${name} --stop \
--pidfile /run/${RC_SVCNAME}.pid
eend $?
}
Notes
Basic
: https://wiki.alpinelinux.org/wiki/Writing_Init_Scripts#Basic_examplecheckpath
: https://manpages.debian.org/testing/openrc/openrc-run.8.en.html--env
: https://manpages.org/supervise-daemon/8Update
See the
logrotate
section below, which has not yet been integrated into this script.Proof of Concept
Install
Usage
Implementation
serviceman-add
:_serviceman-add-openrc-tmpl
: