[Howto] rc.d start script examples in FreeBSD

posted in: computer | 0

FreeBSD v11.1

 

service control:

#to start, stop, restart, reload config or show status of a service execute:
service <name> start
service <name> stop
service <name> restart
service <name> reload
service <name> status

 

create the following scripts in the /etc/rc.d-folder:

/etc/rc.d/dovecot

#!/bin/sh

# REQUIRE:
# PROVIDE: dovecot
# BEFORE:
# KEYWORD: shutdown

. /etc/rc.subr

name="dovecot"
desc="Dovecot IMAP-Server"
rcvar="dovecot_enable"

command="/usr/local/sbin/dovecot"
extra_commands="reload"

load_rc_config ${name}
run_rc_command $1

 

/etc/rc.d/postfix

#!/bin/sh

# REQUIRE:
# PROVIDE: postfix
# BEFORE:
# KEYWORD: shutdown

. /etc/rc.subr

name="postfix"
desc="Postfix Mail-Server"
rcvar="postfix_enable"
procname="/usr/local/postfix/libexec/master"

start_cmd="/usr/local/postfix/sbin/postfix start"
stop_cmd="/usr/local/postfix/sbin/postfix stop"
extra_commands="reload"
reload_cmd="/usr/local/postfix/sbin/postfix reload"

load_rc_config ${name}
run_rc_command $1

 

/etc/rc.d/httpd

#!/bin/sh

# REQUIRE: mysqld
# PROVIDE: httpd
# BEFORE:
# KEYWORD: shutdown

. /etc/rc.subr

name="httpd"
desc="Apache HTTP-Server"
rcvar="httpd_enable"
procname="/usr/local/httpd/bin/httpd"

start_cmd="/usr/local/httpd/bin/httpd -k start"
stop_cmd="/usr/local/httpd/bin/httpd -k graceful-stop"
restart_cmd="/usr/local/httpd/bin/httpd -k restart"
extra_commands="reload"
reload_cmd="/usr/local/httpd/bin/httpd -k graceful"

load_rc_config ${name}
run_rc_command $1

 

/etc/rc.d/mysqld

#!/bin/sh

# REQUIRE:
# PROVIDE: mysqld
# BEFORE:
# KEYWORD: shutdown

. /etc/rc.subr

name="mysqld"
desc="mySQL Database-Server"
rcvar="mysqld_enable"
procname="/usr/local/bin/mysqld"

start_cmd="/usr/local/bin/mysqld &"
extra_commands="reload"

load_rc_config ${name}
run_rc_command $1