Skip to content

Commit 4ff9236

Browse files
Create a start/stop script for Debian
1 parent c361108 commit 4ff9236

File tree

3 files changed

+98
-9
lines changed

3 files changed

+98
-9
lines changed

Makefile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ houseclock: $(OBJS)
2525
install:
2626
mkdir -p /usr/local/bin
2727
cp houseclock /usr/local/bin
28-
chown root:root /usr/local/bin/houseclock
29-
chmod 755 /usr/local/bin/houseclock
28+
cp init.debian /etc/init.d/houseclock
29+
chown root:root /usr/local/bin/houseclock /etc/init.d/houseclock
30+
chmod 755 /usr/local/bin/houseclock /etc/init.d/houseclock
31+
if [ -e /etc/init.d/ntp ] ; then systemctl stop ntp ; systemctl disable ntp ; fi
32+
systemctl daemon-reload
33+
systemctl enable houseclock
34+
systemctl start houseclock
35+
36+
uninstall:
37+
systemctl stop houseclock
38+
systemctl disable houseclock
39+
rm -f /usr/local/bin/houseclock
40+
rm -f /etc/init.d/houseclock
41+
systemctl daemon-reload
42+
if [ -e /etc/init.d/ntp ] ; then systemctl enable ntp ; systemctl start ntp ; fi
3043

README.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,33 @@ When no GPS device is available, the software acts as a NTP broadcast client, li
3636
* make
3737
* sudo make install
3838

39-
# Quick Start
39+
This installs HouseClock as a service (for Debian's systemd) and starts it. If ntpd was installed, this stops and disables ntp.
4040

41-
Manually run the server using the command:
42-
```
43-
houseclock
44-
```
45-
This will read from the GPS device at /dev/ttyACM0, listen for HTTP requests on the http tcp port (80) and handle NTP communication on the ntp udp port (123).
41+
# Configuration
42+
43+
With default options, HouseClock will read from the GPS device at /dev/ttyACM0, listen for HTTP requests on the http tcp port (80) and handle NTP communication on the ntp udp port (123).
4644

4745
All these default can be changed through command line options. For example, if the GPS device is different and the http port is already in use (httpd is running), one can force other values using the -http-service and -gps options:
4846
```
49-
houseclock -http-service=8080 -gps=/dev/ttyACM1
47+
houseclock -http-service=8080 -gps=/dev/tty0
5048
```
5149

5250
For more information about available options, a complete help is available:
5351
```
5452
houseclock -h
5553
````
5654
55+
The service options can be configured by creating file /etc/default/houseclock and set the following shell variables:
56+
57+
**GPS_OPTS**: GPS related options.
58+
**NTP_OPTS**: NTP related options.
59+
**HTTP_OPTS**: HTTP related options.
60+
**OTHER_OPTS**: general purpose options.
61+
62+
For example:
63+
```
64+
GPS_OPTS="-gps=/dev/tty0"
65+
NTP_OPTS="-ntp-period=30"
66+
HTTP_OPTS="-http-service=8080"
67+
```
68+

init.debian

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/sh
2+
3+
### BEGIN INIT INFO
4+
# Provides: ntp
5+
# Required-Start: $network $remote_fs $syslog
6+
# Required-Stop: $network $remote_fs $syslog
7+
# Default-Start: 2 3 4 5
8+
# Default-Stop:
9+
# Short-Description: Start SNTP daemon
10+
### END INIT INFO
11+
12+
PATH=/sbin:/bin:/usr/sbin:/usr/bin
13+
14+
. /lib/lsb/init-functions
15+
16+
DAEMON=/usr/local/bin/houseclock
17+
PIDFILE=/var/run/houseclock.pid
18+
19+
test -x $DAEMON || exit 0
20+
21+
GPS_OPTS=
22+
NTP_OPTS="-ntp-period=10"
23+
HTTP_OPTS=
24+
OTHER_OPTS=
25+
26+
if [ -r /etc/default/houseclock ]; then
27+
. /etc/default/houseclock
28+
fi
29+
30+
31+
case $1 in
32+
start)
33+
log_daemon_msg "Starting SNTP server" "houseclock"
34+
start-stop-daemon --start --quiet --oknodo --background --pidfile $PIDFILE --make-pidfile --startas $DAEMON -- $GPS_OPTS $NTP_OPTS $HTTP_OPTS $OTHER_OPTS
35+
log_end_msg $?
36+
;;
37+
stop)
38+
log_daemon_msg "Stopping NTP server" "houseclock"
39+
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE --retry=TERM/30/KILL/5 --exec $DAEMON
40+
log_end_msg $?
41+
rm -f $PIDFILE
42+
;;
43+
restart|force-reload)
44+
$0 stop && sleep 2 && $0 start
45+
;;
46+
try-restart)
47+
if $0 status >/dev/null; then
48+
$0 restart
49+
else
50+
exit 0
51+
fi
52+
;;
53+
reload)
54+
exit 3
55+
;;
56+
status)
57+
status_of_proc $DAEMON "SNTP server"
58+
;;
59+
*)
60+
echo "Usage: $0 {start|stop|restart|try-restart|force-reload|status}"
61+
exit 2
62+
;;
63+
esac
64+

0 commit comments

Comments
 (0)