mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-02-24 13:30:02 +08:00
Download agent if missing
This commit is contained in:
parent
a7f9791292
commit
e849e307a3
@ -4,35 +4,64 @@ PIDFILE="/var/run/agent.pid"
|
|||||||
SCRIPT="/usr/local/bin/agent.sh"
|
SCRIPT="/usr/local/bin/agent.sh"
|
||||||
|
|
||||||
status() {
|
status() {
|
||||||
|
|
||||||
if [ -f "$PIDFILE" ]; then
|
if [ -f "$PIDFILE" ]; then
|
||||||
echo 'Service running'
|
echo 'Service running'
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
|
|
||||||
if [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")"; then
|
if [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")"; then
|
||||||
echo 'Service already running'
|
echo 'Service already running'
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
echo "-" > /var/lock/subsys/agent.sh
|
|
||||||
echo 'Starting agent service...'
|
echo 'Starting agent service...'
|
||||||
chmod 666 /dev/ttyS0
|
chmod 666 /dev/ttyS0
|
||||||
|
|
||||||
|
if [ -f "$SCRIPT" ]; then
|
||||||
|
|
||||||
|
echo 'ERROR: Agent script not found!' > /dev/ttyS0
|
||||||
|
|
||||||
|
TMP="/tmp/agent.sh"
|
||||||
|
URL="https://raw.githubusercontent.com/kroese/virtual-dsm/master/agent/agent.sh"
|
||||||
|
|
||||||
|
rm -f "${TMP}"
|
||||||
|
|
||||||
|
if ! curl -sfk -m 10 -o "${TMP}" "${URL}"; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mv -f "${TMP}" "${SCRIPT}"
|
||||||
|
chmod 755 "${SCRIPT}
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "-" > /var/lock/subsys/agent.sh
|
||||||
"$SCRIPT" &> /dev/ttyS0 & echo $! > "$PIDFILE"
|
"$SCRIPT" &> /dev/ttyS0 & echo $! > "$PIDFILE"
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
|
|
||||||
if [ ! -f "$PIDFILE" ] || ! kill -0 "$(cat "$PIDFILE")"; then
|
if [ ! -f "$PIDFILE" ] || ! kill -0 "$(cat "$PIDFILE")"; then
|
||||||
echo 'Service not running'
|
echo 'Service not running'
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -f /var/lock/subsys/agent.sh
|
rm -f /var/lock/subsys/agent.sh
|
||||||
echo 'Stopping agent service...'
|
echo 'Stopping agent service...'
|
||||||
|
|
||||||
chmod 666 /dev/ttyS0
|
chmod 666 /dev/ttyS0
|
||||||
echo 'Stopping agent service...' > /dev/ttyS0
|
echo 'Stopping agent service...' > /dev/ttyS0
|
||||||
|
|
||||||
kill -15 "$(cat "$PIDFILE")" && rm -f "$PIDFILE"
|
kill -15 "$(cat "$PIDFILE")" && rm -f "$PIDFILE"
|
||||||
|
|
||||||
echo 'Service stopped'
|
echo 'Service stopped'
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user