SOLVED Run command at iocage jail startup

bodriye

Explorer
Joined
Mar 27, 2016
Messages
82
Hi I am trying to run following command at jail startup /usr/local/bin/flexget daemon start -d
I have tried adding a Init/Shutdown Script with sleep delay with no luck. iocage exec flexget /usr/local/bin/flexget daemon start -d
I have also tried adding crontab task in jail @Reboot with no luck.

Is there a way to run a command as soon as jail starts?

Thanks.
 

bodriye

Explorer
Joined
Mar 27, 2016
Messages
82
Code:
#!/bin/sh

. /etc/rc.subr

name=flexgetd
rcvar=flexgetd_enable

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

load_rc_config $name

flexgetd_start()
{
		/usr/local/bin/flexget -c /root/.flexget/config.yml daemon start -d
}

run_rc_command "$1"


works for me
 
Last edited:

bodriye

Explorer
Joined
Mar 27, 2016
Messages
82
And just in case anyone wants flexget iocage:
change the ip addresses in <>

echo '{"pkgs":["py27-flexget","ca_root_nss","py27-transmissionrpc"]}' > /tmp/pkg.json
iocage create -n "flexget" -p /tmp/pkg.json -r 11.1-RELEASE ip4_addr="vnet0|<jail ip address>/<mask>" defaultrouter="<router address>" vnet="on" allow_raw_sockets="1" boot="on"
rm /tmp/pkg.json
iocage fstab -a flexget /mnt/pepper/apps/flexget /root/.flexget nullfs rw 0 0


example
echo '{"pkgs":["py27-flexget","ca_root_nss","py27-transmissionrpc"]}' > /tmp/pkg.json
iocage create -n "flexget" -p /tmp/pkg.json -r 11.1-RELEASE ip4_addr="vnet0|10.10.100.53/24" defaultrouter="10.10.100.1" vnet="on" allow_raw_sockets="1" boot="on"
rm /tmp/pkg.json
iocage fstab -a flexget /mnt/pepper/apps/flexget /root/.flexget nullfs rw 0 0


and if you want latest updates when you do pkg update && pkg upgrade
iocage exec flexget "mkdir -p /usr/local/etc/pkg/repos"
iocage exec flexget "vi /usr/local/etc/pkg/repos/FreeBSD.conf"


and enter following repo info:
Code:
FreeBSD: {
	url: "pkg+http://pkg.FreeBSD.org/${ABI}/latest"
}


and obviously iocage currently has networking issues so follow instructions on the forums for workarounds.
 
Joined
May 2, 2017
Messages
211
Code:
#!/bin/sh

. /etc/rc.subr

name=flexgetd
rcvar=flexgetd_enable

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

load_rc_config $name

flexgetd_start()
{
        /usr/local/bin/flexget -c /root/.flexget/config.yml daemon start -d
}

run_rc_command "$1"


works for me

Good afternoon,

I'd really appreciate if you could walk a newbie through the exact same thing... I need to properly run the following command at the start of my iocage jail so Home Assistant starts at boot and stays running...

/usr/local/bin/hass --open-ui --config /mnt/hass

Currently, I have all working fine if I open the shell of the jail, and run the command manually. But of course, as soon as I close the shell, the service stops and Home Assistant stops with it.

Can you help with modifying your solution and tell me where to put it? I want to do this right.

Thanks!
 

bodriye

Explorer
Joined
Mar 27, 2016
Messages
82
Good afternoon,

I'd really appreciate if you could walk a newbie through the exact same thing... I need to properly run the following command at the start of my iocage jail so Home Assistant starts at boot and stays running...

/usr/local/bin/hass --open-ui --config /mnt/hass

Currently, I have all working fine if I open the shell of the jail, and run the command manually. But of course, as soon as I close the shell, the service stops and Home Assistant stops with it.

Can you help with modifying your solution and tell me where to put it? I want to do this right.

Thanks!

If you add a ampersand sign to the end of any command you send it to the background.
To bring it back to the foreground you can use fg command.
For Example:
/usr/local/bin/hass --open-ui --config /mnt/hass &

But that won't really help if the shell is closed. There are couple of programs that can help with this.
I personally use program called screen you can install it like any normal freebsd package in the jail.
After you have screen installed run the command like this:
screen -d -m /usr/local/bin/hass --open-ui --config /mnt/hass
This will run the command (-m) in screen in detached (-d) mode.

To list running screen sessions run: screen -ls
To reattach one of those sessions run: screen -r <process id number that screen -ls command shows>

More info on screen:
https://linuxize.com/post/how-to-use-linux-screen/

One more thing, I see that hass has daemon mode (same mode i run my flexget instance above), so you can skip the installing screen and run command like this:

/usr/local/bin/hass --open-ui --config /mnt/hass --daemon

For your startup script you can try this startup script:
Code:
#!/bin/sh

. /etc/rc.subr

name=hassd
rcvar=hassd_enable

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

load_rc_config $name

hassd_start()
{
        /usr/local/bin/hass --open-ui --config /mnt/hass --daemon
}

run_rc_command "$1"


1) Make a file named hassd in /etc/rc.d directory and add the script above

2) Now you edit /etc/rc.conf and add hassd_enable="YES" line to the file.

3) Restart the jail
 
Joined
May 2, 2017
Messages
211
If you add a ampersand sign to the end of any command you send it to the background.
To bring it back to the foreground you can use fg command.
For Example:
/usr/local/bin/hass --open-ui --config /mnt/hass &

But that won't really help if the shell is closed. There are couple of programs that can help with this.
I personally use program called screen you can install it like any normal freebsd package in the jail.
After you have screen installed run the command like this:
screen -d -m /usr/local/bin/hass --open-ui --config /mnt/hass
This will run the command (-m) in screen in detached (-d) mode.

To list running screen sessions run: screen -ls
To reattach one of those sessions run: screen -r <process id number that screen -ls command shows>

More info on screen:
https://linuxize.com/post/how-to-use-linux-screen/

One more thing, I see that hass has daemon mode (same mode i run my flexget instance above), so you can skip the installing screen and run command like this:

/usr/local/bin/hass --open-ui --config /mnt/hass --daemon

For your startup script you can try this startup script:
Code:
#!/bin/sh

. /etc/rc.subr

name=hassd
rcvar=hassd_enable

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

load_rc_config $name

hassd_start()
{
        /usr/local/bin/hass --open-ui --config /mnt/hass --daemon
}

run_rc_command "$1"


1) Make a file named hassd in /etc/rc.d directory and add the script above

2) Now you edit /etc/rc.conf and add hassd_enable="YES" line to the file.

3) Restart the jail


Thank you so much! I'll get on this now and let you know how it goes!
 
Joined
May 2, 2017
Messages
211
No go. Did all that, and it doesn't run at startup... How do I see what's going wrong?

I went the route of the script and rc.conf.
 

bodriye

Explorer
Joined
Mar 27, 2016
Messages
82
No go. Did all that, and it doesn't run at startup... How do I see what's going wrong?

I went the route of the script and rc.conf.
Try running the command /usr/local/bin/hass --open-ui --config /mnt/hass --daemon and see what happens
 
Joined
May 2, 2017
Messages
211
It starts fine. I tested that before I did the script. And that's how I started it after it didn't go automatically. Works fine, just doesn't autostart.
 
Joined
May 2, 2017
Messages
211
I get "Permission denied"...
 
Joined
May 2, 2017
Messages
211
Outstanding!!

I really appreciate the help you've given me. Once I get all these things sorted out, I'm going to compile a reference document on how to set this up. It's the least I can do for all the help others have provided. I've got some other issues to work out, but I'll cross those bridges when I get there...

Thanks a million!
 
Top