我正在配置 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
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
答案1
以下单位定义对我有用:
[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/
它保留用于系统包附带的单元定义。