DAB Appliance Startup Scripts

apmuthu

Renowned Member
Feb 26, 2009
870
11
83
Chennai - India & Singapore
github.com
When we need to run a command immediately after a DAB built Appliance OpenVZ container has fully booted, where do we place it?

If we place it in /etc/init.d/ folder and symlink it into the rcX.d folders with update-rc.d command, it doesn't go well for some programs like stunnel4.

Using the update-rc.d stunnel4 defaults 20 (or 80) and booting the container and executing ps aux | grep stunnel4 we get:
Code:
# ps aux | grep stunnel4
stunnel4   711  0.0  0.0   3836   964 ?        Ss   11:27   0:00 /usr/bin/stunnel4 /etc/stunnel/stunnel.conf
root       810  0.0  0.0   1720   516 pts/0    S+   11:28   0:00 grep stunnel4
The port redirections do not work well.
If we then execute /etc/init.d/stunnel4 restart, the output of ps aux | grep stunnel4 is:
Code:
# ps aux | grep stunnel4
root       898  0.0  0.0   3716   644 pts/0    S    10:38   0:00 /usr/bin/stunnel4 /etc/stunnel/stunnel.conf
root       899  0.0  0.0   3716   408 pts/0    S    10:38   0:00 /usr/bin/stunnel4 /etc/stunnel/stunnel.conf
root       900  0.0  0.0   3716   408 pts/0    S    10:38   0:00 /usr/bin/stunnel4 /etc/stunnel/stunnel.conf
root       901  0.0  0.0   3716   408 pts/0    S    10:38   0:00 /usr/bin/stunnel4 /etc/stunnel/stunnel.conf
root       902  0.0  0.0   3716   408 pts/0    S    10:38   0:00 /usr/bin/stunnel4 /etc/stunnel/stunnel.conf
stunnel4   903  0.0  0.1   4068  2064 ?        Ss   10:38   0:00 /usr/bin/stunnel4 /etc/stunnel/stunnel.conf
root       933  0.0  0.0   1720   504 pts/0    R+   11:23   0:00 grep stunnel4
The port redirections now work as desired.
 
Last edited:
Re: DAB Appliance Startup Scripts - FIX

After reading the OpenVZ-Users-Guide.pdf (1.26 MB) at page 88 -
OpenVZ Action Scripts
OpenVZ allows you to automate procedures like the above by using [FONT=Times New Roman,Times New Roman][FONT=Times New Roman,Times New Roman]OpenVZ action scripts[/FONT][/FONT]. There are six action scripts defined in this version of OpenVZ:

global mount
This script runs immediately after [FONT=Courier New,Courier New][FONT=Courier New,Courier New]vzctl [/FONT][/FONT]mounts the VPS private area. The VPS itself is not yet running and the script is running in the Host OS context.
[FONT=Courier New,Courier New][FONT=Courier New,Courier New]mount[/FONT][/FONT]
This script runs immediately after the global mount script. The VPS is still not running, and the scripts is called in the Host OS context.
[FONT=Courier New,Courier New][FONT=Courier New,Courier New]start[/FONT][/FONT]
After [FONT=Courier New,Courier New][FONT=Courier New,Courier New]vzctl [/FONT][/FONT]has started a VPS, it runs the VPS [FONT=Courier New,Courier New][FONT=Courier New,Courier New]start [/FONT][/FONT]script. The script is running already in the VPS context.
[FONT=Courier New,Courier New][FONT=Courier New,Courier New]stop[/FONT][/FONT]
This script runs before the VPS is stopped, in the VPS context.
[FONT=Courier New,Courier New][FONT=Courier New,Courier New]umount[/FONT][/FONT]
After the VPS has been already stopped, the [FONT=Courier New,Courier New][FONT=Courier New,Courier New]umount [/FONT][/FONT]script is executed, and the script runs in the Host OS context.
global umount
This script runs when [FONT=Courier New,Courier New][FONT=Courier New,Courier New]vzctl [/FONT][/FONT]is about to dismount the VPS private area. It also runs in the Host OS context.
Thus, for example, for VPS 101 the action scripts will have names:
Code:
/etc/vz/conf/vps.mount
/etc/vz/conf/101.mount
/etc/vz/conf/101.start
/etc/vz/conf/101.stop
/etc/vz/conf/101.umount
/etc/vz/conf/vps.umount

The contents of the the start and stop files for my stunnel4 to work will be:
Code:
# cat /etc/vz/conf/101.start

#!/bin/bash
/etc/init.d/stunnel4 restart
 
# cat /etc/vz/conf/101.stop
 
#!/bin/bash
/etc/init.d/stunnel4 stop
The restart was used above instead of start in case it was already started prior to this script's execution.

Now a restart of the 101 container will have it humming nicely!