I have created a Linux daemon (in C language) to send certain information via UDP to another computer. It requires of course the remote IP address and the port number. I store this daemon in /usr/local/bin/
and I also created a script in /etc/init.d/
to start|stop|restart the daemon.
So far, the IP address and the port number are passed to the daemon, directly by the script. By example, the start() part of the script looks like this:
start() {
/usr/local/bin/lvsload_udp_s 192.168.122.25 47239
}
So, when the remote IP and/or port number changes, I have to modify my script, instead of modifying some configuration file. It is a bad practice, I know.
What is the best way of passing the arguments to my daemon? Thanks
Why do you think command line parameters are bad?
Configuration files are additional work, since you need to parse them. And going with your example, modifying a configuration file = modifying one file. Modifying a script = modifying one file. Doesn't seem like much of a difference, when you only have a small number of arguments. You can even stick the parameters into variables at the top of the script, which makes it almost like a config file :-) Some scripts even source such "variable setting scripts" so it really looks like a configuration file.
If you can find a reason why command line parameters are bad, then there's a good chance that you'll also have an idea what to use instead. If, on the other hand, you can't even explain why the command line parameters are bad, then there's probably nothing wrong with using them...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With