How do I set up motion package to "autostart" and use proper config file which is /etc/config/motion?

I am struggling with motion package. Sometimes it works sometimes it does not. Now I try to "autostart" it with following parameters:

/etc/init.d/motion

root@OpenWrt:/etc/init.d$ cat /etc/init.d/motion
#!/bin/sh /etc/rc.common

START=94
USE_PROCD=1

PROG="/usr/bin/motion"
CONF="/etc/motion"

start_service() {
        local enabled

        config_load "motion"
        config_get_bool enabled "general" "enabled" 0
        [ "$enabled" -gt 0 ] || return 1

        procd_open_instance

        procd_set_param command "$PROG"
        procd_append_param command -c "$CONF"

        procd_close_instance
}

/etc/config/motion

root@OpenWrt:/etc/init.d$ cat /etc/config/motion
# Rename this distribution example file to motion.conf
#
# This config file was generated by motion 4.5.0
# Documentation:  /usr/share/doc/motion/motion_guide.html
#
# This file contains only the basic configuration options to get a
# system working.  There are many more options available.  Please
# consult the documentation for the complete list of all options.
#

############################################################
# System control configuration parameters
############################################################

# Start in daemon (background) mode and release terminal.
daemon off

# Start in Setup-Mode, daemon disabled.
setup_mode off

# File to store the process ID.
; pid_file value

# File to write logs messages into.  If not defined stderr and syslog is used.
; log_file value

# Level of log messages [1..9] (EMG, ALR, CRT, ERR, WRN, NTC, INF, DBG, ALL).
log_level 6

# Target directory for pictures, snapshots and movies
; target_dir /tmp/motionfiles

# Video device (e.g. /dev/video0) to be used for capturing.
video_device /dev/video0

# Parameters to control video device.  See motion_guide.html
; video_params value

# The full URL of the network camera stream.
; netcam_url value

# Name of mmal camera (e.g. vc.ril.camera for pi camera).
; mmalcam_name value

# Camera control parameters (see raspivid/raspistill tool documentation)
; mmalcam_params value

############################################################
# Image Processing configuration parameters
############################################################

# Image width in pixels.
width 640

# Image height in pixels.
height 480

# Maximum number of frames to be captured per second.
framerate 15

# Text to be overlayed in the lower left corner of images
text_left CAMERA1

# Text to be overlayed in the lower right corner of images.
text_right %Y-%m-%d\n%T-%q

############################################################
# Motion detection configuration parameters
############################################################

# Always save pictures and movies even if there was no motion.
emulate_motion off

# Threshold for number of changed pixels that triggers motion.
threshold 1500

# Noise threshold for the motion detection.
; noise_level 32

# Despeckle the image using (E/e)rode or (D/d)ilate or (l)abel.
despeckle_filter EedDl

# Number of images that must contain motion to trigger an event.
minimum_motion_frames 1

# Gap in seconds of no motion detected that triggers the end of an event.
event_gap 60

# The number of pre-captured (buffered) pictures from before motion.
pre_capture 3

# Number of frames to capture after motion is no longer detected.
post_capture 0

############################################################
# Script execution configuration parameters
############################################################

# Command to be executed when an event starts.
; on_event_start value

# Command to be executed when an event ends.
; on_event_end value

# Command to be executed when a movie file is closed.
; on_movie_end value

############################################################
# Picture output configuration parameters
############################################################

# Output pictures when motion is detected
picture_output on

# File name(without extension) for pictures relative to target directory
picture_filename %Y%m%d%H%M%S-%q

############################################################
# Movie output configuration parameters
############################################################

# Create movies of motion events.
movie_output on

# Maximum length of movie in seconds.
movie_max_time 60

# The encoding quality of the movie. (0=use bitrate. 1=worst quality, 100=best)
movie_quality 45

# Container/Codec to used for the movie. See motion_guide.html
movie_codec mkv

# File name(without extension) for movies relative to target directory
movie_filename %t-%v-%Y%m%d%H%M%S

############################################################
# Webcontrol configuration parameters
############################################################

# Port number used for the webcontrol.
webcontrol_port 8080

# Restrict webcontrol connections to the localhost.
webcontrol_localhost off

# Type of configuration options to allow via the webcontrol.
webcontrol_parms 0

############################################################
# Live stream configuration parameters
############################################################

# The port number for the live stream.
stream_port 8081

# Restrict stream connections to the localhost.
stream_localhost off

##############################################################
# Camera config files - One for each camera.
##############################################################
; camera /usr/etc/motion/camera1.conf
; camera /usr/etc/motion/camera2.conf
; camera /usr/etc/motion/camera3.conf
; camera /usr/etc/motion/camera4.conf

##############################################################
# Directory to read '.conf' files for cameras.
##############################################################
; camera_dir /usr/etc/motion/conf.d
root@OpenWrt:/etc/init.d$

But it does not work. When I

service motion status

I recive

active with no instances

It only works properly if I start it manually, and strictly specify config file like

motion -c /etc/config/motion

And even in this case it ignores specified directory for *.jpg files and write files to /etc/config directory

I would be very grateful for any help

There's an enabled 0 somewhere.

I used

/etc/init.d/motion enable

to set "autostart" but it seems it does not work?

I figured out that I have to change somehow --sysconfdir=DIR according to

If Motion was invoked with command line option -c pathname Motion will expect the config file to be as specified. When you specify the config file on the command line with -c you can call it anything.If you do not specify -c or the filename you give Motion does not exist, Motion will search for the configuration file called 'motion.conf' in the following order: 1. Current directory from where motion was invoked*

    1. Then in a directory called '.motion' in the current users home directory (shell environment variable $HOME). E.g. /home/goofy/.motion/motion.conf*
    1. The directory defined by the --sysconfdir=DIR when running .configure during installation of Motion*
      *(If this option was not defined the default is /etc/motion)
      https://motion-project.github.io/motion_config.html#Basic_Setup

But I see no such option in any motion config file
May be, by default it runs in setup mode, and I neet to specify in motion.conf to run as daemon?

Because of the line I pasted earlier...

Yeah, too bad you don't have a 4 week memory span.

You're quite toxic, you know that?
My concern is why

/etc/init.d/motion enable 

does not work? motion enabled in motion.conf but since it can not read its config file there is no point in that. The problem is how to make it read proper config file as I understand.

I try your solution, thanks anyway.

UPD: It seems I understand the perplexity of complexity of this stuff, yet the purpose of this shift from my understanding.
File /etc/config/motion is NOT a motion package config file. It is config file for luci or uci, for that matter, which just says that motion package enabled. And nothing more.
So there is no point in editing it in attempt to setup motion package. Cause uci can not read this file without errors, cause uci expects uci-formatted config file and certainly can not understand motion config file. OMG.
And the motion package itself, when enabled, searches for its config file in its root default directory for there is no way in OpenWRT to setup this sysconfdir. wtf...
I am correct?

P.S. This ideology "everything is a file" would be great if these files were not blown out around all over the system like "sapper mistake" meat salad. Well. I hope I do not insult anyone, since only person who read my messages is mister high standards.

UPD2-FINAL: OK. I admit that I am dumb, or, well, at least kind of short-sighted
The thing is that /etc/config/motion as I mentioned do not store config for motion itself. It store config for uci, which is

config motion general
        option enabled '0'

and should be set to '1' of course. I could have guessed that simply by looking at syntax which is typically UCI style, and definitely not motion style.

Then, motion config itself by default is stored in /etc/motion.conf (A clever decision since any nix system has /etc directory) and the thing is that you can change config file location by editing /etc/init.d/motion if you want that.

#!/bin/sh /etc/rc.common

START=94
USE_PROCD=1

PROG="/usr/bin/motion"
CONF="/etc/motion.conf"

start_service() {
        local enabled

        config_load "motion"
        config_get_bool enabled "general" "enabled" 0
        [ "$enabled" -gt 0 ] || return 1

        procd_open_instance

        procd_set_param command "$PROG"
        procd_append_param command -c "$CONF"

        procd_close_instance
}

As anyone can clearly see looking at line CONF. Well, I did not pay much attention to this, or, may be just forgot about that, as usual.

Btw, there is no need to change anything in this file, though, if you want to "autostart" motion. Simple command

service motion enable

or

/etc/init.d/motion enable

is enough.

You can make sure that motion is set to "autostart" by looking at System - > Startup in Web-admin panel of your OpenWRT device.

Well, everything works fine now. I need to set up several cameras and let motion through router to WWW, to be able to see what is going on when I am not at home.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.