Skip to content

Commit 04b0f9b

Browse files
authored
Merge pull request #160 from phl0/dev
Make PID writing and stopping via init.d/systemd work
2 parents c2175ea + 048fb78 commit 04b0f9b

File tree

3 files changed

+30
-18
lines changed

3 files changed

+30
-18
lines changed

LinuxExtras/Debian/ircDDBGateway/etc/init.d/ircddbgateway

+14-8
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,18 @@ do_start()
5757
# 1 if daemon was already running
5858
# 2 if daemon could not be started
5959

60-
# Check if the PID file exists and the actual status of the process
61-
if [ -e $PIDFILE ]; then
62-
status_of_proc -p $PIDFILE $DAEMON_PATH "$NAME process" && status="0" || status="$?"
63-
# If the status is SUCCESS then don't need to start again.
64-
if [ $status = "0" ]; then
65-
return 1 # Exit
60+
# Check if the PID directory and file exists and the actual status of the process
61+
PIDDIR=$(dirname "$PIDFILE")
62+
if [ ! -d "$PIDDIR" ]; then
63+
mkdir $PIDDIR
64+
chown $DAEMON_USER $PIDDIR
65+
else
66+
if [ -e $PIDFILE ]; then
67+
status_of_proc -p $PIDFILE $DAEMON_PATH "$NAME process" && status="0" || status="$?"
68+
# If the status is SUCCESS then don't need to start again.
69+
if [ $status = "0" ]; then
70+
return 1 # Exit
71+
fi
6672
fi
6773
fi
6874

@@ -118,7 +124,7 @@ do_stop()
118124
sleep 15
119125
fi
120126

121-
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
127+
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $DAEMON_NAME
122128
RETVAL="$?"
123129
[ "$RETVAL" = 2 ] && return 2
124130

@@ -147,7 +153,7 @@ do_reload() {
147153
# restarting (for example, when it is sent a SIGHUP),
148154
# then implement that here.
149155
#
150-
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
156+
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $DAEMON_NAME
151157
return 0
152158
}
153159

LinuxExtras/Raspbian/ircDDBGateway/etc/init.d/ircddbgateway

+14-8
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,18 @@ do_start()
5757
# 1 if daemon was already running
5858
# 2 if daemon could not be started
5959

60-
# Check if the PID file exists and the actual status of the process
61-
if [ -e $PIDFILE ]; then
62-
status_of_proc -p $PIDFILE $DAEMON_PATH "$NAME process" && status="0" || status="$?"
63-
# If the status is SUCCESS then don't need to start again.
64-
if [ $status = "0" ]; then
65-
return 1 # Exit
60+
# Check if the PID directory and file exists and the actual status of the process
61+
PIDDIR=$(dirname "$PIDFILE")
62+
if [ ! -d "$PIDDIR" ]; then
63+
mkdir $PIDDIR
64+
chown $DAEMON_USER $PIDDIR
65+
else
66+
if [ -e $PIDFILE ]; then
67+
status_of_proc -p $PIDFILE $DAEMON_PATH "$NAME process" && status="0" || status="$?"
68+
# If the status is SUCCESS then don't need to start again.
69+
if [ $status = "0" ]; then
70+
return 1 # Exit
71+
fi
6672
fi
6773
fi
6874

@@ -118,7 +124,7 @@ do_stop()
118124
sleep 15
119125
fi
120126

121-
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
127+
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $DAEMON_NAME
122128
RETVAL="$?"
123129
[ "$RETVAL" = 2 ] && return 2
124130

@@ -147,7 +153,7 @@ do_reload() {
147153
# restarting (for example, when it is sent a SIGHUP),
148154
# then implement that here.
149155
#
150-
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
156+
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $DAEMON_NAME
151157
return 0
152158
}
153159

ircDDBGateway/ircDDBGateway/IRCDDBGatewayAppD.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ int main(int argc, char** argv)
119119

120120
wxString pidFileName;
121121
if (!name.IsEmpty())
122-
pidFileName.Printf(wxT("/var/run/ircddbgateway_%s.pid"), name.c_str());
122+
pidFileName.Printf(wxT("/var/run/opendv/ircddbgateway_%s.pid"), name.c_str());
123123
else
124-
pidFileName = wxT("/var/run/ircddbgateway.pid");
124+
pidFileName = wxT("/var/run/opendv/ircddbgateway.pid");
125125
pidFileName.Replace(wxT(" "), wxT("_"));
126126

127127
char fileName[128U];

0 commit comments

Comments
 (0)