-
Notifications
You must be signed in to change notification settings - Fork 667
/
systemd.sh
executable file
·54 lines (47 loc) · 1.39 KB
/
systemd.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
service='[Unit]
Description=NewFuture ddns
After=network.target
[Service]
Type=simple
WorkingDirectory=/usr/share/DDNS
ExecStart=/usr/bin/env python /usr/share/DDNS/run.py -c /etc/DDNS/config.json
[Install]
WantedBy=multi-user.target'
timer='[Unit]
Description=NewFuture ddns timer
[Timer]
OnUnitActiveSec=5m
Unit=ddns.service
[Install]
WantedBy=multi-user.target'
if [[ "install" == $1 ]]; then
echo "$service" > /usr/lib/systemd/system/ddns.service
echo "$timer" > /usr/lib/systemd/system/ddns.timer
cp -r `pwd` /usr/share/
mkdir -p /etc/DDNS
if [ ! -f "/etc/DDNS/config.json" ];then
if [ -f "config.json" ];then
cp config.json /etc/DDNS/config.json
fi
fi
systemctl enable ddns.timer
systemctl start ddns.timer
echo "installed"
echo "useful commands:"
echo " systemctl status ddns view service status."
echo " journalctl -u ddns.timer view the logs."
echo "config file: /etc/DDNS/config.json"
elif [[ "uninstall" == $1 ]]; then
systemctl disable ddns.timer
rm /usr/lib/systemd/system/ddns.service
rm /usr/lib/systemd/system/ddns.timer
rm -rf /etc/DDNS
rm -rf /usr/share/DDNS
systemctl daemon-reload
echo "uninstalled"
else
echo "Tips:"
echo " $0 install install the ddns systemd service."
echo " $0 uninstall uninstall the ddns service."
fi