ipfs_daemon/ipfs.initd

105 lines
2.7 KiB
Plaintext
Raw Normal View History

2018-02-20 20:32:38 +00:00
#!/bin/sh
### BEGIN INIT INFO
# Provides: ipfs
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the ipfs daemon
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=#AIM#
2018-02-20 22:33:30 +00:00
IPFS_UID=#UID#
2018-02-25 15:23:17 +00:00
IPFS_GID=#GID#
2018-02-20 20:32:38 +00:00
IPFS_PID_FILE=/var/run/ipfs.pid
2018-02-25 15:23:17 +00:00
IPFS_DATA=#DATA#
2018-02-20 20:32:38 +00:00
test -x $DAEMON || exit 0
. /lib/lsb/init-functions
ipfs_start() {
export "IPFS_PATH=$IPFS_DATA"
2018-02-20 20:32:38 +00:00
if start-stop-daemon --start --quiet --background \
--pidfile $IPFS_PID_FILE --make-pidfile \
--chuid $IPFS_UID:$IPFS_GID --exec $DAEMON -- daemon
then
log_end_msg 0
else
log_end_msg 1
rm -f $IPFS_PID_FILE
fi
} # ipfs_start
ipfs_console() {
export "IPFS_PATH=$DATA_DIR"
export "HOME=$DATA_DIR"
line=
while [ "$line" != "exit" ] ; do
echo -n 'ipfs:> '
read line
#parse exit string
[ "$line" == "quit" ] && line=exit
# exec ipfs <comands>
[ "$line" == "exit" ] || sudo -E -u ipfs ipfs $line
[ "$?" == "1" ] && {
echo "command failed"
echo "use 'help' to show subcomands"
echo "use '<subcmd> --help' for more information"
echo "use 'exit' to leave the console"
}
done
} # ipfs_console
2018-02-20 20:32:38 +00:00
case "$1" in
start)
if [ -s $IPFS_PID_FILE ] && kill -0 $(cat $IPFS_PID_FILE) >/dev/null 2>&1; then
log_progress_msg "apparently already running"
log_end_msg 0
exit 0
fi
log_daemon_msg "Startin ipfs daemon" "ipfs"
ipfs_start
;;
stop)
log_daemon_msg "Stopping ipfs daemon" "ipfs"
start-stop-daemon --stop --quiet --oknodo --pidfile $IPFS_PID_FILE
og_end_msg $?
rm -f $IPFS_PID_FILE
;;
console)
2019-03-10 21:45:29 +00:00
log_daemon_msg "Restarting ipfs daemon"
if [ -s $IPFS_PID_FILE ] && kill -0 $(cat $IPFS_PID_FILE) >/dev/null 2>&1; then
start-stop-daemon --stop --quiet --oknodo --pidfile $IPFS_PID_FILE || true
sleep 1
else
log_warning_msg "ipfs daemon not running, attempting to start."
rm -f $IPFS_PID_FILE
fi
ipfs_start
ipfs_console
;;
2018-02-20 20:32:38 +00:00
restart)
2019-03-10 21:45:29 +00:00
log_daemon_msg "Restarting ipfs daemon"
2018-02-20 20:32:38 +00:00
if [ -s $IPFS_PID_FILE ] && kill -0 $(cat $IPFS_PID_FILE) >/dev/null 2>&1; then
start-stop-daemon --stop --quiet --oknodo --pidfile $IPFS_PID_FILE || true
sleep 1
else
log_warning_msg "ipfs daemon not running, attempting to start."
rm -f $IPFS_PID_FILE
fi
ipfs_start
;;
status)
status_of_proc -p $IPFS_PID_FILE "$DAEMON" ipfs
exit $?
;;
*)
echo "Usage: /etc/init.d/ipfs {start|stop|restart|status|console}"
2018-02-20 20:32:38 +00:00
exit 1
esac
exit 0