Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Configuring motion version 4.3.2-1ubuntu0.1 as a user process in Ubuntu 22.04. Commands and scripts refer to $USER (your login) and $HOME which is probably /home/$USER on your system.
- 1. Install motion.
- $ sudo apt install motion
- 2. Create a directory for motion config.
- $ mkdir 775 $HOME/motion
- 3. Create a directory for motion pictures and video.
- $ mkdir 700 $HOME/Dropbox
- 4. Stop the motion daemon.
- $ sudo systemctl stop motion.service
- 5. Prevent motion running automatically as a daemon.
- $ sudo systemctl disable motion.service
- 6. Create a config file in $HOME/motion/motion.conf. This is the config I use to record one image each second of motion at 640x480 resolution. Feel free to make your own config.
- ### start of motion.conf ###
- daemon off
- setup_mode off
- log_level 6
- target_dir $HOME/Dropbox
- # Video device (if you used /dev/video1 before, use /dev/video0 in this version of motion)
- videodevice /dev/video0
- width 640
- height 480
- framerate 1
- text_left CAMERA1
- text_right %Y-%m-%d\n%T
- emulate_motion off
- threshold 12000
- noise_level 32
- despeckle_filter EedDl
- minimum_motion_frames 1
- event_gap 2
- pre_capture 0
- post_capture 0
- picture_output on
- picture_filename %Y%m%d%H%M%S
- movie_output off
- webcontrol_port 8080
- webcontrol_localhost on
- webcontrol_parms 0
- ### end of motion.conf ###
- 7. Create a script to start motion process at $HOME/start_motion.sh.
- ### start of start_motion.sh ###
- #!/bin/bash
- IMGDIR=$HOME/Dropbox
- VARDIR=$HOME/motion
- PIDFILE=$VARDIR/motion.pid
- LOGFILE=$VARDIR/motion.log
- CONFIGFILE=$VARDIR/motion.conf
- if [ -f "$PIDFILE" ]; then
- pkill -F $PIDFILE
- sleep 1
- rm $PIDFILE
- fi
- if [ ! -d "$VARDIR" ]; then
- mkdir 775 $VARDIR
- fi
- if [ ! -f "$CONFIGFILE" ]; then
- echo "Config file not found."
- exit 1
- fi
- if [ ! -d "$IMGDIR" ]; then
- mkdir 700 $IMGDIR
- fi
- if [ -f "$LOGFILE" ]; then
- rm $LOGFILE
- fi
- /usr/bin/motion -b -c $CONFIGFILE -p $PIDFILE -l $LOGFILE
- ### end of start_motion.sh ###
- 8. Create a script to stop motion process at $HOME/stop_motion.sh.
- ### start of stop_motion.sh ###
- #!/bin/bash
- PIDFILE=$HOME/motion/motion.pid
- if [ ! -f "$PIDFILE" ]; then
- echo "Not running."
- exit 1
- fi
- pkill -F $PIDFILE
- sleep 1
- rm $PIDFILE
- ### end of stop_motion.sh ###
- 9. Create a script to restart motion process at $HOME/restart_motion.sh.
- ### start of restart_motion.sh ###
- #!/bin/bash
- $HOME/stop_motion.sh
- $HOME/start_motion.sh
- ### end of restart_motion.sh ###
- 10. Make the scripts executable.
- $ chmod +x $HOME/start_motion.sh
- $ chmod +x $HOME/stop_motion.sh
- $ chmod +x $HOME/restart_motion.sh
- 11. Add your user to the 'video' group.
- $ sudo usermod -a -G video $USER
- 12. Create a startup entry for motion.
- 12.1. Run 'Startup Applications' from the menu.
- 12.2. Add a program 'Motion' with command '$HOME/start_motion.sh' and delay 5.
- 13. Start the motion application now. Test your pictures are saved to $HOME/Dropbox. If they are not, motion is being stubborn. Restart the process with $HOME/restart_motion.sh.
- @version 1.1
Advertisement
Comments
-
- Changes in v1.1:
- - Uses systemctl to stop and disable the daemon. To reverse the steps in v1.0:
- $ sudo chown root:root $HOME/motion/motion.service
- $ sudo mv $HOME/motion/motion.service /lib/systemd/system/
Add Comment
Please, Sign In to add comment
Advertisement