daemonize mode causes error on startup
Opened this issue · 4 comments
Hello,
we run frontail using following parameters:
frontail -d --disable-usage-stats -n 2000 \
--ui-highlight-preset /tmp/frontail-preset --ui-highlight --pid-path /tmp/frontail.pid --log-path /tmp/frontail.log \
/usr/java/jetty/logs/server.log
-d option causes following error at startup:
node:internal/fs/utils:815
throw new ERR_INVALID_ARG_TYPE(
^
TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (930)
at Object.writeFileSync (node:fs:1509:5)
at module.exports (/usr/node/lib/node_modules/frontail/lib/daemonize.js:64:6)
at Object.<anonymous> (/usr/node/lib/node_modules/frontail/index.js:47:3)
at Module._compile (node:internal/modules/cjs/loader:1108:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
at Module.load (node:internal/modules/cjs/loader:973:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Module.require (node:internal/modules/cjs/loader:997:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object.<anonymous> (/usr/node/lib/node_modules/frontail/bin/frontail:2:1) {
code: 'ERR_INVALID_ARG_TYPE'
}
log file (/tmp/frontail.log) is created, but empty,
pid file (/tmp/frontail.pid) isn't created at all,
- frontail: 4.9.2 (4.9.1 the same)
- node: v15.8.0
- npm: 7.5.1
I don't know it is connected, but very often daemonized frontail dies with no trace.
Btw. we use jetty+frontail in dockerized container based on Centos 8
same here... somone has a fix for this?
- node: v16.9.1
- npm: 7.21.1
Edit:
I've found a workaround:
start it with pm2
pm2 start frontail -- /var/log/logfile.log -t dark
Unfortunately project looks like a bit dead :/.
The fix is trivial... just stringify this line https://github.com/mthenw/frontail/blob/master/lib/daemonize.js#L68
e.g. from
fs.writeFileSync(params.pidPath, proc.pid);
to
fs.writeFileSync(params.pidPath, String(proc.pid));
While somebody takes care of this fix, I have found a workaround for daemonizing it in a Linux environment
damonize_frontail.sh
$FRONTAIL_LOGFILE=./frontail-log.log
FRONTAIL_PID_FILE=./frontail.pid
$LOGFILE=$1
# start frontail storing pid - put options here before $LOGFILE
frontail $LOGFILE &> $FRONTAIL_LOGFILE & frontail_pid=$!
# write PID to disk
echo "$frontail_pid" > $FRONTAIL_PID_FILE
launch daemon: damonize_frontail.sh <logfile>
lately you can kill it like this
kill_frontail.sh
FRONTAIL_PID_FILE=./frontail.pid
$frontail_pid=cat $FRONTAIL_PID_FILE
kill $frontail_pid
rm $FRONTAIL_PID_FILE
Non-linux user should find a similar workaround for their OSes.