Self-daemonizing bash script Self-daemonizing bash script bash bash

Self-daemonizing bash script


Here are things I see.

if [[ $1 != "--daemonize" ]]; then  

Shouln't that be == --daemonize?

nohup $SCRIPTNAME --daemonize "${PARAMS[@]}" &>/dev/null &

Instead of calling your script again, you could just summon a subshell that's placed in a background:

(    Codes that run in daemon mode.) </dev/null >/dev/null 2>&1 &disown

Or

function daemon_mode {    Codes that run in daemon mode.}daemon_mode </dev/null >/dev/null 2>&1 &disown