TransWikia.com

init script for alpine not working

Unix & Linux Asked by karlsebal on January 18, 2021

I am trying to write an init script for gitea in alpine. The first code I tried was

#!/sbin/openrc-run
command=/usr/bin/gitea

command_args="web"
pidfile=/var/run/git.pid
name="Gitea Daemon"

description="Gitea - Git with a cup of tea"

start() {
  ebegin "Starting Gitea"
  start-stop-daemon --start --exec /usr/bin/gitea 
    --pidfile /var/run/git.pid 
  eend $?
}

stop() {
  ebegin "Stopping Gitea"
  start-stop-daemon --stop --exec /usr/bin/gitea 
    --pidfile /var/run/git.pid
  eend $?
}

Gitea does not fork, so when running above code, the service is starting and running but stays in foreground. So I tried to add --background option to start-stop-daemon. Now it is forking but the service is shown as „crashed“ although it’s running. I can fix this by manually creating a git.pid file, otherwise the service is unusable (won’t start nor stop) until I remove /var/run/openrc/started/git manually.

When using the code above and calling it in background by

rc-service git start &

It will start gitea but rc-status shows the service as „starting“.

Additionally I did not accomplish to log the output. Maybe somebody can give me a hint on this. I tried to add a redirect to command_args but this did not work and a redirect of start-stop-daemon’s output is useless when run in background.

One Answer

This works (is the one shipped with gitea-openrc):

#!/sbin/openrc-run

supervisor=supervise-daemon
name=gitea
command="/usr/bin/gitea"
command_user="${GITEA_USER:-gitea}"
command_args="web --config '${GITEA_CONF:-/etc/gitea/app.ini}'"
supervise_daemon_args="--env GITEA_WORK_DIR='${GITEA_WORK_DIR:-/var/lib/gitea}' --chdir '${GITEA_WORK_DIR:-/var/lib/gitea}' --stdout '${GITEA_LOG_FILE:-/var/log/gitea/http.log}' --stderr '${GITEA_LOG_FILE:-/var/log/gitea/http.log}'"
pidfile="/run/gitea.pid"

depend() {
        use logger dns
        need net
        after firewall mysql postgresql
}

If you want to go ahead and use your script, please don't put the "&" at the end, and post the output of the logs.

.: Francesco

Answered by Francesco Colista on January 18, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP