Skip to content

Commit

Permalink
Add the daemon name and pid file path to the daemon arguments to allow
Browse files Browse the repository at this point in the history
multiple instances to run on the same system.
  • Loading branch information
gaudryc committed Nov 1, 2015
1 parent ea4b80a commit 5c9afdb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
12 changes: 8 additions & 4 deletions domoticz.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
DESC="Domoticz Home Automation System"
NAME=domoticz
USERNAME=pi
DAEMON=/home/$USERNAME/domoticz/$NAME
#DAEMON_ARGS="-daemon -www 8080 -sslwww 443 -log /tmp/domoticz.txt"
#DAEMON_ARGS="-daemon -www 8080 -sslwww 443 -syslog"
DAEMON_ARGS="-daemon -www 8080 -sslwww 443"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

DAEMON=/home/$USERNAME/domoticz/$NAME
DAEMON_ARGS="-daemon"
#DAEMON_ARGS="$DAEMON_ARGS -daemonname $NAME -pidfile $PIDFILE"
DAEMON_ARGS="$DAEMON_ARGS -www 8080"
DAEMON_ARGS="$DAEMON_ARGS -sslwww 443"
#DAEMON_ARGS="$DAEMON_ARGS -log /tmp/domoticz.txt"
#DAEMON_ARGS="$DAEMON_ARGS -syslog"

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

Expand Down
18 changes: 15 additions & 3 deletions main/domoticz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,18 +712,30 @@ int main(int argc, char**argv)
g_bRunAsDaemon = true;
}

std::string daemonname = DAEMON_NAME;
if (cmdLine.HasSwitch("-daemonname"))
{
daemonname = cmdLine.GetSafeArgument("-daemonname", 0, DAEMON_NAME);
}

std::string pidfile = PID_FILE;
if (cmdLine.HasSwitch("-pidfile"))
{
pidfile = cmdLine.GetSafeArgument("-pidfile", 0, PID_FILE);
}

if ((g_bRunAsDaemon)||(g_bUseSyslog))
{
setlogmask(LOG_UPTO(LOG_INFO));
openlog(DAEMON_NAME, LOG_CONS | LOG_PERROR, LOG_USER);
openlog(daemonname.c_str(), LOG_CONS | LOG_PERROR, LOG_USER);

syslog(LOG_INFO, "Domoticz is starting up....");
}

if (g_bRunAsDaemon)
{
/* Deamonize */
daemonize(szStartupFolder.c_str(), PID_FILE);
daemonize(szStartupFolder.c_str(), pidfile.c_str());
}
if ((g_bRunAsDaemon) || (g_bUseSyslog))
{
Expand Down Expand Up @@ -788,7 +800,7 @@ int main(int argc, char**argv)
daemonShutdown();

// Delete PID file
remove(PID_FILE);
remove(pidfile.c_str());
}
#else
// Release WinSock
Expand Down

0 comments on commit 5c9afdb

Please sign in to comment.