How to specify directories in scripts in jail

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
I have a jail with some scripts. They get started with a Post-Init task. One script calls the next and so on. I would like to be able to run them via Post-Init task or locally in jail for troubleshooting.

I found in the Post-Init task, I had to call the script with the global path: /mnt/Ark/iocage/jails/jailname/root/****. Then apparently each reference to another script has to have the global path. But if I am in the jail testing, that path is no good; the scripts have to refer to another using ./ or start from the jail root.

In cron jobs, there seems to be a nice fix for this: the scripts use local paths, and the cron task calls the script with iocage exec <jailname> /path/from/jailroot/script.sh. But that doesn't work in Post-Init jobs, or I can't get it to.

Is there a way to do this?
 
Joined
Jan 7, 2015
Messages
1,150
You could use the cron directive @Reboot /path/script in the host and/or jails , basically the same thing. Not sure if this will do it for you or not
 

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
You could use the cron directive @Reboot /path/script in the host and/or jails , basically the same thing. Not sure if this will do it for you or not
Apparently can't do that through the GUI. I tried adding this line to /etc/crontab but not sure if that's the way to go, I'm a bit lost in manual cron stuff:
[USER=22614]@Reboot[/USER] sleep 120 && iocage exec transmission /pia/run_setup.sh

stupid forum insists on tagging the directive as a user
 

Jeremy MItchell

Dabbler
Joined
Oct 23, 2016
Messages
10
Looks like you're trying to start a PIA VPN when the jail starts?

I created a script that calls the PIA connection script (because I do other stuff when starting the jail too). The script and the PIA scripts are in a folder on the NAS that is in turn mounted in the jail.

Script looks like this:

Code:
#!/usr/local/bin/bash

#[do some stuff here]

# start the VPN with port forwarding
echo "Connecting to VPN"
cd /mnt/admin/pia/manual-connections-master
/mnt/admin/pia/manual-connections-master/get_region_and_token.sh

#[do some more stuff before exiting]


Then in root's crontab (so "crontab -e" as root inside the jail) I have this:

Code:
@reboot /mnt/admin/scripts/startup.sh


So whenever the jail is started or restarted, the startup.sh script is run, which in turn calls the PIA connection scripts and connects to the VPN.

Hope this helps.
 

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
That worked! I didn't know/think of running cron jobs inside the jail. That way the paths can be local to the jail, and as you say @Jeremy MItchell , it will run after restarting the jail as well as rebooting the machine. Thanks for the help.
 
Top