Thursday 27 March 2014

Reorganize last partition table in mysql EXPLAINED!!!

When you new data start to use last partition in table that you partitioned it is time that from that last partition create new partitions.

It is neccesery to this because when you create partitions your last partition has parameter MAXVALUE.
Check this post for introduction http://sysadmin-tricks.blogspot.com/2014/03/partitioning-of-mysql-database-table.html .

This means that database will continue to write data in that last partition when all values that are younger that that last defined date. In are case that means that all date larger that 2013-08-21 00:00:00 is stored in partition with MAXVALUE parameter.

When you start to use partition p2014, this means that previuos partition are done with entering data. So for instance, all your partition stores data for one day period but this last partition can store data for much larger period of time because it has MAXVALUE  parameter defined during creation of it.

When this happens it is time to reorganize that last partition. Why is necceseru to do this? Because after some time, this partition becames so large and at that time point of creating partitions on that table loose sence. If your partitions store data for one day and they are 1GB big, this last would be much, much bigger because in it you would have (this is example) data for more that one day.

OK, so here we go!

#mysql
mysql>use database1
mysql>alter table SystemEvents reorganize partition p2014 into
 ( partition p20130907 values less than (to_days('2013-09-07')),
   partition p20130908 values less than (to_days('2013-09-08')),
   partition p20130909 values less than (to_days('2013-09-09')),
   partition p20130910 values less than (to_days('2013-09-10')),
   partition p20130911 values less than (to_days('2013-09-11')),
   partition p20130912 values less than (to_days('2013-09-12')),
   partition p20130913 values less than (to_days('2013-09-13')),
   partition p20130914 values less than (to_days('2013-09-14')),
   partition p20130915 values less than (to_days('2013-09-15')),
   partition p20130916 values less than (to_days('2013-09-16')),
   partition p20130917 values less than (to_days('2013-09-17')),
   partition p20130918 values less than (to_days('2013-09-18')),
   partition p20130919 values less than (to_days('2013-09-19')),
   partition p20130920 values less than (to_days('2013-09-20')),
   partition p20130921 values less than (to_days('2013-09-21')),
   partition p20130922 values less than (to_days('2013-09-22')),
   partition p20130923 values less than (to_days('2013-09-23')),
   partition p20130924 values less than (to_days('2013-09-24')),
   partition p20130925 values less than (to_days('2013-09-25')),
   partition p20130926 values less than (to_days('2013-09-26')),
   partition p20130927 values less than (to_days('2013-09-27')),
   partition p20130928 values less than (to_days('2013-09-28')),
   partition p20130929 values less than (to_days('2013-09-29')),
   partition p20130930 values less than (to_days('2013-09-30')),
   partition p2014 values less than (MAXVALUE));

This will create new partition that will store data for one day from that big partition p2014.
As you can see last partition has again MAXVALUE parameter.
 

Tuesday 25 March 2014

Redusing file system usage from large mysql table with no partition table

Ok, so you do not have table partition so when you want to do delete old data your file system is still used by large mysql table.

I will show you how to delete old data and clean your file system.

1. Backup your mysql database

#mysqldump --all-databases > mysql_30082013.dump

2. Delete old data from specific table. In my case I deleted data from table SystemEvents older than 5 days. In my case this means a reducing data for 95% of space.


mysql> DELETE FROM SystemEvents WHERE DeviceReportedTime <  DATE_SUB(NOW(),INTERVAL 5 DAY);

 3. So we deleted data from table but table is stil using file system. Mysql do not have automatic mechanism of optimising file system space when you delete data from table. Because of this we have to do myisamchk. In case that your use InnoDB tables, this utility wouldn't help you.

Small description from man pages of myisamchk command.

The myisamchk utility gets information about your database tables or checks, repairs, or optimizes them.  myisamchk works with MyISAM tables

So what we are now doing repairing, checking and optimising of SystemEvents table. You will notice that every table is made of two files. One file is MYD and that is data part of table and second is MYI and that is index part of table.

MYI = index file
MYD = data file

So when we deleted data from data, we delete index from MYI file but MYD file did not change. With myisamchk data from MYD will synchronise with indexes from MYI file.


#cd /var/lib/mysql/database1
# myisamchk  -r SystemEvents.MYI
- recovering (with sort) MyISAM-table 'SystemEvents.MYI'
Data records: 1379674
- Fixing index 1

I after this, size of your MYD file should be much, much smaller.

Things that you should be aware of before you begin with myisamchk. Make shoore that you have enough space for this operation. During myisamchk file with extension TMD is created.

# ls |grep SystemEvents

SystemEvents.MYD
SystemEvents.MYI
SystemEvents.TMD

This is temporaly table created because what myisamchk is basically doing is this: create new TMD table, insert data from MYD with index from MYI and after this is done then do rename of that TMD table to MYD.

Size of this TMD table will depend of how much data you still have in MYD table. So if you table is 100GB big and you have left with 100MB space free it is almost certain that you wouldn't be able to do myisamchk repair. I will about how to solve this problem in my next post.





Monday 24 March 2014

Partitioning of mysql database table - why and how?

We have few applications that use mysql database. Everything works perfectly except that one thing!

We are having trouble with file system usage. Even when we clean old data from tables, file system is still used because even do data are deleted from tables because there is no mechanism to automatically shrink tables. You can do this shrinkage with backup, drop and restore table but that means that you have to take your application down and users will notice that.
You can delay your problem with expanding you file system but after some time problem will be there again.
You will also notice that not all of your tables are using same size on file system(if you are rookie, this is important to know). This means that one or two tables are using 95% of your file system.

We solve this problem by using table partitioning. In this case you have same logical table which is made off smaller fragments of table called partition. Parameter that we used for partitioning was date of record. How big partition can be or how small/big these fragments are? Well that is up to you. We used a month parameter, that is are partition are made of data that are collected within a month period. In this case, when are file system is 95% full we just drop oldest partition. Database and application are online all the time and users do not know anything has happened.

When is best time do to table partition? Best time is after installation of database but in reality you usually do not know file system usage of tables until you are in full production. Even then you need some time to seen what table are biggest, how much it grows on day, week, month period. When you know this, then you can do table partitioning.

STEPS:


1. On file system you can see what table is biggest 

 [root@server ~]# cd /var/lib/mysql/database1/
[root@server ~]#  ls -lh
.
.
.
-rw-rw---- 1 mysql mysql   23M Aug  7 07:55 SystemEvents.MYI
-rw-rw---- 1 mysql mysql  110G Aug 12 01:56 SystemEvents.MYD
.

.

Ok, so this table is giving as a headache.

2.Login and connect to specific database called database1
[root@server ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 59
Server version: 5.5.33-cll-lve MySQL Community Server (GPL) by Atomicorp

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use database1;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql>

3. Depending of creating rules of table, you can use different parameter for partitioning.
Maybe safest way is to create new table, do partition of it and then insert data from table that you want to partition in to that new partitioned table and than do rename. This way your original table will be intacted in case something goes wrong.
First see table creating parameters.

mysql> SHOW CREATE TABLE SystemEvents;
SystemEvents | CREATE TABLE `SystemEvents` (
  `ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `CustomerID` bigint(20) DEFAULT NULL,
  `ReceivedAt` datetime DEFAULT NULL,
  `DeviceReportedTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `Facility` smallint(6) DEFAULT NULL,
  `Priority` smallint(6) DEFAULT NULL,
  `FromHost` varchar(60) DEFAULT NULL,
  `Message` text,
  `NTSeverity` int(11) DEFAULT NULL,
  `Importance` int(11) DEFAULT NULL,
  `EventSource` varchar(60) DEFAULT NULL,
  `EventUser` varchar(60) DEFAULT NULL,
  `EventCategory` int(11) DEFAULT NULL,
  `EventID` int(11) DEFAULT NULL,
  `EventBinaryData` text,
  `MaxAvailable` int(11) DEFAULT NULL,
  `CurrUsage` int(11) DEFAULT NULL,
  `MinUsage` int(11) DEFAULT NULL,
  `MaxUsage` int(11) DEFAULT NULL,
  `InfoUnitID` int(11) DEFAULT NULL,
  `SysLogTag` varchar(60) DEFAULT NULL,
  `EventLogType` varchar(60) DEFAULT NULL,
  `GenericFileName` varchar(60) DEFAULT NULL,
  `SystemID` int(11) DEFAULT NULL,
  `checksum` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`ID`,`DeviceReportedTime`)
) ENGINE=MyISAM AUTO_INCREMENT=711764694 DEFAULT CHARSET=latin1;


Ok, now create new table with same parameters.

mysql> CREATE TABLE `SystemEvents_new`  ( ` ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `CustomerID` bigint(20) DEFAULT NULL,
  `ReceivedAt` datetime DEFAULT NULL,
  `DeviceReportedTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `Facility` smallint(6) DEFAULT NULL,
  `Priority` smallint(6) DEFAULT NULL,
  `FromHost` varchar(60) DEFAULT NULL,
  `Message` text,
  `NTSeverity` int(11) DEFAULT NULL,
  `Importance` int(11) DEFAULT NULL,
  `EventSource` varchar(60) DEFAULT NULL,
  `EventUser` varchar(60) DEFAULT NULL,
  `EventCategory` int(11) DEFAULT NULL,
  `EventID` int(11) DEFAULT NULL,
  `EventBinaryData` text,
  `MaxAvailable` int(11) DEFAULT NULL,
  `CurrUsage` int(11) DEFAULT NULL,
  `MinUsage` int(11) DEFAULT NULL,
  `MaxUsage` int(11) DEFAULT NULL,
  `InfoUnitID` int(11) DEFAULT NULL,
  `SysLogTag` varchar(60) DEFAULT NULL,
  `EventLogType` varchar(60) DEFAULT NULL,
  `GenericFileName` varchar(60) DEFAULT NULL,
  `SystemID` int(11) DEFAULT NULL,
  `checksum` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`ID`,`DeviceReportedTime`)
) ENGINE=MyISAM AUTO_INCREMENT=711764694 DEFAULT CHARSET=latin1


Ok, we created table called SystemEvents_new with same parameter as SystemEvents table.
4. Now create partition based on these parameters DeviceReportedTime and ID. For my application I need to use these parameters, for yours you will maybe need to use different. These parameters are called PRIMARY KEYS. It is important to define these because you would not be able to do partition without them because they are parameters of partitioning.

mysql> alter table SystemEvents_new PARTITION BY RANGE(TO_DAYS(DeviceReportedTime))  ( partition p20130820 values less than (TO_DAYS('2013-08-20 00:00:00')),
partition p20130821 values less than (TO_DAYS('2013-08-21 00:00:00')), 
partition p2014 values less than (MAXVALUE));


Ok, so we created following partitions p20130820 with values that are prior 2013-08-20 00:00:00, p20130821 with values that are prior 2013-08-21 00:00:00 but after last knows partition(in this case that is partition p20130820) and p2014 with all values that are greater then are last known partition(in this case that is p20130821). So important thing here is to have continues value in table SystemEvents_new. As you can see time continuum is not broken. It won't be possible to create partition without creating last partition that have MAXVALUE parameter. This means that database will continue to write data in that last partition when all values that are younger that that last defined date. In are case that means that all date larger that 2013-08-21 00:00:00 is stored in partition with MAXVALUE parameter.

5. Insert data from non-partitioned SystemEvents table into partitioned SystemEvents_new table.

mysql>insert into SystemEvents_new select * from SystemEvents;

6. After you inserted data, you can rename table names

mysql>rename table SystemEvents to SystemEvents_old, SystemEvents_new to SystemEvents;

7. Exit mysql. Check if there are partition on file system.

 [root@server ~]# cd /var/lib/mysql/database1/
[root@server ~]#  ls -lh
.
.
.
-rw-rw---- 1 mysql mysql  144M Aug  22 01:48 SystemEvents#P#p20130820.MYD
-rw-rw---- 1 mysql mysql   13M
Aug  22 12:10 SystemEvents#P#p20130820.MYI
-rw-rw---- 1 mysql mysql  143M
Aug  22 01:49 SystemEvents#P#p20130821.MYD
-rw-rw---- 1 mysql mysql   13M
Aug  22 12:10 SystemEvents#P#p20130821.MYI
-rw-rw---- 1 mysql mysql 1019M
Aug  22 01:48 SystemEvents#P#p2014.MYD
-rw-rw---- 1 mysql mysql   89M
Aug  22 07:55 SystemEvents#P#p2014.MYI
.

.

Ok, so we have done partitioning part.
Now when you want to free some file system space you just drop oldest partition instead making backup ,drop table, create table, restore data,etc.

8. When your file system is full then drop partition table

mysql>alter table SystemEvents drop partition p20130820;



Off course,this is simple example with only 3 partition created. You can create as much partition as you want with smaller or bigger time interval.
It is important to know that depending of size of that table, insert process can take a long time to finish. During this time it would be good to stop your application because you want insert process to finish as soon as possible. If you can not stop your application, insert can be done but it will take a bit longer to finish because you will have insert, reading, writing,etc. in you database. 

Wednesday 19 March 2014

SEA AIX stops working, recreating SEA without hating AIX

Hm... where to start?
Well, we do have IBM pSeries p570. Actually, we have two racks of it. We are using IBM LPAR virtualization. We have 4 LPAR per rack with two(for redundancy (for what else))) VIOS server per rack for virtualization of CPU and RAM.
Are IBM support introduce as with concept of Shared Ethernet Adapter(SEA) when they need to implement SEA for enabling separate 10Gb/s ethernet interface for backing up are servers that was running on LPAR.

I hope that you do understand concept of SEA. Point of SEA is that you have shared ethernet interface that you can share thought VIOS among all LPAR that are connected to that VIOS.

If you are Linux admin (like  I am) then you will probably  need some time (like I did) to understand why IBM make concept of  SEA so complicated and creating of it hard as living hell. Believe me, reading IBM redbook is one thing and actually creating SEA is totally different thing(at least it was or me).

Ok, here are things that you need to know before you start to create SEA. Once you create SEA it will work perfectly as long as no network issues with physical interface occurred.

Things that you need for SEA:
1. At least one physical ethernet interface connected to your network equipment. You network will route traffic from that interface to your desired destination.
2.One virtual ethernet interface that will be in VLAN 1 for communicating between LPAR
3.Optional: One virtual ethernet interface that will be in VLAN 99 for control channel between two VIOS. This is for case that you want to have redundant SEA between VIOS'es.

VERY IMPORTANT: SEA IS CREATED ON VIOS AND YOU DO NOT ASSING IP ADDRESS TO IT.

I will show you simplest possible case of creating SEA.

$ lsdev |grep ent
ent0             Available   10 Gigabit Ethernet-SR PCI-X 2.0 DDR Adapter (1410eb02)
ent1             Available   10 Gigabit Ethernet-SR PCI-X 2.0 DDR Adapter (1410eb02)
ent2             Available   Logical Host Ethernet Port (lp-hea)
ent3             Available   Virtual I/O Ethernet Adapter (l-lan)
ent4             Available   Virtual I/O Ethernet Adapter (l-lan)

$ mkvdev -sea ent1 -vadapter ent4 -default ent4 -defaultid 1
ent5 Available
$ lsdev |grep ent
ent0             Available   10 Gigabit Ethernet-SR PCI-X 2.0 DDR Adapter (1410eb02)
ent1             Available   10 Gigabit Ethernet-SR PCI-X 2.0 DDR Adapter (1410eb02)
ent2             Available   Logical Host Ethernet Port (lp-hea)
ent3             Available   Virtual I/O Ethernet Adapter (l-lan)
ent4             Available   Virtual I/O Ethernet Adapter (l-lan)
ent5             Available   Shared Ethernet Adapter



Suppose ent1 is physical ethernet interface. Check with your network admin if he can see state on that interface. State should be UP. If it is not UP, he should do UP/DOWN of that port on network equipment until he can see that port state is UP.  If he can not see this interface correctly, you could not make SEA to work correctly.
ent4 is out virtual ethernet interface and it is in VLAN 1 and should have access to external network.

Chance that you create SEA with no trouble is almost  zero so you need to be very patient.

In case that you have any trouble in configuring SEA, maybe best thing to do is that you remove all virtual interface that you need to work with. In are case that is ent4 and ent5.

You could also create link aggregated interface from ent1 and ent2. In this case you will have redundancy on physical interfaces,too.





Tuesday 18 March 2014

HP mini 110 reboot procces stale SOLVED

I own one of these wonderful and powerful things, HP mini110. To be specific this model has mark

#110C-1100EM

Windows XP is OS.

After perfect serving for 2 year, something strange start to happen. When I reboot the system, boot process stops at very beginning. I stops at a place when you can select to go in boot menu or to select boot order. And it just stops there. I also notice that when laptop don't have power for long time (more than a day) with battery out, when I start it, it starts with no problem! I case that I need to restart it right away, same issue appears.

My first suspecting was BIOS battery, because I had it for 2 years and God knows how long it was sitting in some warehouse waiting for me :) . So I change BIOS battery. And nothing happened. Issue persist.

Before this issue appeared few keys on my keyboard stop to work. I bought cheap keyboard from Ebay.com. I tough maybe this was issue.

Hm.... I tried to ignore my problem because I also noticed that when I but laptop in stand by, it starts normally.
I also formatted OS, reinstalled XP, issue persist. Installed Linux, issue persist.

I took out HDD,issue persist.
So it was no OS issue, no BIOS battery issue, no power issue, no keyboard, no HDD.
For some time I tried to ignore problem by simply not let it go out of power.

After few months of constant looking I laptop had enough power, I sad to my self IT IS ENOUGH - or sell it or fix it!

I read all forums about similar problems.

There were many solutions,I tried them all but nothing seams to resolve my problem!

Then, one day I came across one article, where some guy was talking that he resolve his similar by unplugging integrated web camera. What a stupid thing to do I thought while I was reading that. But then ... I remember that I had issues starting to work my web camera. It was working OK for some time and it just stopped. I never tried to fix it because I thought that if has to be driver issue.

So I dismantle my screen, unplugged web camera, start laptop and ...... IT STARTED TO WORK NORMALLY!!!

Anyway, web camera was malfunction and at some point this was so bad that during boot process when hardware components are being inspected it could not pass that inspection!

It has been 2 years since this and my small but tought laptop is still working like Swiss clock!

Friday 14 March 2014

Reusing KVM cables from HP DL Proliant g5 and g6 for g8 servers HEADS UP

In case that you are considering buying HP Proliant Gen 8 servers without KVM cables because you have KVM cables from HP Proliant Gen5 and Gen6, here's small but useful tip.

In case that you don't know Gen8 servers don't have PS/2 port for mouse and keyboard. Because KVM cables for older HP server generation have 1 VGA and 2 PS/S port they cannot be connected to Gen8 server because they only have USB ports for mouse and keyboard.

Why this is important? Price of one VGA+USB cable is 99$


Thursday 13 March 2014

Extracting data from Paradox DB for easier reporting system

Few months ago I had to do extraction of data from application that is using Paradox DB. 
Application was running great but it takes to much manual work for reporting system that we need to do.
So as Linux admin I came to idea of making vbs script(because it was running of Windows XP) and make my job more easy.

Idea was to convert one Paradox table into some manipulative format like txt or csv and from that new file format extract necessary information.

Searching on the net for solution I came across to this perfect program called Paradox Converter.
God things about him is that you can do conversion thru CMD because I wanted to do this conversion through vbs script. I downloaded trial version. Only restriction in trial version is that you can only convert 50 column of particular table what in my case was more then enough.

God thing about Paradox Converter is that you can insert parsing parameter like date,you can select what column to use,what column to parse,etc. in file and when you execute conversion there is no need for human interaction.

Because I was unable to master vbs scripting in short time that I need to done this task I decide to install Cygwin and use all simplicity and power of Linux on Windows! :)

Now practical part!

Suppose you have Paradox table called Paradox_table.DB and you want to convert it to txt and from that new file do wanted parsing.

Suppose that we installed Paradox Converter in Program Files.(I will only be talking about CMD usage of Paradox Conveter. In case you want GUI, this is no post for you.) Find location of Paradox_table.DB. 

Most simple conversion would be like this:

C:\Program Files (x86)\Paradox Converter\pxcnv.exe C:\my documents\Paradox_table.DB C:\my documents\Paradox_table.txt

where Paradox_table.txt is converted file from Paradox Database to txt. You can call it what ever you want.
Executed like this, this will convert all columns. In case that you want only certain column to convert than in you should add this parameter

/COLUMNS:column_name1,column_name2,column_name3

at the end of line.

There are many filter options that you can use. For me it was interesting to use date parameter so that I can sort information by day and not to use empty fields. To use filter use parameter FILTER like this

/FILTER:filter.txt

at the end of line where filter.txt is text file in which you will store filter parameters.
My filter.txt file look like this

$ cat filter.txt
column_date:15/03/2013
column_id:!empty()

So finally my executing line is

C:\Program Files (x86)\Paradox Converter\pxcnv.exe C:\my documents\Paradox_table.DB C:\my documents\Paradox_table.txt /COLUMNS:column_name1,column_name2,column_name3/FILTER:filter.txt
This will convert my Paradox table into txt file only converting columns that I want filtering values that I want.

You can make .bat file in which you will store above command.

I called my prdx2txt.bat

Now we will use Cygwin!

#cat prdx2txt.bat
"C:\Program Files (x86)\Paradox Converter\pxcnv.exe" "C:\my documents\Paradox_table.DB" "C:\my documents\Paradox_table.txt" /COLUMNS:column_name1,column_name2,column_name3 /FILTER:filter.txt


Now when you want to use in script, use it like this

.
.
.
./prdx2txt.bat
.

.
.


This saved me a lot of time.

I hope this will help you!:)



Wednesday 12 March 2014

Running /etc/init.d/networking restart is deprecated because it may not enable again some interfaces ... (warning). SOLVED!!!

I have few Debian servers. (Debian GNU/Linux 6.0 \n \l )

Recently, I had demand to add another ethernet card and assign IP to it. No big deal, right? Right!

But ...

This was my network configuration

-# cat /etc/network/interfaces
 

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet static
        address 192.168.1.2
        netmask 255.255.255.0
        network 192.168.1.0
        broadcast 192.168.1.255
        gateway 192.168.1.1


So I just append configuration for eth1.

allow-hotplug eth1
iface eth1 inet static
        address 192.168.1.3
        netmask 255.255.255.0
        network 192.168.1.0       



And normally restart network and than ......

#/etc/init.d/networking restart
Running /etc/init.d/networking restart is deprecated because it may not enable again some interfaces ... (warning).

and than nothing. Both interface were down. I manually bring then up

#ifup eth0
#ifup eth1

And that worked just fine. I was able to connect thru both IP addresses.
But when I try to restart network using /etc/init.d/networking restart same thing occurred. That was strange because they read same configuration file but from some reason restart do not work and ifup works.

Hm....

After 30 minutes of googling ....

Running either /etc/init.d/networking restart or invoke-rc.d networking restart would run: # ifdown -a
then
# ifup -a

The problem is that ifdown -a will bring down all network interfaces, whereas ifup -a will only bring up any network devices in /etc/network/interfaces that are set to auto, anything with allow-hotplug won't be bought back up until it detects a hotplug event, usually when a network cable is plugged in.

So I add

auto eth0

and

auto eth1

And now /etc/init.d/networking start/restart works fine!!!

Thursday 6 March 2014

Start/stop/restart alfresco as non root user SOLVED

It is always pain in the ass when you have to start/stop/restart application as root user but you cannot give root password to admin of that application. So how to change/bend this? (Morpheus: Some of them can be bent, others can be broken)

So application is Alfresco(alfresco-4.2.d). You have to be root user to start/stop/restart this application. My application admin do not have root password so he cannot start/stop/restart Alfresco.
Last couple off days, he is testing some new features and he need frequent restart of Alfresco. So he calls me every. And that start to bother me because sometimes I am not there or I am doing something more important. And then he waits and waits.

So how I solve problem for him as non root user to restart alfresco as he is root?


I created a script that will check content of a file that he can write in. Depending of value in that file, alfresco will restart or not.

I called script res_alfresco.sh
Script look like this:

#!/bin/bash
FILE=/location/file.txt
if [ `cat $FILE` == 1 ]
then
echo 1
/etc/init.d/alfresco restart
sleep 10
echo 0 > $FILE
else
echo 0
fi


I put it in crontab for root user and set to run every 2 minutes
*/2 * * * * /opt/scripts/res_alfresco.sh

Value in file has to be 1 for restart.
In case that is 1, restart of alfesco and set write 0 in file. In this case restart will only happen once.

I hope that will help someone.