Creating services for Linux with systemd

Posted in Unix on October 15th, 2012 by phoenixdigital

Setting up services to start on boot is pretty straight forward.

You will need to create a service file in /lib/systemd/system/
vi /lib/systemd/system/your-service-name.service

then create a symbolic link for this file to /etc/systemd/system/
ln -s /lib/systemd/system/your-service-name.service /etc/systemd/system/your-service-name.service

Use the following command to reload any changes
systemctl daemon-reload

This command to start your service
systemctl start your-service-name.service

This command to enable your service on boot
systemctl enable your-service-name.service

If you run into any issues check /var/log/messages for any errors
tail /var/log/messages

Two example service files

[Unit]
Description=Polling weather station for live weather data
After=syslog.target network.target

[Service]
User=phoenix
Type=simple
ExecStart=/home/phoenix/weather/data/start.sh
KillSignal=SIGHUP

[Install]
WantedBy=multi-user.target

or

[Unit]
Description=PyTivo streaming service
After=syslog.target network.target

[Service]
Type=simple
ExecStart=/var/lib/pytivo/pyTivo.py

[Install]
WantedBy=multi-user.target

Ref: http://kezhong.wordpress.com/2011/11/19/creating-my-own-systemd-service-files-on-fedora-16x86_64/

Find new HDD and partition and format

Posted in Unix on July 29th, 2012 by phoenixdigital

List all partitions
cat /proc/partitions

List all lvm partitions
dmsetup ls
pvdisplay
vgdisplay
lvdisplay

Check drives already in use
blkid
or
ls -l /dev/disk/by-uuid/

Find the drive that is not in that list
ls -al /dev/sd*

Create partition
fdisk /dev/sd?

If you are making a primary partition larger than 2TB you will need to follow this method using gparted
http://www.cyberciti.biz/tips/fdisk-unable-to-create-partition-greater-2tb.html

Format
mkfs -t ext4 /dev/sd?1

check for its UUID
blkid
or
ls -l /dev/disk/by-uuid/

and add to /etc/fstab
vi /etc/fstab
UUID=d002359e-307d-41d3-8b15-b234235c55a /your/mount/point ext4 defaults 1 2

Test /etc/fstab
mount -a

Create filesystem
mkfs.ext4 /dev/vg_drive3/lv_drive3

Mounting an old drive hot plugged in
vgchange -a y

Tags: , , ,

Cleaning up Unix disk space

Posted in Unix on March 2nd, 2012 by phoenixdigital

From time to time you may need to clean up your system as disk space runs low. Realistically you should look at setting up syslog to handle areas of your disk that might be prone to blowout usage but if you haven’t then the following commands may be of use.

Read more »

Tags: , , , , ,

Remote rsyslog on Linux

Posted in Unix on February 24th, 2012 by phoenixdigital

In order to log data from a remote machine to a central server you will need to perform the following to the central server.
Read more »

Tags: , ,

Redhat resize a LVM partition

Posted in Unix on November 10th, 2011 by phoenixdigital

This is a bit fiddly but I was in the following situation.

I had a bootable 4GB USB drive running Oracle Unbreakable Linux installation. It was installed on an LVM parition on the USB drive.

Now it came time to move this to an 8G drive which was achieved with the command

dd if=/dev/sda of=/dev/sdb conv=notrunc

Where the original 4G drive was /dev/sda and the replacement 8G drive was /dev/sdb.

All good so far. Now however how do I extend the LVM parition to use this new space. Here is where some hoop jumping comes in.
Read more »

Tags: , , , ,

Adding time sync daemon (ntpd) service to Redhat

Posted in Unix on September 28th, 2011 by phoenixdigital

Below is a basic summary of the commands required to install a ntp daemon onto your server to keep track of time.

Read more »

Tags: , , , ,

Adding Services to RHEL with chkconfig

Posted in Unix on September 27th, 2011 by phoenixdigital

If you want your daemons to start and stop with your Redhat system as it boots chkconfig is what you were looking for.
Read more »

Tags: , , , , ,

Solaris 10 useful commands

Posted in Unix on August 31st, 2011 by phoenixdigital

A store of useful commands as I find them

displays the memory usage of running processes
prstat

List active processes (generally useful only with a grep)
ps -ef

Display physical memory size on server
prtconf|grep -i mem

Display swap size (do the math based on results of two commands)
pagesize
swap -l

Package installation
Get your version via ‘uname -a’ reference wikipedia if you dont know how to translate to Sun version.

Get packages from here
http://www.sunfreeware.com/

install with command
cd
gunzip packagename.gz
pkgadd -d packagename

Tags: , , ,

Solaris 10 SMF services

Posted in Unix on August 30th, 2011 by phoenixdigital

The SMF or Service Management Facility handles the control of services within Solaris 10. Below are some common commands for a useful lookup.

The service FMRI is an identifier of each service and can be seen by running the list services commands below. The FMRI in all the commands below can be replaced with just the service name as long as there are no other services with similar names.

List all services
svcs

List all services including disabled services
svcs -a

View a service current status
svcs -H <service_FMRI>

Read more »

Tags: , , , , , , , ,

YUM package installation

Posted in Unix on June 1st, 2011 by phoenixdigital

Below are some basics for installations of required packages using YUM (Yellowdog Updater Modified)

These steps are primarily for Oracle Enterprise Linux but will be valid for most Linux systems.
Read more »

Tags: , , ,