Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm facing an issue with a python file that I'd like to start as a service. I named my service ocrserver and the script I want to start is in /home/administrator/ocr/ocrserver/init.py with some parameters added like --address --port etc... After reading the documentation from the FreeBSD site

I wrote the following script:

#!/bin/sh

# $FreeBSD$
#
# PROVIDE: ocrserver 
# REQUIRE: NETWORK
# KEYWORD: shutdown

# add the following line to /etc/rc.conf to enable the ocrserver:
# ocrserver_enable="YES"

. /etc/rc.subr

name="ocrserver"
rcvar="ocrserver_enable"

# default values
: ${ocrserver_enable="NO"}

base_path="/home/administrator/ocr/ocrserver"

address="localhost"
http_port=8080
pyproxy_port=10800

log_level="debug"

pidfile="${base_path}/ocrserver.pid"

command="/usr/sbin/daemon"

# -p : daemon handler pidfile
# -f : redirect stdout and stderr to /dev/null
# -c : change working dir to root
command_args="-p ${pidfile} -f -c /home/administrator/ocr/ocrserver/__init__.py \
--address ${address} --http-port ${http_port} --log-level ${log_level} \
--pyproxy-port ${pyproxy_port}"

procname="/home/administrator/ocr/ocrserver/__init__.py"
command_interpreter="/usr/local/bin/python3.3"

load_rc_config $name
run_rc_command "$1"

Then I added one line setting up the corresponding rcvar to YES in the /etc/rc.conf file. and I launched it:

sudo service ocrserver start where I get the message "Starting ocrserver". and after entering a sudo service ocrserver status, I can see that the service is not running. I also ran a pgrep -l python3.3 command to see if any python3 process was running but no result

I precise that I did a chmod 755 on the file to make it readable and executable by all the users.

Has anyone some experience with this kind of thing?

Thanks for your answers.

share|improve this question
1  
running __init__.py as a script is probably an error. You could put the main() part from __init__.py into __main__.py and try to run it as python3.3 -mocrserver (/home/administrator/ocr/ should be in Python path in this case (python3.3 -c 'import sys; print("\n".join(sys.path))')). –  J.F. Sebastian Nov 2 '13 at 6:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.