Solved How to run command on startup?

Hi
I have remote access with ssh in my server. I also have this command that I need to run on startup
uwsgi --emperor /usr/local/etc/uwsgi/vassals/ --uid www --gid www
and I am trying to find a way to run it automatically on start up.
Unfortunately it doesn't run. What I tried so far:

I created a file /etc/rc.local with
Code:
#!/bin/sh
uwsgi --emperor /usr/local/etc/uwsgi/vassals/ --uid www --gid www
and chmoded it to 755. Doesn't work

I created the file /usr/local/etc/rc.d/qssite with content

Code:
#!/bin/sh

# PROVIDE: qssite

. /etc/rc.subr

name="qssite"
start_cmd="${name}_start"
stop_cmd="${name}_stop"

qssite_start() {
   echo "qssite starting"
   # your commands here
   uwsgi --emperor /usr/local/etc/uwsgi/vassals/ --uid www --gid www
}

qssite_stop() {
   echo "qssite stopping"
   # your commands here
}

run_rc_command "$1"

# eof
chmoded to +x and even added to /etc/rc.conf:
Code:
qssite_enable="YES"
Still doesn't start on boot.

If I do sudo /usr/local/etc/rc.d/qssite start it works. But I want it to run automatically on boot.
 
Try putting the full path to the uwsgi program in your scripts. Any rc/cron script should be using the full path for all executables. Not that I'm guaranteeing it'll fix your problem but it's extremely bad practice to not use full paths in scripts. You can never be sure that rc or cron or whatever is going to look in the same places for executables that the system does when you run scripts manually.
 
Thanks. I totally overlooked this. Also it needed an ampersand in the end of the command so it can go in the background. Now it works and life is beautiful again :)
 
Back
Top