iocage startup script

dknm

Dabbler
Joined
Aug 27, 2018
Messages
25
I'm trying to setup a startup script to run two lines I currently do manually inside the jail

source ~/py3-venv-pgadmin/bin/activate.csh python3 ~/py3-venv-pgadmin/lib/python3.6/site-packages/pgadmin4/pgAdmin4.py &

I looked at a few resources, namely
https://www.freebsd.org/doc/en_US.ISO8859-1/articles/rc-scripting/rcng-daemon-adv.html
https://forums.freenas.org/index.php?threads/run-command-at-iocage-jail-startup.61819/

And saw 2 formatting styles, tried both - looking like so:
attempt #1
Code:
#!/bin/sh
#
#
#
. /etc/rc.subr

name="pgadmin4-daemon"
rcvar="${name}_enable"

load_rc_config ${name}

pidfile="/var/run/pgadmin4-daemon.pid"

command="source ~/py3-venv-pgadmin/bin/activate.csh"
command_args="python3 ~/py3-venv-pgadmin/lib/python3.6/site-packages/pgadmin4/pgAdmin4.py &"

run_rc_command "$1"

#attempt 2
Code:
#!/bin/sh
#
#
. /etc/rc.subr

name="pgadmin4-daemon"
rcvar="${name}_enable"

start_cmd="${name}_start"
stop_cmd=":"

load_rc_config $name

pgadmin4-daemon_start()
{
    source ~/py3-venv-pgadmin/bin/activate.csh
    python3 ~/py3-venv-pgadmin/lib/python3.6/site-packages/pgadmin4/pgAdmin4.py &
}

run_rc_command "$1"


And then:

echo 'pgadmin4-daemon_enable="YES"' >> /etc/rc.conf
chmod +x /etc/rc.d/pgadmin4-daemon

Either way, it errors with

Code:
service pgadmin4-daemon start
/etc/rc.conf: pgadmin4-daemon_enable=YES: not found
/etc/rc.conf: pgadmin4-daemon_enable=YES: not found
/etc/rc.d/pgadmin4-daemon: WARNING: $pgadmin4-daemon_enable is not set properly - see rc.conf(5).
Cannot 'start' pgadmin4-daemon. Set pgadmin4-daemon_enable to YES in /etc/rc.conf or use 'onestart' instead of 'start'.


Is the syntax I'm getting wrong or something else entirely?
 

nojohnny101

Wizard
Joined
Dec 3, 2015
Messages
1,478
You have to do as it says and enable pgadmin4 to Yes...similiar to this:
iocage exec tautulli sysrc "tautulli_enable=YES" (for my iocage jail that runs tautulli)

I also had to execute these two statements to get my tautulli jail working:
iocage exec tautulli cp /usr/local/share/Tautulli/init-scripts/init.freenas /usr/local/etc/rc.d/tautulli
iocage exec tautulli chmod u+x /usr/local/etc/rc.d/tautulli

credit goes to this tutorial: https://forums.freenas.org/index.ph...darr-lidarr-jackett-transmission-organizr.58/

Hope this helps.
 

dknm

Dabbler
Joined
Aug 27, 2018
Messages
25

Thank you for the resource. I did some digging and found the script the plugin relies on, with the intent of then adapting it.
Also had a look in this thread and my understanding is you don't need to create pid / status / stop variables explicitly.
My script (usr/local/etc/rc.d/pgadmin) then became

Code:
#!/bin/sh
#
. /etc/rc.subr

name="pgadmin"
rcvar=${name}_enable

load_rc_config ${name}
: ${pgadmin_enable:="NO"}
: ${pgadmin_user:="root"}
: ${pgadmin_dir:="/root/py3-venv-pgadmin/lib/python3.6/site-packages/pgadmin4/"}


. /root/py3-venv-pgadmin/bin/activate

python3 /root/py3-venv-pgadmin/lib/python3.6/site-packages/pgadmin4/pgAdmin4.py &


With this I can run service pgadmin start and it works (I can't do service status or stop though, either will attempt to start a new instance).

It won't however run on startup. (Made it executable and added sysrc pgadmin_enable="YES" ).

Running either lines with command= in front returns permission denied. Probably has something to do with this changing the shell agent from root -> python

Code:
root@postgresql:~ # service pgadmin start
/usr/local/etc/rc.d/pgadmin: /root/py3-venv-pgadmin/bin/activate: Permission denied
/usr/local/etc/rc.d/pgadmin: python3: not found
/usr/local/etc/rc.d/pgadmin: WARNING: run_rc_command: cannot run 


So, I'm a bit closer but don't know how to go further. Could I get a sense check / feedback please?
 
Last edited:

isparks6

Cadet
Joined
Jun 27, 2019
Messages
2
Hi, did you have any luck figuring it out? I'm running into a similar problem, trying to do the same thing. I want to run pgAdmin in the background as a daemon when my jail starts. Here's my script:


Code:
#!/bin/sh

# PROVIDE: pgAdminActivate

. /etc/rc.subr
. /root/pgadmin4/bin/activate

name="pgAdminActivate"
rcvar=`set_rcvar`
start_cmd="${name}_start"
stop_cmd=":"

load rc_config $name

pgAdminActivate_start()
{
    python /root/pgadmin4/lib/python2.7/site-packages/pgadmin4/pgAdmin4.py
}

run_rc_command "$1"


I can force it to run using onestart, but whenever I try to simply start the script I get the following error:

Code:
./pgAdminActivate: load: not found
./pgAdminActivate: WARNING: $pgAdminActivate_enable is not set properly - see rc.conf(5)
Cannot 'start' pgAdminActivate. Set pgAdminActivate_enable to YES in /etc/rc.vonf or use 'onestart' instead of 'start'


I have run the command
Code:
sysrc pgAdminActivate_enable=YES
and have confirmed that that line is in /etc/rc.conf. The script has execute permissions. Not sure where to go from here.
 

isparks6

Cadet
Joined
Jun 27, 2019
Messages
2
I figured out the problem on my end. The line load rc_config ${name} should be load_rc_config ${name}. Got caught on the underscore. After fixing that, everything worked as expected!
 
Top