NzbDrone and FreeBSD/Freenas

Status
Not open for further replies.

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
This?
I have no idea how to read it, it's clearly meant to be parsed and filled in before use. I don't know how to interpret %%JAVA_CMD%% for instance.

yeah, cause when I build my port it gets parsed. %%JAVA_CMD%%=/usr/local/openjdkX/bin/java
I assume you would just have
Code:
command="/usr/local/bin/mono"
command_args="whatever.exe >$LOGFILE 2>&1 &"


The '>LOGFILE 2>&1 &' would redirect the errors and output to a logfile instead of the terminal

if you define a pidfile (which I see you already did), all of your functions (pre/post)start, (pre/post) stop, would be done by the subroutines that the init system provides.
 

tofagerl

Contributor
Joined
Aug 26, 2013
Messages
118
OK, I already did the logfile actually. I'll try it out. Thanks.

By the way, any idea how I get the logfile to rotate daily?
 

tofagerl

Contributor
Joined
Aug 26, 2013
Messages
118
Well, that worked really well, except now the pidfile isn't there, yet service status still works.
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
Well, that worked really well, except now the pidfile isn't there, yet service status still works.

hmm, actually now that i remember.. pidfile is only defined in your rc script. but it expects you program to actually create it. If you don't need a pidfile then don't define one. the init can figure our what process it is by looking at the user + command + command_args

EDIT
yup,looking at my subsonic script i don't define one. I do in most of my other sciprts cause the programs create their own pid, but with subsonic I just let the init figure it out.
 

tofagerl

Contributor
Joined
Aug 26, 2013
Messages
118
Right, I need it for monit, but I can edit the monit config so it finds the pid from ps and grep.
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
Right, I need it for monit, but I can edit the monit config so it finds the pid from ps and grep.

ahh, i see. maybe monit could ask the init file for the current status.
 

tofagerl

Contributor
Joined
Aug 26, 2013
Messages
118
Nah, it needs an actual pidfile as it turns out, so I would need to create a wrapper script, which would fuck up the rc script... Sigh...
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
Nah, it needs an actual pidfile as it turns out, so I would need to create a wrapper script, which would fuck up the rc script... Sigh...

i think you could just define the pidfile in a prestart command like you were doing before.
 

tofagerl

Contributor
Joined
Aug 26, 2013
Messages
118
Maybe, but can I create just the poststart, which I assume you meant, and not the start and stop commands? Hell, why ask, I'll just try it. Faster that way ;)
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
Maybe, but can I create just the poststart, which I assume you meant, and not the start and stop commands? Hell, why ask, I'll just try it. Faster that way ;)

yup, poststart is where it should go. was up way too late last night =P
I sometimes define prestart commands if a program can't deal with a stale pidfile on it's own.
 

tofagerl

Contributor
Joined
Aug 26, 2013
Messages
118
That works, except the poststop command doesn't delete the pidfile like I told it to.
Nevermind, I forgot to designate the stop_postcmd var.

Thanks a lot for your help, I'm about ready to publish this on the nzbdrone forum. here's the final file for your amusement:
Code:
#!/bin/sh
#
# PROVIDE: nzbdrone
# REQUIRE: NETWORKING SERVERS DAEMON ldconfig resolv
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# nzbdrone_enable (bool):    Set to NO by default.
#            Set it to YES to enable it.
# nzbdrone_data_dir:    Directory where nzbdrone configuration
#            data is stored.
#            Default: /home/${nzbdrone_user}/.config/NzbDrone
# nzbdrone_user:    The user account nzbdrone daemon runs as what
#            you want it to be. It uses 'nobody' user by
#            default. Do not sets it as empty or it will run
#            as root.
# nzbdrone_group:    The group account nzbdrone daemon runs as what
#            you want it to be. It uses 'user' group by
#            default. Do not sets it as empty or it will run
#            as wheel.
 
. /etc/rc.subr
name="nzbdrone"
rcvar="${name}_enable"
load_rc_config $name
start_postcmd="${name}_poststart"
pidfile="/var/run/${name}.pid"
stop_postcmd="${name}_poststop"
 
 
: ${nzbdrone_enable:="NO"}
: ${nzbdrone_user:="nobody"} #NOTE: DO NOT RUN AS ROOT, IT WILL BURN YOUR HOUSE DOWN AND RAPE YOUR CAT!
: ${nzbdrone_group:="user"}
: ${nzbdrone_dir:="/opt/NzbDrone"}
: ${nzbdrone_data_dir:="/home/${nzbdrone_user}/.config/NzbDrone"}
: ${nzbdrone_log:="/var/log/nzbdrone.log"}
 
command="/usr/local/bin/mono"
command_args="/opt/NzbDrone/NzbDrone.exe >$nzbdrone_log 2>&1 &"
nzbdrone_poststart()
{
        MONOSERVER_PID=$(ps ax | grep "NzbDrone.exe" | grep -v grep | awk '{print $1}')
        if [ -f $pidfile ]; then
                rm $pidfile
        fi
        if [ -n $MONOSERVER_PID ]; then
                echo $MONOSERVER_PID > $pidfile
        fi
}
nzbdrone_poststop()
{
        rm $pidfile
}
run_rc_command "$1"
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
That works, except the poststop command doesn't delete the pidfile like I told it to.
Code:
nzbdrone_poststop()
{
        rm $pidfile
}

mind posting what you currently have?
 

raidflex

Guru
Joined
Mar 14, 2012
Messages
531
Can you please post your final working script tofagerl. Thanks.

Edit: nvm found it on the NZBDRONE forums, thanks for the script!
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949

Looks good. Mind checking if my changes works

Changes I made
  • I simplified nzbdrone_poststart() to utlize a built in variable
  • no need deleting a stale pidfile then overwriting it. just overwriting it would do the same thing.
  • utilized nzbdrone_dir
Future changes
  • can you specify "nzbdrone_data_dir" as a commandline flag to nzbdrone? if so maybe we should specify it to something like /usr/local/etc/nzbdrone (but this directory would need to be owned by nzbdrone_user). otherwise the variable can be deleted, it's not being used.
  • if the above is implemented we might want to specify a user other than nobody to own the config files. it would need to either be a built in account, or people would need to add it. (though this is something a port maintainer would need to think about, not something that needs to be taken care of in this script)
Code:
#!/bin/sh
#
# PROVIDE: nzbdrone
# REQUIRE: NETWORKING SERVERS DAEMON ldconfig resolv
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# nzbdrone_enable (bool):    Set to NO by default.
#            Set it to YES to enable it.
# nzbdrone_data_dir:    Directory where nzbdrone configuration
#            data is stored.
#            Default: /home/${nzbdrone_user}/.config/NzbDrone
# nzbdrone_user:    The user account nzbdrone daemon runs as what
#            you want it to be. It uses 'nobody' user by
#            default. Do not sets it as empty or it will run
#            as root.
# nzbdrone_group:    The group account nzbdrone daemon runs as what
#            you want it to be. It uses 'user' group by
#            default. Do not sets it as empty or it will run
#            as wheel.
 
. /etc/rc.subr
name="nzbdrone"
rcvar="${name}_enable"
load_rc_config $name
start_postcmd="${name}_poststart"
pidfile="/var/run/${name}.pid"
stop_postcmd="${name}_poststop"
 
 
: ${nzbdrone_enable:="NO"}
: ${nzbdrone_user:="nobody"} #NOTE: DO NOT RUN AS ROOT, IT WILL BURN YOUR HOUSE DOWN AND RAPE YOUR CAT!
: ${nzbdrone_group:="user"}
: ${nzbdrone_dir:="/opt/NzbDrone"}
: ${nzbdrone_data_dir:="/home/${nzbdrone_user}/.config/NzbDrone"}
: ${nzbdrone_log:="/var/log/nzbdrone.log"}
 
command="/usr/local/bin/mono"
command_args="$nzbdrone_dir/NzbDrone.exe >$nzbdrone_log 2>&1 &"
nzbdrone_poststart()
{
        echo $rc_pid > $pidfile
}
nzbdrone_poststop()
{
        rm $pidfile
}
run_rc_command "$1"
 

raidflex

Guru
Joined
Mar 14, 2012
Messages
531
I cannot seem to get the service started with the script using any user except root. When I attempt to load the service it does not start. If I change the user to root in the rc script it will start. I have made sure that the user/group has been created and that the user has access to the NzbDrone folder/files. I am probably missing something obvious here, just not sure what.
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
I cannot seem to get the service started with the script using any user except root. When I attempt to load the service it does not start. If I change the user to root in the rc script it will start. I have made sure that the user/group has been created and that the user has access to the NzbDrone folder/files. I am probably missing something obvious here, just not sure what.
the user probably needs a home directory to create it's config directory. might be a possible issue.
 
Status
Not open for further replies.
Top