subversion package in debian jessie does not include a systemd service file. what is the simplest solution for automatic start. i try
[Unit]
Description=Subversion protocol daemon
After=syslog.target network.target
[Service]
Type=forking
#EnvironmentFile=/etc/conf.d/svnserve
#ExecStart=/usr/bin/svnserve --daemon $SVNSERVE_ARGS
ExecStart=/usr/bin/svnserve -d -r /svnFolder/repositories
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
Alias=svnserve.service
it is an adaptation of https://bbs.archlinux.org/viewtopic.php?id=190127 but i have put the arguments directly for svnserve directly here.
what can be improved?
Here is a proposal to setup svnserve
service "the-Debian-way" running with a dedicated svn
service account with proper logging. According to FHS, repositories should be stored in /srv/
:
mkdir -p /srv/svn/repos; chown svn /srv/svn/repos
First, the service configuration for systemd /etc/systemd/system/svnserve.service
:
[Unit]
Description=Subversion protocol daemon
After=syslog.target network.target
[Service]
Type=forking
RuntimeDirectory=svnserve
PIDFile=/run/svnserve/svnserve.pid
EnvironmentFile=/etc/default/svnserve
ExecStart=/usr/bin/svnserve $DAEMON_ARGS
User=svn
Group=svn
KillMode=control-group
Restart=on-failure
[Install]
WantedBy=multi-user.target
Second, the service startup options at /etc/default/svnserve
:
# svnserve options
DAEMON_ARGS="--daemon --pid-file /run/svnserve/svnserve.pid --root /srv/svn/repos --log-file /var/log/svnserve/svnserve.log"
To work properly, the folder for log files must be created with proper ownership and run location for pid file too:
mkdir /var/log/svnserve; chown svn /var/log/svnserve
mkdir -p /run/svnserve; chown svn /run/svnserve
To end with log rotation configuration /etc/logrotate.d/svnserve
:
/var/log/svnserve/*.log {
daily
missingok
rotate 14
compress
notifempty
create 640 svn adm
sharedscripts
postrotate
if /bin/systemctl status svnserve > /dev/null ; then \
/bin/systemctl restart svnserve > /dev/null; \
fi;
endscript
}
Hope this helps.
Update: My answer below has been obsoleted. These improvements and others have been incorporated into Yves Martin's excellent solution.
I have two improvements: it's generally recommended not to run such things as root. Create a user for this, for example 'svn'. It is also recommended to explicitly specify a PID file when using forking. My svnserve.service looks much like yours except I add the lines:
User=svn
Group=svn
PIDFile=/usr/local/svn/svnserve.pid
ExecStart=/usr/bin/svnserve -d -r /usr/local/svn/repos --pid-file /usr/local/svn/svnserve.pid
One comment on Yves Martin's excellent answer above (I don't have the rep points to comment yet):
When trying to enable the service to start on boot, I'd get an error:
$ sudo systemctl enable svnserve.service
Failed to execute operation: Invalid argument
After doing some research I found you apparently cannot set an alias to the same name as the service. Deleting the Alias line from the [Install] section of the svnserve.service solved the issue:
[Unit]
Description=Subversion protocol daemon
After=syslog.target network.target
[Service]
Type=forking
RuntimeDirectory=svnserve
PIDFile=/run/svnserve/svnserve.pid
EnvironmentFile=/etc/default/svnserve
ExecStart=/usr/bin/svnserve $DAEMON_ARGS
User=svn
Group=svn
KillMode=control-group
Restart=on-failure
[Install]
WantedBy=multi-user.target
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With