Skip to content

Commit 39ceb18

Browse files
committed
Experimental systemd service for dovesnap.
TODO: work through most install/upgrade scenarios and test. Tested manually working with own "dovesnap" user, "docker" group.
1 parent 4e7a554 commit 39ceb18

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ See also https://docs.faucet.nz for FAUCET documentation, including monitoring d
1313
* Optionally: additional physical interfaces to connect other hosts also running dovesnap
1414
* non-netfilter iptables. For Debian/Ubuntu, follow the legacy option at https://wiki.debian.org/iptables (`update-alternatives --set iptables /usr/sbin/iptables-legacy`). This requirement will be addressed in a future version.
1515

16+
### Installing as a systemd service
17+
18+
The `install.sh` and `uninstall.sh` scripts can be used to install and uninstall dovesnap as a systemd managed service. An upgrade can be accomplished by executing a `git pull` within `~dovesnap` as the `dovesnap` user, and restarting the service. Persistent configuration is stored in `~dovesnap/service.env`.
19+
1620
### QuickStart Instructions
1721

1822
These instructions describe the most basic use of dovesnap - creating a docker network with Internet access, where dovesnap provides all the FAUCET infrastructure. See below for more advanced usage.

dovesnap.service

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# TODO: copy default service.env, install dovesnap.service and enable/start.
2+
[Unit]
3+
Description=dovesnap
4+
Requires=docker.service
5+
After=docker.service
6+
7+
[Service]
8+
Restart=always
9+
# TODO: create dovesnap user, add to docker group.
10+
User=dovesnap
11+
Group=docker
12+
WorkingDirectory=/home/dovesnap/dovesnap
13+
EnvironmentFile=/home/dovesnap/service.env
14+
ExecStartPre=/usr/local/bin/docker-compose build
15+
ExecStartPre=-mkdir -p ${FAUCET_PREFIX}
16+
# DOCKERFILES without {} as contains spaces.
17+
ExecStartPre=-/usr/local/bin/docker-compose $DOCKERFILES down
18+
ExecStart=/usr/local/bin/docker-compose $DOCKERFILES up
19+
ExecStop=/usr/local/bin/docker-compose $DOCKERFILES down
20+
21+
[Install]
22+
WantedBy=multi-user.target

install.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/sh
2+
3+
echo installing dovesnap
4+
5+
giturl=$1
6+
7+
for dep in docker docker-compose git ; do
8+
depv=$($dep --version 2>/dev/null)
9+
if [ "$depv" = "" ] ; then
10+
echo $dep not installed.
11+
exit 1
12+
fi
13+
done
14+
15+
if [ -f /etc/systemd/system/dovesnap.service ] ; then
16+
echo dovesnap service already installed.
17+
exit 1
18+
fi
19+
20+
dovesnapid=$(id dovesnap 2>/dev/null)
21+
if [ "$dovesnapid" != "" ] ; then
22+
echo dovesnap user already exists.
23+
exit 1
24+
fi
25+
26+
sudo useradd -m dovesnap -G docker
27+
if [ "$giturl" = "" ] ; then
28+
sudo -u dovesnap -s eval 'cd ~dovesnap && git clone https://github.com/iqtlabs/dovesnap && cd ~dovesnap/dovesnap && git fetch --all --tags && git checkout $(git describe --tags --abbrev=0)' || exit
29+
else
30+
sudo -u dovesnap -s eval "cd ~dovesnap && git clone $giturl" || exit
31+
fi
32+
sudo -u dovesnap -s eval 'cp ~dovesnap/dovesnap/service.env ~dovesnap' || exit
33+
sudo cp ~dovesnap/dovesnap/dovesnap.service /etc/systemd/system || exit
34+
sudo systemctl daemon-reload || exit
35+
sudo systemctl enable dovesnap || exit
36+
sudo systemctl start dovesnap
37+
38+
echo dovesnap installed

service.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Where FAUCET will store dovesnap managed config.
2+
FAUCET_PREFIX=/home/dovesnap/faucet
3+
# TODO: optionally use remote FAUCET/RPC service.
4+
DOCKERFILES=-f docker-compose.yml -f docker-compose-standalone.yml

uninstall.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
3+
echo uninstalling dovesnap
4+
5+
if [ ! -f /etc/systemd/system/dovesnap.service ] ; then
6+
echo dovesnap service not installed.
7+
exit 1
8+
fi
9+
10+
dovesnapid=$(id dovesnap)
11+
if [ "$dovesnapid" = "" ] ; then
12+
echo no dovesnap user.
13+
exit 1
14+
fi
15+
16+
sudo service dovesnap stop || true
17+
sudo systemctl disable dovesnap
18+
sudo rm -f /etc/systemd/system/dovesnap.service
19+
sudo userdel -r dovesnap
20+
21+
echo dovesnap uninstalled

0 commit comments

Comments
 (0)