From d9f6f3f68e588eacc0fb3900d7006546e2f8214d Mon Sep 17 00:00:00 2001 From: Mamoru TASAKA Date: Dec 30 2015 16:48:22 +0000 Subject: Switch to use systemd unit on F-24+ --- diff --git a/xtide-2.14-rcscript-pidfile-with-server-change.patch b/xtide-2.14-rcscript-pidfile-with-server-change.patch new file mode 100644 index 0000000..d6f4ee3 --- /dev/null +++ b/xtide-2.14-rcscript-pidfile-with-server-change.patch @@ -0,0 +1,51 @@ +--- xtide-2.14/scripts/Fedora/rc.xttpd.pid_rc 2006-11-25 07:03:03.000000000 +0900 ++++ xtide-2.14/scripts/Fedora/rc.xttpd 2015-12-30 23:37:17.110917961 +0900 +@@ -6,13 +6,14 @@ + # description: Harmonic tide clock and tide predictor server + # processname: xttpd + # config: /etc/sysconfig/xttpd +-# pidfile: /var/run/xttpd.pid ++# pidfile: /var/run/xttpd/xttpd.pid + # + + PATH=/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin + CONFIG=/etc/sysconfig/xttpd + + LOCK=/var/lock/subsys/xttpd ++PIDFILE=/var/run/xttpd.pid + + # Source function library. + . /etc/rc.d/init.d/functions +@@ -40,13 +41,8 @@ + return $RETVAL + fi + +- if test "$XTTPD_FEEDBACK"; then +- daemon $DAEMON $PORT XTTPD_FEEDBACK=$XTTPD_FEEDBACK HOME=$HOME ++ daemon --pidfile $PIDFILE $DAEMON $PORT XTTPD_FEEDBACK=$XTTPD_FEEDBACK HOME=$HOME + RETVAL=$? +- else +- daemon $DAEMON $PORT HOME=$HOME +- RETVAL=$? +- fi + [ $RETVAL -eq 0 ] && touch $LOCK + echo + return $RETVAL +@@ -54,7 +50,7 @@ + + stop(){ + echo -n $"Stopping $PROG: " +- killproc $DAEMON ++ killproc -p $PIDFILE $DAEMON + RETVAL=$? + [ $RETVAL -eq 0 ] && rm -f $LOCK + echo +@@ -67,7 +63,7 @@ + } + + status_xttpd(){ +- status $PROG ++ status -p $PIDFILE $PROG + } + + case "$1" in diff --git a/xtide-2.14-server-write-pid.patch b/xtide-2.14-server-write-pid.patch new file mode 100644 index 0000000..506ab48 --- /dev/null +++ b/xtide-2.14-server-write-pid.patch @@ -0,0 +1,147 @@ +--- xtide-2.14/xttpd.cc.pidfile 2014-10-12 04:42:10.000000000 +0900 ++++ xtide-2.14/xttpd.cc 2015-12-30 21:05:16.087233767 +0900 +@@ -34,6 +34,11 @@ using namespace libxtide; + #include + #include + #include ++#include ++#include ++#include ++#include ++#include + + + // These browsers nowadays can get pretty verbose. +@@ -44,6 +49,11 @@ static const size_t bufsize (10000); + static Dstr webmaster; + static ZoneIndex zoneIndex; + static bool zoneinfoIsNotHorriblyObsolete; ++static int processTermReason = 0; ++ ++// Pid file name ++#define PID_FILE_DIR "/var/run/xttpd" ++#define PID_FILE_NAME PID_FILE_DIR "/xttpd.pid" + + + namespace TimeControl { +@@ -1153,6 +1163,89 @@ static void dontBeRoot() { + } + } + ++static void createPidFileDirectory(void) { ++ struct stat st; ++ mode_t dirMode = S_IRWXU | S_IRGRP | S_IXGRP; ++ ++ if (stat(PID_FILE_DIR, &st) != 0) { ++ int errnum = errno; ++ if (errnum != ENOENT) { ++ Global::xperror("stat"); ++ exit (-1); ++ } ++ ++ if (mkdir(PID_FILE_DIR, dirMode) < 0) { ++ Global::xperror("mkdir"); ++ exit (-1); ++ } ++ ++ if (stat(PID_FILE_DIR, &st) != 0) { ++ Global::xperror("stat"); ++ exit (-1); ++ } ++ } ++ ++ // Make it sure that PID_FILE_DIR is a directory ++ // (not a symlink or so) ++ if (!S_ISDIR(st.st_mode)) { ++ Dstr msg (PID_FILE_DIR " is not a directory"); ++ Global::log (msg, LOG_ERR); ++ exit (-1); ++ } ++ ++ // Again chmod ++ if (chmod(PID_FILE_DIR, dirMode) < 0) { ++ Global::xperror("chmod"); ++ exit (-1); ++ } ++ ++ group *gr = getgrnam (xttpd_group); ++ if (!gr) { ++ Global::xperror ("getgrnam"); ++ exit (-1); ++ } ++ passwd *nb = getpwnam (xttpd_user); ++ if (!nb) { ++ Global::xperror ("getpwnam"); ++ exit(-1); ++ } ++ ++ if (chown(PID_FILE_DIR, nb->pw_uid, gr->gr_gid) < 0) { ++ Global::xperror ("chown"); ++ exit(-1); ++ } ++ ++} ++ ++static void writePidFile(pid_t pid) { ++ FILE *pidFd = fopen(PID_FILE_NAME, "w"); ++ if (!pidFd) { ++ Global::xperror("fopen"); ++ exit (-1); ++ } ++ ++ if (fprintf(pidFd, "%d", (int)pid) < 0) { ++ Global::xperror ("fprintf"); ++ exit (-1); ++ } ++ ++ fclose(pidFd); ++} ++ ++static void handlerSigterm(int sig) { ++ processTermReason = sig; ++} ++ ++static void initSignalHander(void) { ++ struct sigaction sigact; ++ memset(&sigact, 0, sizeof sigact); ++ ++ sigemptyset(&sigact.sa_mask); ++ sigact.sa_flags |= SA_RESTART; ++ sigact.sa_handler = handlerSigterm; ++ ++ sigaction(SIGTERM, &sigact, NULL); ++} + + int main (int argc, char **argv) { + +@@ -1181,7 +1274,13 @@ int main (int argc, char **argv) { + portNumberEvade = parseAddress (portnum, addr, argv[1]); + setupSocket (portnum, addr, listenSocket); + } ++ // Create pid directory before dropping priviledge ++ createPidFileDirectory(); + dontBeRoot(); ++ writePidFile(getpid()); ++ ++ // Initialize signal handler ++ initSignalHander(); + + // An unfortunate consequence of needing to drop root ASAP is that + // failure to bind the port prevents xttpd -v from working. +@@ -1212,7 +1311,7 @@ int main (int argc, char **argv) { + FD_ZERO (&rdset); + FD_SET (listenSocket, &rdset); + sockaddr addr; +- while (true) { ++ while (!processTermReason) { + fd_set trdset, twrset, texset; + trdset = rdset; + // I seem to remember that some platforms barf if you provide +@@ -1235,6 +1334,7 @@ int main (int argc, char **argv) { + while (waitpid (-1, (int*)NULL, WNOHANG|WUNTRACED) > 0); + } + ++ unlink(PID_FILE_NAME); + exit (0); + } + diff --git a/xtide.spec b/xtide.spec index 9fc0627..a634cb5 100644 --- a/xtide.spec +++ b/xtide.spec @@ -2,8 +2,13 @@ #%%define betatag dev-20141014 %define dwfdate 20151227 +%global use_systemd_unit 1 +%if 0%{?fedora} <= 23 +%global use_systemd_unit 0 +%endif + -%define fedorarel 4 +%define fedorarel 6 %define rel %{?betatag:0.}%{fedorarel}%{?betatag:.%(echo %betatag | sed -e 's|-||g')} @@ -30,8 +35,11 @@ Source30: xtide-README.fedora #Source40: Harminics-USpart-recreate-sh.tar.bz2 #Source41: harmonics-dwf-%{dwfdate}-dump-US.tar.bz2 Source42: ftp://ftp.flaterco.com/xtide/harmonics-dwf-%{dwfdate}-free.tar.bz2 +# The following files need discussion with the upstream +Source50: xttpd.service # new systemd ( >= 37.4? ) needs pidfile -Patch0: xtide-2.12.1-rcscript-pidfile.patch +Patch0: xtide-2.14-rcscript-pidfile-with-server-change.patch +Patch1: xtide-2.14-server-write-pid.patch License: GPLv3+ Group: Applications/Engineering @@ -43,8 +51,9 @@ BuildRequires: zlib-devel BuildRequires: desktop-file-utils BuildRequires: libdstr-devel BuildRequires: libtcd-devel -%if 0%{?fedora} >= 17 BuildRequires: gpsd-devel >= 3 +%if %{?use_systemd_unit} +BuildRequires: systemd-devel %endif Requires: wvs-data @@ -123,7 +132,8 @@ grep -rl 'include.*' . | while read f ; do sed -i.name -e 's|\(include.*\)|\1|' $f done -%patch0 -p1 -b .pid +%patch1 -p1 -b .pid_server +%patch0 -p1 -b .pid_rc # Embed version sed -i.ver \ @@ -178,6 +188,20 @@ echo "%{_datadir}/wvs-data/" >> %{name}.conf %{__sed} -i -e 's|/usr/libexec|%{_libexecdir}|' \ $RPM_BUILD_ROOT%{_sbindir}/xttpd +# Create pid directory for xttpd +# and create tmpfile.d file +%{__mkdir_p} ${RPM_BUILD_ROOT}%{_localstatedir}/run/xttpd +%{__mkdir_p} ${RPM_BUILD_ROOT}%{_prefix}/lib/tmpfiles.d +%{__cat} > ${RPM_BUILD_ROOT}%{_prefix}/lib/tmpfiles.d/xttpd.conf </dev/null || : fi +%endif [ $1 -eq 0 ] || exit 0 touch --no-create %{_datadir}/icons/hicolor || : @@ -268,10 +302,14 @@ getent passwd xttpd &> /dev/null || \ exit 0 %preun +%if 0%{?use_systemd_unit} +%systemd_preun xttpd.service +%else if [ $1 = 0 ] ; then /sbin/service xttpd stop &>/dev/null /sbin/chkconfig --del xttpd fi +%endif exit 0 %posttrans @@ -317,13 +355,28 @@ exit 0 # xttpd %config(noreplace) %{_sysconfdir}/sysconfig/xttpd +%attr(0750,xttpd,xttpd) %dir %{_localstatedir}/run/xttpd +%{_prefix}/lib/tmpfiles.d/xttpd.conf +%if 0%{?use_systemd_unit} +%{_unitdir}/xttpd.service +%else %{_initddir}/xttpd +%endif %{_sbindir}/xttpd %{_libexecdir}/xttpd %{_datadir}/man/man8/xttpd.8* %changelog +* Thu Dec 31 2015 Mamoru TASAKA - 2.14.3-6 +- Switch to use systemd unit on F-24+ + +* Wed Dec 30 2015 Mamoru TASAKA - 2.14.3-5 +- Make xttpd server create pidfile by itself +- Modify rcscript to reflect server change +- Remove if-condition when calling xttpd-wrapper.sh + with regard to XTTPD_FEEDBACK option + * Tue Dec 29 2015 Mamoru TASAKA - 2.14.3-4 - Harmonics data 20151227 diff --git a/xttpd.service b/xttpd.service new file mode 100644 index 0000000..fbbf976 --- /dev/null +++ b/xttpd.service @@ -0,0 +1,13 @@ +[Unit] +Description=Harmonic tide clock and tide predictor (web server) +Documentation=man:xttpd(8) +After=network.target + +[Service] +Type=forking +PIDFile=/var/run/xttpd/xttpd.pid +EnvironmentFile=-/etc/sysconfig/xttpd +ExecStart=/usr/sbin/xttpd $PORT XTTPD_FEEDBACK=$XTTPD_FEEDBACK HOME=$HOME + +[Install] +WantedBy=multi-user.target