create account

FreeBSD - creating a simple rc.d service by klevn

View this thread on: hive.blogpeakd.comecency.com
· @klevn · (edited)
$0.24
FreeBSD - creating a simple rc.d service
created services before,  this is much easier than systemd.

this is all it takes to create a small service that mounts and unmounts a nfs partition.

yes I could put this into fstab.. but I found it can hang the computer on boot if it is not present.. and there is no easy way to 'turn it off' in the fstab without physically editing it.

it only requires one file, a rc.d style service file. 

this makes things easier, i can not simply say.. as root

~~~
service zengarden start 
service zengarden stop
~~~

and add this to my rc.conf

~~~
zengarden_enable="YES"
~~~


here is the file that does all the work.

  /usr/local/etc/rc.d/zengarden

~~~
#!/bin/sh

# PROVIDE: zengarden
# REQUIRE: serenity nfs-client
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable the zengarden:
#
# zengarden_enable="YES"
#

. /etc/rc.subr

#export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

name="zengarden"
rcvar="zengarden_enable"
start_cmd="${name}_start" 
stop_cmd="${name}_stop" 

zengarden_start() 
{
	/sbin/mount serenity:/srv/nfs/zg /mnt/zg
}
zengarden_stop() 
{
	umount /mnt/zg
}

load_rc_config $name 
: ${zengarden_enable=NO}
run_rc_command "$1"
~~~

using search/replace all of 'zengarden' in this file .. you can create a simple rc.d service that works for you.  (be sure you name the file you create the same)

edit the command within start/stop respectively to get the results you want.
👍  , , , , , ,
properties (23)
authorklevn
permlinkfreebsd-creating-a-simple-rc-d-service
categoryfreebsd
json_metadata"{"tags":["admin","startup","pob","vyb"],"app":"hiveblog/0.1","format":"markdown","description":"Simple rc.d script to perform startup/shutdown actions are making my life easier."}"
created2022-01-25 14:24:39
last_update2022-01-25 14:46:18
depth0
children0
last_payout2022-02-01 14:24:39
cashout_time1969-12-31 23:59:59
total_payout_value0.120 HBD
curator_payout_value0.116 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,434
author_reputation539,164,563,565
root_title"FreeBSD - creating a simple rc.d service"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id109,840,596
net_rshares195,896,093,176
author_curate_reward""
vote details (7)