# dae - daemon control script - request for comments



## dylanbr (Nov 24, 2010)

Hi all,

I have created a small shell script called *dae* to help speed up the process of controlling system daemons. That is to make it quicker to _stop_ / _start_ / _restart_ or otherwise interact with the system startup scripts.

The latest development version can be found at https://github.com/dylanbr/dae or there is an older version already in ports/sysutils/dae.

I'm looking for comments anyone may have regarding bugs, additional features or anything that would make this script more useful (without deviating too far from it's core purpose).

Thanks!

- Dylan


----------



## SirDice (Nov 24, 2010)

All I can suggest is looking at fsc before adding things that are already being developed. 

http://www.freebsd.org/news/status/report-2010-07-2010-09.html#FreeBSD-Services-Control-(fsc)


----------



## dylanbr (Nov 24, 2010)

Thanks for the link SirDice - I'll definitely take a look but on first glance it doesn't look to be the same.

What I might need to do is add fsc support to dae.

To clarify: dae is only concerned with taking action over daemons -- it is a conveniant shorthand to allow one to perform these actions with the least amount of effort. It does have any monitoring capability. Where one would normally type something like "/usr/local/etc/rc.d/apache2 restart; /usr/local/etc/rc.d/mysql restart", one can type "dae apa= my=" instead.

Hope this helps to explain a little -- this is definitely not any sort of earth shattering change to the way things work -- just something for lazy people like me to speed things up a little


----------



## SirDice (Nov 24, 2010)

dylanbr said:
			
		

> To clarify: dae is only concerned with taking action over daemons -- it is a conveniant shorthand to allow one to perform these actions with the least amount of effort. It does have any monitoring capability. Where one would normally type something like "/usr/local/etc/rc.d/apache2 restart; /usr/local/etc/rc.d/mysql restart", one can type "dae apa= my=" instead.


Which is similar to the intended `# fscadm enable apache`


----------



## graudeejs (Nov 24, 2010)

dylanbr said:
			
		

> Thanks for the link SirDice - I'll definitely take a look but on first glance it doesn't look to be the same.
> 
> What I might need to do is add fsc support to dae.
> 
> ...



You should install mksh. File completion works very well, so all you have to do is:

```
/u<tab>lo<tab>e<tab>rc<tab>po<tab> restart
```
to get

```
/usr/local/etc/rc.d/postfix restart
```


----------



## dylanbr (Nov 24, 2010)

A comparison:

If I'm reading the fscadm man page correctly, "fscadm enable apache" will enable service monitoring via fscd for your apache service and start it again if it dies but it will not restart the service if it is already running. From what I can see fscadm doesn't actually support a mechanism to force a restart - only to add monitoring.

"dae apa=" on the other hand will not enable any sort of service monitor, it will not check if the service is running, it will just send a "restart" to the closest matching script starting with "apa". This means I don't have to worry whether I'm running apache or apache2 or apache22, as long as the script starts with apa. It's also quicker to type which is great on slow lines. ( I'm from Africa, we're good at slow lines  ). And finally in my example I restart two services with a single command, another time saver.

I feel I should stress again -- this is about minimising the input and knowledge needed to accomplish the action. One could probably accomplish the same thing by using a set of aliases or some shell expansion. I decided to rather go for a shell script to do the job.

It looks like both are great tools for managing whatever is running on your system -- but they service two different purposes. I can envisage using fscd to make sure apache keeps running but using dae to restart it if I need to change the configuration file.


----------



## dylanbr (Nov 24, 2010)

killasmurf86 said:
			
		

> You should install mksh. File completion works very well, so all you have to do is:
> 
> ```
> /u<tab>lo<tab>e<tab>rc<tab>po<tab> restart
> ...



22 characters vs. 8 for "dae pos=" -- you are obviously not near as lazy as I am! :h

Thanks for the comment.


----------



## SirDice (Nov 24, 2010)

killasmurf86 said:
			
		

> You should install mksh. File completion works very well, so all you have to do is:
> 
> ```
> /u<tab>lo<tab>e<tab>rc<tab>po<tab> restart
> ...



No need for mksh, this works on tcsh, csh and bash too


----------



## graudeejs (Nov 24, 2010)

Ye I know, but I like how it works on mksh [much better]


----------



## jalla (Nov 24, 2010)

> Ye I know, but I like how it works on mksh [much better]


In danger of straying widely off-topic here, but I'd like to ask why?
(Seriously, I've never used it so I'm curious as to how completion works much better in mksh)

And btw, in FreeBSD tcsh==csh.


----------



## graudeejs (Nov 24, 2010)

jalla said:
			
		

> In danger of straying widely off-topic here, but I'd like to ask why?
> (Seriously, I've never used it so I'm curious as to how completion works much better in mksh)
> 
> And btw, in FreeBSD tcsh==csh.



1) it's faster to press single tab, than Ctrl+D
2) if I enter 1 character and hit tab, I will see all available commands
3) if I neter part of path, that matches other directories (for example /usr/l) and hit enter it will show all matching directories, so I can pick faster.... [t?csh feels much different there]

There are some situations, where completion in t?csh isn't as good as mksh... But I don't remember exact case, so I can't tell you... however when you work with bough of them (I do), then you notice the difference.
You really need to try... to see... anyway, t?csh completion is good enough....

btw, you don't need to rehash mksh  (I like it)


----------



## SirDice (Nov 24, 2010)

Trying not to take it even further off topic


			
				jalla said:
			
		

> And btw, in FreeBSD tcsh==csh.


Correct. It's the same executable (one is a hardlink to the other) but they do behave differently.


----------



## wblock@ (Nov 24, 2010)

Odd that nobody has mentioned service(8) yet.

`# service apache22 restart`
`# service devfs restart`


----------



## graudeejs (Nov 24, 2010)

Didn't knew about it


----------



## rbelk (Nov 24, 2010)

Dylanbr, you can also use the already installed utilities from the base distribution.
1. rcstart -- starts a service.
2. rcorder -- print out a dependency ordering of a set of interdependent files.
3. rcrestart -- restarts a service, symlinked to rcstart.
4. rcstatus -- gives the status of services, symlinked to rcstart.
5. rcstop -- stops a service, symlinked to rcstart.


----------



## phoenix (Nov 24, 2010)

Uhm, what "base distribution" are you using?  I don't see any mention of rcstart/rcrestart/rcstop/rcstatus on my 7.3 or 8.1 systems.  Nothing via which(), locate(), man(), or find().

There is, however, rcorder(), and service().


----------



## SirDice (Nov 24, 2010)

phoenix said:
			
		

> Uhm, what "base distribution" are you using?  I don't see any mention of rcstart/rcrestart/rcstop/rcstatus on my 7.3 or 8.1 systems.


Looks like they're specific to DragonFlyBSD.

http://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/sbin/rcrun/Makefile


----------



## rbelk (Nov 24, 2010)

Sorry Dylanbr, my mistake. I found them on the net. I've been using them far to long and just forgot about it. Here's the copyright from the scripts.

Here's the output of 'uname -a'.

```
FreeBSD rbserver.umsmed.edu 8.1-RELEASE FreeBSD 8.1-RELEASE #0: Mon Jul 19 02:36:49 UTC 2010 root@mason.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  amd64
```



> # Copyright (c) 2006-2009
> # Dominic Fandrey <kamikaze@bsdforen.de>
> #
> # Redistribution and use in source and binary forms, with or without
> ...



Dominic does maintain the /usr/ports/sysutils/bsdadminscripts package. I will see if he still supports them for FreeBSD and if he does I'll upload them to my web site.


----------



## rbelk (Nov 24, 2010)

OK Guys, they are in the bsdadminscripts port. So install it and your good to go.


----------



## SirDice (Nov 24, 2010)

Actually, they're all quite usefull. And most I didn't even know about :\

I personally like fsc. Now lets see if I can break a ten year old habit


----------



## dylanbr (Nov 25, 2010)

wblock said:
			
		

> Odd that nobody has mentioned service(8) yet.
> 
> `# service apache22 restart`
> `# service devfs restart`





			
				rbelk said:
			
		

> OK Guys, they are in the bsdadminscripts port. So install it and your good to go.





			
				SirDice said:
			
		

> Actually, they're all quite usefull. And most I didn't even know about :\
> 
> I personally like fsc. Now lets see if I can break a ten year old habit



Thanks for all the great feedback guys!

It is very interesting to see the growth in functionality in this area. I do hope that eventually we end up with something that is standardised across the entire BSD ecosystem.

Personally what I'd like to see is the service monitoring of fsc coupled with the ability of service (or the rc* utilities) to report on the ordering and activation status and finally the shortcuts and globbing I've put into dae. That would give me confidence that once I start a service it stays running but also let me make changes quickly and easily.

Exciting times. :e


----------

