CREATE init.d ipfs start/stop script
This commit is contained in:
parent
fca5581679
commit
b9ede3d0bc
|
@ -76,6 +76,113 @@ EOF
|
||||||
sudo cp -f /tmp/ipfs.service /etc/systemd/system/
|
sudo cp -f /tmp/ipfs.service /etc/systemd/system/
|
||||||
sudo sed -i "s/_USER_/$USER/g" /etc/systemd/system/ipfs.service
|
sudo sed -i "s/_USER_/$USER/g" /etc/systemd/system/ipfs.service
|
||||||
|
|
||||||
|
echo "CREATE init.d ipfs start/stop script"
|
||||||
|
cat > /tmp/ipfs.service <<EOF
|
||||||
|
|
||||||
|
#!/bin/sh
|
||||||
|
### BEGIN INIT INFO
|
||||||
|
# Provides: ipfs-daemon
|
||||||
|
# Required-Start: $remote_fs $network $named $syslog
|
||||||
|
# Required-Stop: $remote_fs $network $named $syslog
|
||||||
|
# Should-Start: iptables ip6tables firewalld
|
||||||
|
# Should-Stop: $remote_fs $network $syslog
|
||||||
|
# Default-Start: 2 3 4 5
|
||||||
|
# Default-Stop: 0 1 6
|
||||||
|
# Short-Description: Start/Stop IPFS Daemon
|
||||||
|
# Description: Starts or stops the IPFS Daemon with watchdogging
|
||||||
|
### END INIT INFO
|
||||||
|
|
||||||
|
dir="/home/_USER_"
|
||||||
|
bin_path=`which ipfs`
|
||||||
|
cmd="$bin_path daemon"
|
||||||
|
user="_USER_"
|
||||||
|
|
||||||
|
name=`basename $0`
|
||||||
|
pid_file="/var/run/$name.pid"
|
||||||
|
tmp_file="/tmp/$name.pid"
|
||||||
|
log_file="/var/log/$name.log"
|
||||||
|
|
||||||
|
get_pid() {
|
||||||
|
cat "$pid_file"
|
||||||
|
}
|
||||||
|
|
||||||
|
is_running() {
|
||||||
|
[ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
if is_running; then
|
||||||
|
echo "Already started"
|
||||||
|
else
|
||||||
|
echo "Starting $name"
|
||||||
|
cd "$dir"
|
||||||
|
sudo -u "$user" /bin/sh -c 'echo $$>'"$tmp_file"' && exec '"$cmd"' 2>&1 >>'"$log_file" &
|
||||||
|
sleep 5
|
||||||
|
mv $tmp_file $pid_file
|
||||||
|
if ! is_running; then
|
||||||
|
echo "Unable to start $name"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
if is_running; then
|
||||||
|
echo -n "Stopping $name.."
|
||||||
|
kill -9 `get_pid`
|
||||||
|
for i in {1..10}
|
||||||
|
do
|
||||||
|
if ! is_running; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -n "."
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
|
||||||
|
if is_running; then
|
||||||
|
echo "Not stopped; may still be shutting down or shutdown may have failed"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "Stopped"
|
||||||
|
if [ -f "$pid_file" ]; then
|
||||||
|
rm "$pid_file"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Not running"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
restart)
|
||||||
|
$0 stop
|
||||||
|
if is_running; then
|
||||||
|
echo "Unable to stop, will not attempt to start"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
$0 start
|
||||||
|
;;
|
||||||
|
status)
|
||||||
|
if is_running; then
|
||||||
|
echo "Running"
|
||||||
|
else
|
||||||
|
echo "Stopped"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Usage: $0 {start|stop|restart|status}"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
EOF
|
||||||
|
sudo cp -f /tmp/ipfs.service /etc/init.d/ipfs
|
||||||
|
sudo sed -i "s/_USER_/$USER/g" /etc/init.d/ipfs
|
||||||
|
sudo touch /var/log/ipfs.log
|
||||||
|
sudo chown $USER /var/log/ipfs.log
|
||||||
|
|
||||||
[[ -d ~/.ipfs ]] && sudo chown -R $USER:$USER ~/.ipfs
|
[[ -d ~/.ipfs ]] && sudo chown -R $USER:$USER ~/.ipfs
|
||||||
|
|
||||||
sudo systemctl daemon-reload || err "Restart IPFS"
|
sudo systemctl daemon-reload || err "Restart IPFS"
|
||||||
|
|
Loading…
Reference in New Issue