Dear all,

I developed a small tool to montitor my solar system and write the data into a database in golang.
The go tool just runs on foreground and log to STDOUT.

I want to run that now on my system using maybe an rc script so it is started automatically on startup.

Using FreeBSD 14.3.

Starting it work perfectly fine.
But I have problems with the restart command.
If I execute:
service monitorsolar restart
Stopping monitorsolar.
kill: 14894: Operation not permitted
monitorsolar already running?  (pid=14894).

But is is running:
ps auxw |grep solar
root                14894    0.0  0.0   13856    1964  -  Ss  07:50        0:00.00 daemon: monitorsolar[14895] (daemon) gitlab_deploy_solar 14895    0.0  0.0 1275980   26404  -  S 07:50        0:00.02 ./monitorSolarApi -config /usr/local/etc/monitorsolar

I think it is maybe a problem with how permissions are dropped. I executed all commands as root.
Maybe someone sees the problem in the rc script and can give me a tip:
#!/bin/sh
# PROVIDE: monitorsolar
# REQUIRE: DAEMON NETWORKING
# KEYWORD: shutdown

#
# Add these lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service
#
# monitorsolar_enable (bool):      Set to NO by default
#                                  Set it to YES to enable monitorSolar.
# monitorsolar_args (string):      Custom extra arguments for monitorSolar
# monitorsolar_user (string):      Set to gitlab_deploy_solar by default
#                                  The user to run the server (make sure user exists)
# monitorsolar_group (string):     Set to gitlab_deploy_solar by default
#                                  The group to run the server (make sure group exists)

. /etc/rc.subr

name="monitorsolar"
desc="Run Monitor Solar server"
rcvar="${name}_enable"

load_rc_config "${name}"

: ${monitorsolar_enable:="NO"}
: ${monitorsolar_user:="gitlab_deploy_solar"}
: ${monitorsolar_group:="gitlab_deploy_solar"}
: ${monitorsolar_args:=""}

command="/usr/sbin/daemon"
logfile="/var/log/${name}/${name}.log"
pidfile="/var/run/${name}.pid"
configfile="/usr/local/etc/monitorsolar"
workingdir="/usr/home/http/solar.fechner.net/app"

start_precmd="monitorsolar_precmd"
start_cmd="monitorsolar_start"

monitorsolar_precmd()
{
  # Ensure log directory exists
  install -d -g "${monitorsolar_group}" -o "${monitorsolar_user}" "$(dirname "${logfile}")"
}

monitorsolar_start()
{
  # redirect stdout to logfile and drop root permissions
  ${command} \
    -H \
    -o "${logfile}" \
    -t "${name}" \
    -P "${pidfile}" \
    -u "${monitorsolar_user}" \
    sh -c "cd '${workingdir}' && ./monitorSolarApi -config '${configfile}' ${monitorsolar_args}"
}

run_rc_command "$1"

Gruß
Matthias

--

"Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the universe trying to
produce bigger and better idiots. So far, the universe is winning." --
Rich Cook


Reply via email to