Register for the iXsystems Community to get an ad-free experience and exclusive discounts in our eBay Store.

MotionEye rc.d startup script (working manually but not on startup)

potatosword

Junior Member
Joined
Dec 30, 2018
Messages
22
So the rundown is that I've successfully installed MotionEye in an iocage running 11.2 but I can't get my startup script to work. I more or less followed this to get everything installed. This command must be issued in order to start the service:

meyectl startserver -b -c /etc/motioneye/motioneye.conf

I've created an rc.d script and chmod 755. The script runs manually via sh() just fine but does not seem to run at startup - which of course means something is going wrong with that process. I've placed copies of the script in both /etc/rc.d/ and /usr/local/etc/rc.d/.

Code:
#!/bin/sh

.   /etc/rc.subr

name=motioneye
rcvar=motioneye_enable
start_cmd="${name}_start"
stop_cmd=":"

load_rc_config $name

motioneye_start(){
    meyectl startserver -b -c /etc/motioneye/motioneye.conf
}

run_rc_command "$1" 


annoyingly, service -e gives me this output:

Code:
/etc/rc.d/cleanvar
/etc/rc.d/netif
/etc/rc.d/newsyslog
/etc/rc.d/syslogd
/etc/rc.d/virecover
/etc/rc.d/motd
/etc/rc.d/cron
/etc/rc.d/motioneye


I wish I had more verbose output from the jail as to what is going on. I'm sure I'm missing something trivial.
 
Last edited:

potatosword

Junior Member
Joined
Dec 30, 2018
Messages
22
I forgot to mention it but I've also ran sysrc motioneye_enable=YES which didn't do the trick. Is it possible rc.d scripts are running before python has started? (meyectl is a python script)
 
Last edited:

Jailer

Not strong, but bad
Joined
Sep 12, 2014
Messages
4,346
I don't know much about scripting but I got a service to start at jail startup in one of my jails by making a crontab entry in the jail you want the service to start. You use the command @Reboot and then add the path to your script so it would look something like:

Code:
@reboot /bin/sh /path/to/script
 

potatosword

Junior Member
Joined
Dec 30, 2018
Messages
22
I was curious about this approach so I tried it out but it didn't work for me. Below is what I entered into crontab -e - and yes I realize /bin/sh is pretty redundantly called out.

Code:
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
# Order of crontab fields
# minute hour mday month wday command

@reboot /bin/sh /etc/rc.d/motioneye


Curiously if I try to do service motioneye start I get eval: meyectl: not found which is really my first indication that it's not able to find the meyectl python script. Maybe I need to point to the exact path of meyectl?

Edit: pointed to the exact path of meyectl and now get this error instead (at least I'm making progress now and have error messages to work from!)

Code:
usage: meyectl startserver [-c CONFIG_FILE] [-d] [-h] [-l] [-v] [-b] meyectl startserver: error: argument -c: expected one argument eval: /etc/motioneye/motioneye.conf: Permission denied 


My guess is I need to chmod motioneye.conf.
 
Last edited:

Jurgen Segaert

Senior Member
Joined
Jul 10, 2016
Messages
346
The difference is the PATH. Best practice is to specify the full path in the rc.d script, instead of just meyectl do /full/path/to/meyectl.
You may also need to add a proper path in the motioneye_start command.
 

potatosword

Junior Member
Joined
Dec 30, 2018
Messages
22
Yeah I just updated this with the full path in motioneye_start() and ran chmod 755 on motioneye.conf. This is now the output:

Here is a copy of /etc/motioneye/motioneye.conf

It appears I had a typo in the startup script (nano added a space) that confused the -c argument. I'm now able to get it to start up automatically (and through service motioneye start) but once inside motioneye nothing really works. To troubleshoot this I tried echoing $USER out during the script. When I start via service montioneye start I get what appears to be NULL, and when I do a manual run of the script I get root. I presume I need some sort of daemon in the startup script?
 
Last edited:

potatosword

Junior Member
Joined
Dec 30, 2018
Messages
22
Alright everything is working smoothly now. This is now the script in /etc/rc.d

Code:
#!/bin/sh

.   /etc/rc.subr

name=motioneye
rcvar=motioneye_enable
start_cmd="${name}_start"
stop_cmd="${name}_stop"

load_rc_config $name

motioneye_start(){
    daemon -u root /usr/local/bin/meyectl startserver -b -c /etc/motioneye/motioneye.conf
}

motioneye_stop(){
    daemon -u root /usr/local/bin/meyectl stopserver -b -c /etc/motioneye/motioneye.conf
}

run_rc_command "$1" 
 
Top