From 7c766b2096ca22ab1c134fcdfa3ddbe7d77f6cdc Mon Sep 17 00:00:00 2001 From: Sam James Date: Sat, 19 Feb 2022 22:39:39 +0000 Subject: [PATCH] distrib: refine OpenRC init scripts - Add logging to init script - Add delay so OpenRC realises if we crashed quickly b/c of e.g. bad config file - General cleanups (like supporting multiple instances, style changes) This should make it a lot easier to see what's going wrong when something breaks. Bug: ergochat/ergo#1914 Signed-off-by: Sam James --- distrib/openrc/ergo.confd | 1 + distrib/openrc/ergo.initd | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/distrib/openrc/ergo.confd b/distrib/openrc/ergo.confd index 4a061b86..b9f917c0 100644 --- a/distrib/openrc/ergo.confd +++ b/distrib/openrc/ergo.confd @@ -1,2 +1,3 @@ # /etc/conf.d/ergo: config file for /etc/init.d/ergo ERGO_CONFIGFILE="/etc/ergo/ircd.yaml" +ERGO_USERNAME="ergo" diff --git a/distrib/openrc/ergo.initd b/distrib/openrc/ergo.initd index 025d6951..8bd1aba2 100644 --- a/distrib/openrc/ergo.initd +++ b/distrib/openrc/ergo.initd @@ -1,17 +1,30 @@ #!/sbin/openrc-run -command=/usr/bin/ergo -command_args="run --conf ${ERGO_CONFIGFILE:-"/etc/ergo/ircd.yaml"}" -command_background=true -extra_started_commands="reload" -pidfile=/var/run/ergo.pid -name="ergo" +name=${RC_SVCNAME} description="ergo IRC daemon" +command=/usr/bin/ergo +command_args="run --conf ${ERGO_CONFIGFILE:-'/etc/ergo/ircd.yaml'}" +command_user=${ERGO_USERNAME:-ergo} +command_background=true + +pidfile=/var/run/${RC_SVCNAME}.pid + +output_log="/var/log/${RC_SVCNAME}.out" +error_log="/var/log/${RC_SVCNAME}.err" +# --wait: to wait 1 second after launching to see if it survived startup +start_stop_daemon_args="--wait 1000" + +extra_started_commands="reload" + depend() { use dns provide ircd } +start_pre() { + checkpath --owner ${command_user}:${command_user} --mode 0640 --file /var/log/${RC_SVCNAME}.out /var/log/${RC_SVCNAME}.err +} + reload() { ebegin "Reloading ${RC_SVCNAME}" start-stop-daemon --signal HUP --pidfile "${pidfile}"