# Restart Perl daemon



## dg2drf (May 30, 2010)

Hello,

I run a perl daemon as spam filter. When a update from the main perlsript is available, 
it was download, extract und then the mainscript makes a "exit 1" (I think it is like an errorlevel in DOS) to restart.In the start-shell i must look with what exit the script ends und if is an exit 1 than make a restart, if it was an exit 0 than end the daemon.

In the moment I must control the status of the daemon every day and when he doesnÂ´t run I 
must start the daemon manualy. 

My question is, how must I make, that the perl-scipt starts automatic ?
I have make some tests, but I didnÂ´t find the right way.

best regards
Ralf 


Here is my Start-script :


```
#!/bin/sh
#
# $FreeBSD: ports/mail/assp/files/assp.in,v 1.1 2006/07/18 03:08:23 rafan Exp $
#

# PROVIDE: assp
# REQUIRE: LOGIN
# KEYWORD: shutdown

. /etc/rc.subr

name=assp2
rcvar=`set_rcvar`

start_cmd=assp_start
stop_cmd=assp_stop
restart_cmd=assp_restart
# command=/var/db/assp2/assp.pl
# command_interpreter=/usr/bin/perl
pidfile=/var/db/assp2/pid
extra_commands="reload"
reload_cmd=assp_reload


assp_start()
{
if [ "$1" = "" ]
then 
BASE=/var/db/assp2;
else
BASE=$1;
fi
export BASE
echo Starting ASSP Anti-SPAM Proxy server in $BASE
trap '' 1
LANG=
export LANG
exec $BASE/assp.pl $BASE 
RETVAL=$?
exit $RETVAL
}

assp_stop()
{
if [ "$1" = "" ]
 then
  BASE=/var/db/assp2;
 else
  BASE=$1;
fi
export BASE
echo Stopping ASSP Anti-SPAM Proxy server in $BASE
pidfile=$BASE/pid
kill `cat $pidfile`
rm -f $pidfile 
}

load_rc_config $name
: ${assp2_enable="NO"}
: ${assp2_flags="/var/db/assp2"}

assp_reload()
{
kill -USR1 `cat $pidfile`
  
}

assp_restart()
{
/var/db/assp2/stop && /var/db/assp2/start
}

run_rc_command "$1"
```


----------



## hydra (May 30, 2010)

You can write a shell script and run it daily via cron.

For example:

```
check_for_update()

if (retval = 0)
  command_to_kill_daemon()
else if (retval = 1)
  command_to_restart_daemon()
```


----------

