OctoPrint 遠端控制 3D印表機 視訊監看狀況 Mjpg-Streamer Webcam 開機自動啟動 (使用Raspberry Pi 樹莓派) OctoPrint 遠端控制 3D印表機 視訊監看狀況 Mjpg-Streamer Webcam 開機自動啟動 (使用Raspberry Pi 樹莓派)
  3D印表機、  Raspberry Pi、  OctoPrint、  Mjpg-Streamer       ez      2015-06-23

前一篇介紹 Mjpg-Streamer 的安裝方法,只要重新開機後就必須輸入指令啟動軟體,如果要讓 Mjpg-Streamer 開機後自動啟動,請依據下面方法操作。

首先切換到安裝的資料夾,新增一個 Shell 檔案,要用當作 service 服務使用,只需要輸入以下指令:

cd ~/mjpg-streamer/
vi mjpg-streamer.sh

將以下內容貼到 mjpg-streamer.sh 檔案內,並且儲存檔案。

###BEGIN INIT INFO
#Provides:                   mjpg_streamer.sh
#Default-Start:          2 3 4 5
#Default-Stop:          0 1 6
#Short-Description: mjpg_streamer for webcam
#Description:             Streams /dev/video0 and /dev/video1 to http://IP/?action=stream
###END INIT INFO

# Using the lsb functions to perform the operations.
./lib/lsb/init-functions
# Process name ( For display )
NAME=mjpg_streamer.sh
# Daemon name, where is the actual executable
DAEMON=/home/pi/mjpg-streamer/mjpg-streamer-experimental/
# pid file for the daemon
PIDFILE=/var/run/mjpg_streamer.pid

# If the daemon is not there, then exit.
test -x $DAEMON || exit 5

case $1 in
         start)
                  echo "Starting mjpg_streamer"
                  cd $DAEMON
                  sudo ./mjpg_streamer -i "./input_uvc.so" -o "./output_http.so -w ./www" &
                  sleep 2
                  echo "mjpg_streamer started"
                  ;;
         stop)
                  echo "Stopping mjpg_streamer..."
                  killall mjpg_streamer
                  echo "mjpg_streamer stopped"
                  ;;
         restart)
                  $0 stop && sleep 2 && $0 start
                  ;;
         status)
                 pid=`ps -A | grep mjpg_streamer | grep -v "grep" | grep -v mjpg_streamer. | awk '{print $1}' | head -n 1`
                 if [ -n "$pid" ];
                 then
                         echo "mjpg_streamer is running with pid ${pid}"
                         echo "mjpg_streamer was started with the following command line"
                         cat /proc/${pid}/cmdline ; echo ""
                 else
                         echo "Could not find mjpg_streamer running"
                 fi
                 ;;
         *)
                  echo "Usage: $0 {start|stop|restart|status}"
                  exit 2
                  ;;
esac

檔案新增完成後,要測試檔案是否能正常運作,輸入以下指令:

sudo sh ./mjpg-streamer.sh start

打開瀏覽器,測試 Mjpg-Streamer 是否能正常運作,如果能正常運作就代表 Shell 檔案設定完成。

複製相關檔案到系統目錄,並且變更權限 和 設定成開機自動啟動,只需要輸入以下指令:

sudo cp mjpg-streamer.sh /etc/init.d/mjpg-streamer.sh
sudo chmod +x /etc/init.d/mjpg-streamer.sh
sudo update-rc.d mjpg-streamer.sh defaults

已經完成設定!

可以重新開機試試看,是否開機後會自動運作。


標籤:   3D印表機、  Mjpg-Streamer、  OctoPi、  OctoPrint、  Raspberry Pi

我要留言