Monthly Archives: February 2010

Linux – How to create Daemon Service

>Installation Part
1-Create a directory called /package
[root@testserver ~]# mkdir /package
2- Download Daemon tool on package directory
[root@testserver package]# wget -c http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
3-Download Daemon tools patch to avoid compile/svscan- “daemontools-0.76.errno.patch”
4) patch daemon tools-
(i) Go to ‘/package/admin/daemontools-0.76’ directory and run the following command
[root@testserver daemontools-0.76]# patch -p1 < ../daemontools-0.76.errno.patch (ii) Installing Daemon Tools – Go to ‘/package/admin/daemontools-0.76’ directory and run the following command [root@testserver daemontools-0.76]# package/install Implementation Part

1-Make sure /service/ directory is created with 755 permission
2- Create a folder where you would like to configure your daemon script linked with /service directory like /var/svc.d
3-Create a folder which indicates your Daemon service i.e /var/svc.d/nagios_check
4- create two folder and file as below
run ( file, permission must be 755 in order to execute )
log ( Folder )
env ( folder )
Further create a ‘run’ script inside ‘log’ directory to supervise daemon log with timestamp
The structure would like this.
[root@testserver svc.d]# tree

`– nagios_check
|– env
|– log
| `– run
`– run
5- create run file inside /var/svc.d/nagios-check like this
#!/bin/bash
exec 2>&1
echo “*** Starting service nagios_check…”
exec envdir ./env /root/admin/nagios_check.sh
Note – This will run /root/admin/nagios_check.sh as a deamon
6-create run file inside /var/svc/.d/nagios-check/log like this.
#!/bin/bash
exec multilog t ./main

Note –‘t’ feature with multilog with use for timpstamp of log files.
7- now create the softlink with /service folder to get daemon activiated.
i)-Go to /service directory and run the following commands
[root@testserver service]# ln -s /var/svc.d/nagios_check nagios_check
ii)- run the svc –t command to get /service recognized new deamon
iii) you can use svstat /service/* to see the daemon status like
[root@testserver ~]# svstat /service/*
/service/nagios-check: up (pid 6118) 1 seconds

Note- you can use ‘env’ directory to declare ENVIRNOMENT VARIABLE used inside script like /root/admin/nagios_check.sh for daemon purpose.

Advertisements

VMWare – Extending virtual disk in vmware workstation

>1) use
vmware-vdiskmanage
Suppose I need to grow Windows 2003 Server’s disk space upto 20GB from current 7 GB
Please follow the following steps–
1) Use ‘vmware-vdiskmanage’
i.e
C:Program FilesVMwareVMware Workstation>vmware-vdiskmanager.exe -x 20GB “c:Virtual MachinesWin2K3 ENTWindows Server 2003 Enterprise Edition.vmdk”
2)Download EXTPART utility ( Free) and installed it on Vmware Virtual Machine.
Boot the virtual machine, go to cmd prompt and run the extpart utility as below.

extpart.exe c: 20000

It will extend virtual disk to 20GB.

VMware – Recovering a deleted/lost .vmx file

>To recreate a deleted or lost .vmx file, follow the below steps:

1. Log into the ESX host as root.
2. Browse to the data store where the VM is residing.
3. Open the vmware.log file (cat vmware.log grep less).
4. Search for DICT entries in the file, these entries list the preferred setting and list which .vmx file was used.
5. Go to the section ‘configuration’ as highlighted below.
6. All entries between the ‘Configuration and ‘USER DEFAULTS’ section is part of VMX file.
7. Copy all the entries in this section to file and remove the time stamps in front of the line.
Dec 23 01:44:07.360: vmx DICT — COMMAND LINE
Dec 23 01:44:07.360: vmx DICT sched.group = host/user
Dec 23 01:44:07.360: vmx DICT — CONFIGURATION
Dec 23 01:44:07.360: vmx DICT config.version = 8
Dec 23 01:44:07.360: vmx DICT virtualHW.version = 4
Dec 23 01:44:07.360: vmx DICT floppy0.present = FALSE
Dec 23 01:44:07.360: vmx DICT nvram = Mail.nvram
Dec 23 01:44:07.360: vmx DICT powerType.powerOff = default
Dec 23 01:44:07.360: vmx DICT powerType.powerOn = default
Dec 23 01:44:07.360: vmx DICT powerType.suspend = default
Dec 23 01:44:07.360: vmx DICT powerType.reset = default
Dec 23 01:44:07.360: vmx DICT displayName = Mail
Dec 23 01:44:07.360: vmx DICT extendedConfigFile = Mail.vmxf
Dec 23 01:44:07.360: vmx DICT scsi0.present = TRUE
Dec 23 01:44:07.360: vmx DICT scsi0.sharedBus = none
Dec 23 01:44:07.360: vmx DICT memsize = 2048
Dec 23 01:44:07.360: vmx DICT scsi0:0.present = TRUE
Dec 23 01:44:07.360: vmx DICT scsi0:0.fileName = Mail-000002.vmdk
Dec 23 01:44:07.360: vmx DICT scsi0:0.deviceType = scsi-hardDisk
Dec 23 01:44:07.360: vmx DICT ide0:0.present = TRUE
Dec 23 01:44:07.360: vmx DICT ide0:0.fileName = /vmimages/ISO/windows 2003 r2 disk1.iso
Dec 23 01:44:07.360: vmx DICT ide0:0.deviceType = cdrom-image
Dec 23 01:44:07.360: vmx DICT floppy0.fileName = /dev/fd0
Dec 23 01:44:07.360: vmx DICT ethernet0.present = TRUE
Dec 23 01:44:07.360: vmx DICT ethernet0.startConnected = TRUE
Dec 23 01:44:07.360: vmx DICT ethernet0.wakeOnPcktRcv = FALSE
Dec 23 01:44:07.360: vmx DICT ethernet0.networkName = VM Network
Dec 23 01:44:07.360: vmx DICT ethernet0.addressType = generated
Dec 23 01:44:07.360: vmx DICT ethernet1.present = TRUE
Dec 23 01:44:07.360: vmx DICT ethernet1.startConnected = TRUE
Dec 23 01:44:07.360: vmx DICT ethernet1.wakeOnPcktRcv = FALSE
Dec 23 01:44:07.360: vmx DICT ethernet1.networkName = iSCSI
Dec 23 01:44:07.360: vmx DICT ethernet1.addressType = generated
Dec 23 01:44:07.360: vmx DICT usb.present = FALSE
Dec 23 01:44:07.360: vmx DICT serial0.present = FALSE
Dec 23 01:44:07.360: vmx DICT serial0.yieldOnMsrRead = true
Dec 23 01:44:07.360: vmx DICT serial0.fileName = /dev/ttyS0
Dec 23 01:44:07.360: vmx DICT serial1.present = FALSE
Dec 23 01:44:07.360: vmx DICT serial0.present = FALSE
Dec 23 01:44:07.360: vmx DICT serial0.yieldOnMsrRead = true
Dec 23 01:44:07.360: vmx DICT serial0.fileName = /dev/ttyS0
Dec 23 01:44:07.360: vmx DICT serial1.present = FALSE
Dec 23 01:44:07.360: vmx DICT serial1.yieldOnMsrRead = true
Dec 23 01:44:07.360: vmx DICT serial1.fileName = /dev/ttyS1
Dec 23 01:44:07.360: vmx DICT parallel0.present = FALSE
Dec 23 01:44:07.360: vmx DICT parallel0.fileName = /dev/parport0
Dec 23 01:44:07.360: vmx DICT parallel0.bidirectional = false
Dec 23 01:44:07.360: vmx DICT guestOS = win2000serv
Dec 23 01:44:07.360: vmx DICT sched.cpu.affinity = all
Dec 23 01:44:07.360: vmx DICT sched.mem.affinity = all
Dec 23 01:44:07.360: vmx DICT scsi0:0.redo =
Dec 23 01:44:07.360: vmx DICT ethernet0.generatedAddress = 00:0c:29:5c:71:db
Dec 23 01:44:07.360: vmx DICT ethernet1.generatedAddress = 00:0c:29:5c:71:e5
Dec 23 01:44:07.360: vmx DICT uuid.location = 56 4d 25 c0 c5 3e 01 fc-c6 87 49 2a b9 5c 71 db
Dec 23 01:44:07.360: vmx DICT uuid.bios = 56 4d 25 c0 c5 3e 01 fc-c6 87 49 2a b9 5c 71 db
Dec 23 01:44:07.360: vmx DICT sched.swap.derivedName = /vmfs/volumes/b4a92836-f7c59acd/Mail/Mail-7de70e31.vswp
Dec 23 01:44:07.360: vmx DICT ethernet0.generatedAddressOffset = 0
Dec 23 01:44:07.360: vmx DICT ethernet1.generatedAddressOffset = 10
Dec 23 01:44:07.360: vmx DICT tools.syncTime = FALSE
Dec 23 01:44:07.360: vmx DICT checkpoint.vmState.readOnly = FALSE
Dec 23 01:44:07.360: vmx DICT checkpoint.vmState =
Dec 23 01:44:07.360: vmx DICT scsi0:1.present = FALSE
Dec 23 01:44:07.360: vmx DICT scsi0:1.fileName = Mail_1.vmdk
Dec 23 01:44:07.360: vmx DICT scsi0:1.deviceType = scsi-hardDisk
Dec 23 01:44:07.360: vmx DICT scsi0:1.redo =
Dec 23 01:44:07.360: vmx DICT ide0:0.startConnected = TRUE
Dec 23 01:44:07.360: vmx DICT — USER DEFAULTS
Dec 23 01:44:07.360: vmx DICT — HOST DEFAULTS
Dec 23 01:44:07.360: vmx DICT libdir = /usr/lib/vmware
Dec 23 01:44:07.360: vmx DICT authd.fullpath = /usr/sbin/vmware-authd
Dec 23 01:44:07.360: vmx DICT authd.client.port = 902

After removing the time stamp the file should look like (warp the arguments in quotes):
config.version = “8”
virtualHW.version = “4”
floppy0.present = “false”
nvram = “Mail.nvram”
powerType.powerOff = “default”
powerType.powerOn = “default”
powerType.suspend = “default”
powerType.reset = “default”

displayName = “Mail”
extendedConfigFile = “Mail.vmxf”

scsi0.present = “true”
scsi0.sharedBus = “none”
memsize = “2048”
scsi0:0.present = “true”
scsi0:0.fileName = “Mail-000002.vmdk”
scsi0:0.deviceType = “scsi-hardDisk”
ide0:0.present = “true”
ide0:0.fileName = “/vmimages/ISO/windows 2003 r2 disk1.iso”

ide0:0.deviceType = “cdrom-image”
floppy0.fileName = “/dev/fd0”
ethernet0.present = “true”
ethernet0.startConnected = “true”
ethernet0.wakeOnPcktRcv = “false”
ethernet0.networkName = “VM Network”
ethernet0.addressType = “generated”
ethernet1.present = “true”
ethernet1.startConnected = “true”
ethernet1.wakeOnPcktRcv = “false”
ethernet1.networkName = “iSCSI”
ethernet1.addressType = “generated”
usb.present = “false”
serial0.present = “false”
serial0.yieldOnMsrRead = “true”
serial0.fileName = “/dev/ttyS0”
serial1.present = “false”
serial1.yieldOnMsrRead = “true”
serial1.fileName = “/dev/ttyS1”
parallel0.present = “false”
parallel0.fileName = “/dev/parport0”
parallel0.bidirectional = “false”
guestOS = “win2000serv”
sched.cpu.affinity = “all”
sched.mem.affinity = “all”

scsi0:0.redo = “”
ethernet0.generatedAddress = “00:0c:29:5c:71:db”
ethernet1.generatedAddress = “00:0c:29:5c:71:e5”
uuid.location = “56 4d 25 c0 c5 3e 01 fc-c6 87 49 2a b9 5c 71 db”
uuid.bios = “56 4d 25 c0 c5 3e 01 fc-c6 87 49 2a b9 5c 71 db”
sched.swap.derivedName = “/vmfs/volumes/b4a92836-f7c59acd/Mail/Mail-7de70e31.vswp”
ethernet0.generatedAddressOffset = “0”
ethernet1.generatedAddressOffset = “10”
tools.syncTime = “FALSE”

checkpoint.vmState.readOnly = “FALSE”
checkpoint.vmState = “”

scsi0:1.present = “false”
scsi0:1.fileName = “Mail_1.vmdk”
scsi0:1.deviceType = “scsi-hardDisk”
scsi0:1.redo = “”

ide0:0.startConnected = “true”