Skip to content

Commit 5c9afdb

Browse files
committed
Add the daemon name and pid file path to the daemon arguments to allow
multiple instances to run on the same system.
1 parent ea4b80a commit 5c9afdb

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

domoticz.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
1515
DESC="Domoticz Home Automation System"
1616
NAME=domoticz
1717
USERNAME=pi
18-
DAEMON=/home/$USERNAME/domoticz/$NAME
19-
#DAEMON_ARGS="-daemon -www 8080 -sslwww 443 -log /tmp/domoticz.txt"
20-
#DAEMON_ARGS="-daemon -www 8080 -sslwww 443 -syslog"
21-
DAEMON_ARGS="-daemon -www 8080 -sslwww 443"
2218
PIDFILE=/var/run/$NAME.pid
2319
SCRIPTNAME=/etc/init.d/$NAME
2420

21+
DAEMON=/home/$USERNAME/domoticz/$NAME
22+
DAEMON_ARGS="-daemon"
23+
#DAEMON_ARGS="$DAEMON_ARGS -daemonname $NAME -pidfile $PIDFILE"
24+
DAEMON_ARGS="$DAEMON_ARGS -www 8080"
25+
DAEMON_ARGS="$DAEMON_ARGS -sslwww 443"
26+
#DAEMON_ARGS="$DAEMON_ARGS -log /tmp/domoticz.txt"
27+
#DAEMON_ARGS="$DAEMON_ARGS -syslog"
28+
2529
# Exit if the package is not installed
2630
[ -x "$DAEMON" ] || exit 0
2731

main/domoticz.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -712,18 +712,30 @@ int main(int argc, char**argv)
712712
g_bRunAsDaemon = true;
713713
}
714714

715+
std::string daemonname = DAEMON_NAME;
716+
if (cmdLine.HasSwitch("-daemonname"))
717+
{
718+
daemonname = cmdLine.GetSafeArgument("-daemonname", 0, DAEMON_NAME);
719+
}
720+
721+
std::string pidfile = PID_FILE;
722+
if (cmdLine.HasSwitch("-pidfile"))
723+
{
724+
pidfile = cmdLine.GetSafeArgument("-pidfile", 0, PID_FILE);
725+
}
726+
715727
if ((g_bRunAsDaemon)||(g_bUseSyslog))
716728
{
717729
setlogmask(LOG_UPTO(LOG_INFO));
718-
openlog(DAEMON_NAME, LOG_CONS | LOG_PERROR, LOG_USER);
730+
openlog(daemonname.c_str(), LOG_CONS | LOG_PERROR, LOG_USER);
719731

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

723735
if (g_bRunAsDaemon)
724736
{
725737
/* Deamonize */
726-
daemonize(szStartupFolder.c_str(), PID_FILE);
738+
daemonize(szStartupFolder.c_str(), pidfile.c_str());
727739
}
728740
if ((g_bRunAsDaemon) || (g_bUseSyslog))
729741
{
@@ -788,7 +800,7 @@ int main(int argc, char**argv)
788800
daemonShutdown();
789801

790802
// Delete PID file
791-
remove(PID_FILE);
803+
remove(pidfile.c_str());
792804
}
793805
#else
794806
// Release WinSock

0 commit comments

Comments
 (0)