Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to start svnserve with systemctl systemd

Tags:

svn

systemd

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?

like image 810
user855443 Avatar asked Jul 05 '16 07:07

user855443


3 Answers

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.

like image 118
Yves Martin Avatar answered Nov 04 '22 06:11

Yves Martin


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
like image 30
EricS Avatar answered Nov 04 '22 07:11

EricS


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
like image 20
Matt Hovey Avatar answered Nov 04 '22 07:11

Matt Hovey