diff --git a/config.layout b/config.layout index da63e895a9d..4846fe3b6e9 100644 --- a/config.layout +++ b/config.layout @@ -277,3 +277,23 @@ logdir: /var/log+ cachedir: /var/lib+ + + + prefix: /opt/trafficserver + exec_prefix: ${prefix} + bindir: ${exec_prefix}/bin + sbindir: ${exec_prefix}/sbin + libdir: ${exec_prefix}/lib + libexecdir: ${exec_prefix}/libexec + infodir: ${prefix}/share/info + mandir: ${prefix}/share/man + sysconfdir: /etc+ + datadir: ${prefix}/share+ + docdir: ${prefix}/share/doc+ + installbuilddir: ${datadir}/build + includedir: ${prefix}/include + localstatedir: /var/lib+ + runtimedir: /run+ + logdir: /var/log+ + cachedir: /var/cache+ + diff --git a/rc/trafficserver.in b/rc/trafficserver.in index b0512ada4ee..03952d16ea2 100644 --- a/rc/trafficserver.in +++ b/rc/trafficserver.in @@ -66,6 +66,8 @@ elif [ "$UNAME_S" = "Darwin" ]; then DISTRIB_ID="Darwin" elif [ "$UNAME_S" = "FreeBSD" ]; then DISTRIB_ID="FreeBSD" +elif nixos-version > /dev/null; then + DISTRIB_ID="nixos" fi # We might want to move over to use /etc/system-release for more distros? @@ -90,7 +92,7 @@ test -x $ESED || ESED=sed # Ubuntu: Do NOT "set -e" #Ubuntu:PATH should only include /usr/* if it runs after the mountnfs.sh script -PATH=/usr/sbin:/usr/bin:/sbin:/bin +test "$DISTRIB_ID" != nixos && PATH=/usr/sbin:/usr/bin:/sbin:/bin DESC="start/stop Traffic Server" NAME=trafficserver SLEEP_TIME=5 @@ -135,6 +137,10 @@ elif [ "$DISTRIB_ID" = "Darwin" ]; then SCRIPTNAME=$0 # Darwin elif [ "$DISTRIB_ID" = "FreeBSD" ]; then SCRIPTNAME=$0 # FreeBSD +elif [ "$DISTRIB_ID" = "nixos" ]; then + SCRIPTNAME=$0 # NixOS + echo "Warn: Use of this script is not recommended on NixOS. Instead, enable the module" + echo " 'services.trafficserver' and use systemctl to control Traffic Server." else echo "This script needs to be ported to this OS" exit 1 @@ -183,7 +189,7 @@ if [ ! -d $TS_BASE@exp_runtimedir@ ]; then fi # -# Fedora: +# Fedora/NixOS: # launches $* in the background # and checks if program creates its own pid lock file # redirects stdout and stderr to files @@ -201,7 +207,7 @@ forkdaemon() do # check for regular file and size greater than 0 if [[ -f $TM_PIDFILE ]] && [[ -s $TM_PIDFILE ]]; then - success + success || true return 0 fi @@ -210,7 +216,7 @@ forkdaemon() done - failure + failure || true return 1 } @@ -321,6 +327,9 @@ case "$1" in echo -n "Starting ${TS_PACKAGE_NAME}" startproc -p $TM_PIDFILE $TM_DAEMON $TM_DAEMON_ARGS rc_status -v + elif [ "$DISTRIB_ID" = "nixos" ]; then + echo "Starting ${TS_PACKAGE_NAME}" + forkdaemon $TM_DAEMON $TM_DAEMON_ARGS elif [ "$DISTRIB_ID" = "Darwin" ]; then echo "Starting ${TS_PACKAGE_NAME}" launchctl bsexec / launchctl list $TM_NAME > /dev/null 2>&1 && exit 0 @@ -359,6 +368,16 @@ case "$1" in echo -n "Stopping ${TS_NAME}" killproc -p $TS_PIDFILE $TS_DAEMON rc_status -v + elif [ "$DISTRIB_ID" = "nixos" ]; then + echo "Stopping ${TS_PACKAGE_NAME}" + if [ -e "$TM_PIDFILE" ]; then + kill $(cat $TM_PIDFILE) + rm -f ${TM_PIDFILE} + fi + if [ -e "$TS_PIDFILE" ]; then + kill $(cat $TS_PIDFILE) + rm -f ${TS_PIDFILE} + fi elif [ "$DISTRIB_ID" = "Darwin" ]; then echo "Stopping ${TS_PACKAGE_NAME}" launchctl bsexec / launchctl list $TM_NAME > /dev/null 2>&1 || exit 0 @@ -404,6 +423,9 @@ case "$1" in echo -n "Reloading ${NAME}" $TL_BINARY config reload rc_status -v + elif [ "$DISTRIB_ID" = "nixos" ]; then + echo "Reloading ${NAME}" + $TL_BINARY config reload elif [ "$DISTRIB_ID" = "Darwin" ]; then echo "Reloading ${NAME}" $TL_BINARY config reload @@ -460,7 +482,7 @@ case "$1" in status=$? [ $status -eq 0 ] || /bin/echo -n "not " echo "running." - elif [ "$DISTRIB_ID" = "FreeBSD" -o "$DISTRIB_ID" = "gentoo" ]; then + elif [ "$DISTRIB_ID" = "FreeBSD" -o "$DISTRIB_ID" = "gentoo" -o "$DISTRIB_ID" = "nixos" ]; then if pgrep $TM_NAME > /dev/null ; then echo "$TM_NAME running as pid `cat $TM_PIDFILE`" ; else echo "$TM_NAME not running" @@ -496,6 +518,8 @@ case "$1" in echo "Usage: $0 {start|stop|reload|restart|status}" elif [ "$DISTRIB_ID" = "suse" ]; then echo "Usage: $0 {start|stop|restart|status}" + elif [ "$DISTRIB_ID" = "nixos" ]; then + echo "Usage: $0 {start|stop|reload|restart|status}" elif [ "$DISTRIB_ID" = "Darwin" ]; then echo "Usage: $0 {start|stop|restart|status}" elif [ "$DISTRIB_ID" = "FreeBSD" ]; then diff --git a/rc/trafficserver.service.in b/rc/trafficserver.service.in index 7aab8488dbd..a503a49d8cf 100644 --- a/rc/trafficserver.service.in +++ b/rc/trafficserver.service.in @@ -17,7 +17,7 @@ # [Unit] Description=Apache Traffic Server is a fast, scalable and extensible caching proxy server. -After=syslog.target network.target +After=network.target [Service] Type=simple @@ -26,10 +26,7 @@ ExecStart=@exp_bindir@/traffic_manager $TM_DAEMON_ARGS Restart=on-failure RestartSec=5s LimitNOFILE=1000000 -ExecStopPost=/bin/sh -c ' \ - export TM_PIDFILE=$(@exp_bindir@/traffic_layout 2>/dev/null | grep RUNTIMEDIR | cut -d: -f2)/manager.lock ; \ - /bin/rm $TM_PIDFILE ; \ - if [[ $? -ne 0 ]]; then echo "ERROR: Unable to delete PID"; exit 1; fi' +PIDFile=@exp_runtimedir@/manager.lock TimeoutStopSec=5s ExecReload=@exp_bindir@/traffic_ctl config reload KillMode=process diff --git a/tools/tsxs.in b/tools/tsxs.in index b480a36bfc9..c3cc8d44d85 100755 --- a/tools/tsxs.in +++ b/tools/tsxs.in @@ -204,6 +204,9 @@ do OBJ=$OPTARG ;; i) + if [[ "$INSTALLDIR" = /nix/store* ]]; then + bail "unsupported option: -i is disabled on Nix" + fi INSTALL=1 ;; c)