ZFS Automatic Snapshot Daemon
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
#!/usr/local/bin/bash
|
|
|
|
|
|
|
|
install() {
|
|
|
|
uninstall
|
|
|
|
|
|
|
|
cat >"$launchd_file" << EOF
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
|
|
<plist version="1.0">
|
|
|
|
<dict>
|
|
|
|
<key>Label</key>
|
|
|
|
<string>$launchd_name</string>
|
|
|
|
<key>ProgramArguments</key>
|
|
|
|
<array>
|
|
|
|
<string>`which python3`</string>
|
|
|
|
<string>$zasd_root/src/zasd.py</string>
|
|
|
|
</array>
|
|
|
|
<key>KeepAlive</key>
|
|
|
|
<$keep_alive/>
|
|
|
|
<key>StandardOutPath</key>
|
|
|
|
<string>$log_root/zasd.log</string>
|
|
|
|
<key>StandardErrorPath</key>
|
|
|
|
<string>$log_root/zasd.err</string>
|
|
|
|
</dict>
|
|
|
|
</plist>
|
|
|
|
EOF
|
|
|
|
|
|
|
|
load
|
|
|
|
}
|
|
|
|
|
|
|
|
uninstall() {
|
|
|
|
if is_installed; then
|
|
|
|
unload
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm -f "$launchd_file"
|
|
|
|
}
|
|
|
|
|
|
|
|
load() {
|
|
|
|
launchctl load -w "$launchd_file"
|
|
|
|
}
|
|
|
|
|
|
|
|
unload() {
|
|
|
|
launchctl unload -w "$launchd_file"
|
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
|
|
|
launchctl kickstart -k $domain/$launchd_name
|
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
launchctl stop $launchd_name
|
|
|
|
}
|
|
|
|
|
|
|
|
is_installed() {
|
|
|
|
launchctl list | fgrep -q $launchd_name
|
|
|
|
}
|
|
|
|
|
|
|
|
initialise() {
|
|
|
|
if [ $UID == 0 ]; then
|
|
|
|
launchd_file="/Library/LaunchDaemons/$launchd_name.plist"
|
|
|
|
domain=system
|
|
|
|
log_root="/var/log"
|
|
|
|
else
|
|
|
|
launchd_file="$HOME/Library/LaunchAgents/$launchd_name.plist"
|
|
|
|
domain=gui/$UID
|
|
|
|
log_root="$zasd_root/log"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
zasd_root="$(dirname "$(greadlink -f "$0")")/../.."
|
|
|
|
|
|
|
|
launchd_name=no.thj.zasd
|
|
|
|
|
|
|
|
keep_alive=true
|
|
|
|
|
|
|
|
# Parse arguments
|
|
|
|
while (($#)); do
|
|
|
|
case $1 in
|
|
|
|
-K|--keep-alive)
|
|
|
|
keep_alive=true
|
|
|
|
;;
|
|
|
|
|
|
|
|
-k|--no-keep-alive)
|
|
|
|
keep_alive=false
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
command=$1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
initialise
|
|
|
|
|
|
|
|
case $command in
|
|
|
|
install)
|
|
|
|
install
|
|
|
|
;;
|
|
|
|
|
|
|
|
uninstall)
|
|
|
|
uninstall
|
|
|
|
;;
|
|
|
|
|
|
|
|
load)
|
|
|
|
load
|
|
|
|
;;
|
|
|
|
|
|
|
|
unload)
|
|
|
|
unload
|
|
|
|
;;
|
|
|
|
|
|
|
|
start|restart)
|
|
|
|
start
|
|
|
|
;;
|
|
|
|
|
|
|
|
stop)
|
|
|
|
stop
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
echo "./zasctl [options] <install|load|start|restart|stop|unload|uninstall>"
|
|
|
|
;;
|
|
|
|
esac
|