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.

No comments: