2

I've created scripts to control starting, stopping, etc. of my git-daemon on Fedora28. I'm now attempting to link these scripts to a systemd service so git-daemon will be available after reboot.

The primary script (gitT) is...

#!/bin/bash
case "$1" in
  'start')
    echo "Starting git-daemon"
    /home/git/scripts/start.sh >> /home/git/gitT.log
    ;;
  'stop')
    echo "Stopping git-daemon"
    /home/git/scripts/stop.sh >> /home/git/gitT.log
    ;;
  'restart')
    echo "Bouncing git-daemon"
    /home/git/scripts/bounce.sh >> /home/git/gitT.log
    ;;
  'status')
    echo "Status of git-daemon"
    /home/git/scripts/status.sh
    ;;
  *)
    echo "`basename $0`: usage: `basename $0` { stop | start | restart | status }"
    ;;
esac

Secondary scripts are...

start.sh

#!/bin/bash
# --------------------------
echo "---------------------"
/usr/bin/git daemon --export-all --enable=receive-pack --verbose --pid-file=/home/git/git-daemon.pid --base-path=/home/git/repos >> /home/git/git-daemon.out 2>> /home/git/git-daemon.err &
echo "---------------------"
echo "STARTED at `date`"

stop.sh

#!/bin/bash
# --------------------------
echo "---------------------"
pkill -F /home/git/git-daemon.pid
echo "---------------------"
echo "STOPPED at `date`"

bounce.sh

#!/bin/bash
# --------------------------
echo "====================="
/home/git/scripts/stop.sh
echo "====================="
sleep 5
echo "====================="
/home/git/scripts/start.sh
echo "====================="
echo "BOUNCED"

and status.sh

#!/bin/bash
# --------------------------
echo "====================="
ps -x --forest
echo "====================="

Finally I created a service file (git-daemon.service)...

[Unit]
Description=Git Daemon
Documentation=man:git-daemon(1)
ConditionPathExists=/home/git/repos

[Service]
Type=oneshot
ExecStart=/bin/bash /home/git/gitT start
ExecStop=/bin/bash /home/git/gitT stop
RemainAfterExit=yes
User=git
Group=git

[Install]
WantedBy=multi-user.target

Then I set it up with these commands...

cp /home/git/git-daemon.service /etc/systemd/system
systemctl enable git-daemon.service

Now if I run gitT start as the git user, everything starts fine. But it I run systemctl start git-daemon as root, this is the error...

fatal: base-path '/home/git/repos' does not exist or is not a directory

1 Answer 1

6

fatal: base-path '/home/git/repos' does not exist or is not a directory

is caused by

ConditionPathExists=/home/git/repos

Since it thinks that directory does not exist. What is the output of

ls -ld /home/git/repos

?

When running it manually does the process actually start? or are you just not getting any errors back when you run it manually? Since with the level of scripts you have backgrounding and redirecting output they scripts will run successfully no matter if the underlying commands fails or not. You should check the log files you have created.


But why do you have so many files to begin with? You can reduce this all down to a single service file with:

[Unit]
Description=Git Daemon
Documentation=man:git-daemon(1)
ConditionPathExists=/home/git/repos

[Service]
ExecStart=/usr/bin/git daemon --export-all --enable=receive-pack --verbose --base-path=/home/git/repos
User=git
Group=git

[Install]
WantedBy=multi-user.target

Then you can view all logs with journalctl -xfu git-daemon and not worry about having to keep track of the PID file.

1
  • The output of # ls -ld /home/git/repos is drwxrwxr-x. 3 git git 4096 May 18 08:10 /home/git/repos. And as I stated, everything works if I run it from the git user. Only if I run it from root with systemctl does if fail.
    – dacracot
    May 19, 2018 at 14:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .