Cron job: curl inside a jail

Status
Not open for further replies.

ppmax

Contributor
Joined
May 16, 2012
Messages
111
Hi, N00b question here--

I installed curl inside a jail and want to run a cron job. Do I have to enter the jail to run curl, or can I execute curl with an absolute path to curl inside the jail?

thx
PP
 

ppmax

Contributor
Joined
May 16, 2012
Messages
111
Just a thread bump...

Anyone? Any suggestions? Running cron to something like wget or curl installed inside a jail can't be *that* rare. Is there a crontab inside the jail?

thx
PP
 

ProtoSD

MVP
Joined
Jul 1, 2011
Messages
3,348
You should be able to use a "jexec" command from cron outside the jail and make curl do something inside the jail. Do a man on "jexec".

Generally it's like this:

jexec Jail-ID Some-command-inside-jail

You can get the jail ID by doing "jls" outside the jail. The jail ID can change if you restart the jail or reboot, or it can be set to always be the same for a specific jail. I *think* this is the case with the Plugin jail.

-- Proto
 

ppmax

Contributor
Joined
May 16, 2012
Messages
111
Thanks for the reply Proto--much appreciated.

>>You can get the jail ID by doing "jls" outside the jail. The jail ID can change if you restart the jail or reboot, or it can be set to always be the same for a specific jail. I *think* this is the case with the Plugin jail.

This is the part that is hanging me up: the fact that the jail ID can change. Anecdotally I recall seeing my jail ID change from 1 to 2 on a reboot. How do you set this to a static value?

The way I set it up:
Create a cron job that points to a shell script
Shell script calls jexec 1 /usr/local/bin/curl...)

I have this all set up I just need to find out how to prevent the jail ID changing...or is there a method that I can call on the object that returns the jail ID?

thx--
PP
 

ppmax

Contributor
Joined
May 16, 2012
Messages
111
Replying to my own post...

After snooping around it seems that /var/run/jail_plugins.id holds the jail id value...

Needs to bone up on my shell scripting mojo so I can read this value from inside my shell script:

jexec [read /var/run/jail_plugins.id] /usr/local/bin/curl...

Other internets say that it's possible to execute jexec -n [jailname] [command]...how does one find the name of a jail? apparently it isn't the same as the hostname.
http://forums.freebsd.org/showthread.php?t=3178

thx
PP
 

ppmax

Contributor
Joined
May 16, 2012
Messages
111
SOLVED:

here is my cron
jexec `cat /var/run/jail_plugins.id` /root/ppcam-fetch.sh

ppcam-fetch.sh:
#!/bin/sh
/usr/local/bin/curl -s [my webcam ip] -o /mnt/media/Pictures/pcam/`date "+%Y-%m-%d_%H-%M-%S"`.jpg


Works like a charm. Thanks Proto for the tips
PP
 

ProtoSD

MVP
Joined
Jul 1, 2011
Messages
3,348
All the config stuff for the jail is setup in /etc/rc.conf or if you want to edit it so it persists /conf/base/etc/rc.conf.

The /var/run/jail-id value has the potential to be wrong if the jail didn't terminate properly.

So the line/variable you need to set in rc.conf looks like this:

jail_JAIL-NAME_flags="-n 1"


And you would need to change JAIL-NAME to whatever it's called, you'll see what it is. There are a bunch of lines that begin with "jail_***x="***x".


Sorry for the late reply, I'm far away at my hack-shack in the mountains with a slow mobile broadband connection ;)
 

ppmax

Contributor
Joined
May 16, 2012
Messages
111
>>Sorry for the late reply, I'm far away at my hack-shack in the mountains with a slow mobile broadband connection
No worries my friend! It's great that you reply ;)

I took a look at /conf/base/etc/rc.conf and I don't see anything about jails in that file. This makes sense since the presence of jails is not part of the base config. Are you saying I can add jail specific params to the base rc.conf file?

Interestingly, there is nothing in the /etc/rc.conf file that defines a jail name. I inquired about name vs. hostname on a BSD forum and was advised that these are indeed different and not synonymous. Heres what I see in mine:
Code:
jail_plugins_rootdir="/mnt/volume1/plugins_jail/plugins"
jail_plugins_hostname="plugins"
jail_plugins_ip="192.168.0.15"
jail_plugins_devfs_enable="YES"
jail_plugins_devfs_ruleset="devfsrules_jail"
jail_plugins_procfs_enable="YES"
jail_plugins_mount_enable="YES"
jail_sysvipc_allow="YES"
jail_list="plugins"
jail_enable="YES"


Originally I was thinking that I could use jexec -n and refer to the jail name instead of the JID, but since no name was set by default I opted for the cat /var/run/jail_plugins.id route.

Enjoy the mountains!

PP
 

ProtoSD

MVP
Joined
Jul 1, 2011
Messages
3,348
Ok, I'm back. I haven't looked at the rc.conf stuff before now for the plugin jail, but it looks like they name it "plugins". So you would add the line in your /conf/base/etc/rc.conf (do "mount -rw /" first):

jail_plugins_flags="-n 1"


I'm enjoying the peacefulness and uninterupted time I get to spend on the computer while listening to crickets and screaming out loud when I walk out the door at night and the glowing eyeballs of a deer are staring at me! ;)
 

ppmax

Contributor
Joined
May 16, 2012
Messages
111
Thanks Protosd--great idea.
 

sartoris

Cadet
Joined
Mar 9, 2014
Messages
1
I know that this is a couple years old, but just out of curiosity, have you tried used jexec JAILNAME cmd to avoid the changing JID problem?
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
This thread is from 2012. Locking the thread.
 
Status
Not open for further replies.
Top