#!/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# IPFS_UID=#UID# IPFS_GID=#GID# IPFS_PID_FILE=/var/run/ipfs.pid IPFS_DATA=#DATA# test -x $DAEMON || exit 0 . /lib/lsb/init-functions ipfs_start() { export "IPFS_PATH=$IPFS_DATA" 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 [ "$line" == "exit" ] || sudo -E -u ipfs ipfs $line [ "$?" == "1" ] && { echo "command failed" echo "use 'help' to show subcomands" echo "use ' --help' for more information" echo "use 'exit' to leave the console" } done } # ipfs_console 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) log_daemon_msg "Restarting rsync daemon" "ipfs" 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 ;; restart) log_daemon_msg "Restarting rsync daemon" "ipfs" 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}" exit 1 esac exit 0