Svn

SVN 伺服器開機啟動

  • October 29, 2020

我正在配置 Subversion 並希望它在啟動時啟動。使用以下命令系列:

sudo mkdir /var/svn
sudo useradd -r -s /bin/false svn
sudo mkdir /etc/svn
sudo cp /home/zipo/svnserve /etc/svn/svnserve
sudo chown root:root /etc/svn/svnserve
set execute to owner/group/other
sudo nano /lib/systemd/system/svn.service
sudo systemctl daemon-reload
sudo systemctl enable svn
sudo systemctl start svn

當我在 syslog 中鍵入手動命令以啟動服務sudo systemctl start svn時,會出現以下日誌條目:

   Oct 29 10:13:27 testserver systemd[1]: Started SVN server.
   Oct 29 10:13:27 testserver svnserve[3128]:  * Starting svnserve...
   Oct 29 10:13:27 testserver svnserve[3128]:    ...done.

但服務不起作用。我在正確的埠 9999 上檢查它,如配置中所述。如果我使用以下命令手動執行它,它會啟動並正常工作:sudo -H -u svn bash -c '/etc/svn/svnserve start'

我錯過了什麼?

svn.service 文件內容:

   [Unit]
   Description=SVN server
   After=network.target

   [Service]
   User=svn
   Group=svn
   Type=simple
   ExecStart=/etc/svn/svnserve start
   GuessMainPID=no

   [Install]
   WantedBy=multi-user.target

svnserve 文件內容:

   #! /bin/sh -e
   #
   # svnserve - brings up the svn server so anonymous users
   # can access svn
   #

   # Get LSB functions
   . /lib/lsb/init-functions
   . /etc/default/rcS

   SVNSERVE=/usr/bin/svnserve
   SVN_USER=svn
   SVN_GROUP=svn
   SVN_REPO_PATH=/var/svn/

   # Check that the package is still installed
   [ -x $SVNSERVE ] || exit 0;

   case "$1" in
           start)
                   log_begin_msg "Starting svnserve..."
                   umask 002
                   if start-stop-daemon --start \
                   --chuid $SVN_USER:$SVN_GROUP \
                   --exec $SVNSERVE \
                   -- -d --listen-port=9999 -r $SVN_REPO_PATH; then
                           log_end_msg 0
                   else
                           log_end_msg $?
                   fi
           ;;

           stop)
                   log_begin_msg "Stopping svnserve..."
                   if start-stop-daemon --stop --exec $SVNSERVE; then
                   log_end_msg 0
                   else
                   log_end_msg $?
                   fi
           ;;

           restart|force-reload)
                   "$0" stop && "$0" start
           ;;

           *)
           echo "Usage: /etc/init.d/svnserve {start|stop|restart|force-reload}"
                   exit 1
           ;;
   esac

   exit 0

以下單位定義對我有用:

[Unit]
Description=SVN server
After=network.target

[Service]
User=svn
Group=svn
Type=forking
ExecStart=/usr/bin/svnserve -d --listen-port=9999 -r /var/svn

[Install]
WantedBy=multi-user.target

請注意,我之所以設置Type=forking是因為svnserve使用-d.

旁注:您自己的服務定義應該轉到/etc/systemd/system/,/lib/systemd/system/保留用於系統包附帶的單元定義。

引用自:https://serverfault.com/questions/1040489