DaemonForums  

Go Back   DaemonForums > OpenBSD > OpenBSD General

OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 29th December 2022
gordon.f gordon.f is offline
Fdisk Soldier
 
Join Date: Oct 2021
Location: Europe
Posts: 60
Default What is the equivalent of a unit file of Linux in OpenBSD?

Dear OpenBSD users,

there is an information for Linux distributions:
Quote:
.service: A service unit describes how to manage a service or application on the server. This will include how to start or stop the service, under which circumstances it should be automatically started, and the dependency and ordering information for related software.
For an OpenBSD VPS, how can one create an equivalent file, so a program bound to that file can starts when VPS starts and works until next reboot?

Could you please refer a man page for this?

Also if you've provisioned such a system can you tell something about it? For example what did you build? What does it do? I'd really like to hear about your experience.
Reply With Quote
  #2   (View Single Post)  
Old 29th December 2022
Head_on_a_Stick's Avatar
Head_on_a_Stick Head_on_a_Stick is offline
Real Name: Matthew
Bitchy Nerd Elitist
 
Join Date: Dec 2015
Location: London
Posts: 461
Default

See rc.d(8) et al. Check /etc/rc.d/ for some examples to work from (and the man page ofc).

Note that systemd unit files are declarative in nature and so require no coding skills. Services in OpenBSD are controlled by shell scripts, which will need a lot more thought and attention to avoid user-induced bugs. This is one of the advantages of systemd for the "normal" user.
Reply With Quote
  #3   (View Single Post)  
Old 29th December 2022
gordon.f gordon.f is offline
Fdisk Soldier
 
Join Date: Oct 2021
Location: Europe
Posts: 60
Default

Quote:
Originally Posted by Head_on_a_Stick View Post
See rc.d(8) et al. Check /etc/rc.d/ for some examples to work from (and the man page ofc).

Note that systemd unit files are declarative in nature and so require no coding skills. Services in OpenBSD are controlled by shell scripts, which will need a lot more thought and attention to avoid user-induced bugs. This is one of the advantages of systemd for the "normal" user.
Dear Matthew,

Thanks for the information. So in order to create a script for rc.d I assume I should be able to write some ksh code, is that correct?
Reply With Quote
  #4   (View Single Post)  
Old 29th December 2022
Head_on_a_Stick's Avatar
Head_on_a_Stick Head_on_a_Stick is offline
Real Name: Matthew
Bitchy Nerd Elitist
 
Join Date: Dec 2015
Location: London
Posts: 461
Default

Yes, that's right. It's not as complicated as it sounds though. For example, /etc/rc.d/amd is only 11 lines.
Reply With Quote
  #5   (View Single Post)  
Old 29th December 2022
gordon.f gordon.f is offline
Fdisk Soldier
 
Join Date: Oct 2021
Location: Europe
Posts: 60
Default

Quote:
Originally Posted by Head_on_a_Stick View Post
Yes, that's right. It's not as complicated as it sounds though. For example, /etc/rc.d/amd is only 11 lines.
I checked it and at first glance it seems not very complicated like you said.

How can I get the full list of these keywords below? Which words I can put into a script so rcctl can understand? I guess these scripts are controlled by rcctl.
Code:
rc_reload=NO
rc_stop=NO

Last edited by gordon.f; 29th December 2022 at 04:50 PM. Reason: Typo
Reply With Quote
  #6   (View Single Post)  
Old 29th December 2022
Head_on_a_Stick's Avatar
Head_on_a_Stick Head_on_a_Stick is offline
Real Name: Matthew
Bitchy Nerd Elitist
 
Join Date: Dec 2015
Location: London
Posts: 461
Default

The available actions are listed by the _rc_actions variable in /etc/rc.d/rc/subr.

Last edited by Head_on_a_Stick; 29th December 2022 at 05:09 PM. Reason: better reply
Reply With Quote
  #7   (View Single Post)  
Old 29th December 2022
gordon.f gordon.f is offline
Fdisk Soldier
 
Join Date: Oct 2021
Location: Europe
Posts: 60
Default

Quote:
Originally Posted by Head_on_a_Stick View Post
The available actions are listed by the _rc_actions variable in /etc/rc.d/rc/subr.
Thanks a lot. I found some of them and their meanings in the man page: https://man.openbsd.org/rc.subr.8
Reply With Quote
  #8   (View Single Post)  
Old 29th December 2022
Head_on_a_Stick's Avatar
Head_on_a_Stick Head_on_a_Stick is offline
Real Name: Matthew
Bitchy Nerd Elitist
 
Join Date: Dec 2015
Location: London
Posts: 461
Default

Hah! Well done. I missed that man page. I was just reading the scripts... :P
Reply With Quote
  #9   (View Single Post)  
Old 29th December 2022
gordon.f gordon.f is offline
Fdisk Soldier
 
Join Date: Oct 2021
Location: Europe
Posts: 60
Default

Quote:
Originally Posted by Head_on_a_Stick View Post
Hah! Well done. I missed that man page. I was just reading the scripts... :P
Can I also ask why we are putting this line
Code:
. /etc/rc.d/rc.subr
after this line
Code:
daemon_execdir="/etc/amd"
This global default daemon_execdir defined in rc.subr so how come we can write it before . /etc/rc.d/rc.subr?
Reply With Quote
Old 29th December 2022
Head_on_a_Stick's Avatar
Head_on_a_Stick Head_on_a_Stick is offline
Real Name: Matthew
Bitchy Nerd Elitist
 
Join Date: Dec 2015
Location: London
Posts: 461
Default

Looks like /etc/rc.d/rc.subr uses the daemon_execdir variable so it must be set in the rc script before sourcing rc.subr.
Reply With Quote
Old 29th December 2022
gordon.f gordon.f is offline
Fdisk Soldier
 
Join Date: Oct 2021
Location: Europe
Posts: 60
Default

Yes, that's what I'm wondering. How do you use that variable before including the file which defines it?

Last edited by gordon.f; 29th December 2022 at 06:00 PM. Reason: Typo
Reply With Quote
Old 29th December 2022
Head_on_a_Stick's Avatar
Head_on_a_Stick Head_on_a_Stick is offline
Real Name: Matthew
Bitchy Nerd Elitist
 
Join Date: Dec 2015
Location: London
Posts: 461
Default

The variable is only called in rc.subr, it is set (or not) in the rc script itself.

Reference: https://github.com/openbsd/src/blob/...d/rc.subr#L116
Reply With Quote
Old 29th December 2022
gordon.f gordon.f is offline
Fdisk Soldier
 
Join Date: Oct 2021
Location: Europe
Posts: 60
Default

I'm sorry I didn't get it.
Code:
#!/bin/ksh
#
# $OpenBSD: amd,v 1.11 2022/05/26 11:27:03 ajacoutot Exp $

daemon="/usr/sbin/amd"
daemon_execdir="/etc/amd"

. /etc/rc.d/rc.subr
Shouldn't we first include the file "/etc/rc.d/rc.subr" and then use the variable "daemon_execdir"? Does ksh not have a rule of declaration order?
Reply With Quote
Old 29th December 2022
Head_on_a_Stick's Avatar
Head_on_a_Stick Head_on_a_Stick is offline
Real Name: Matthew
Bitchy Nerd Elitist
 
Join Date: Dec 2015
Location: London
Posts: 461
Default

daemon_execdir is not set anywhere in rc.subr but the variable is used there so it needs to be set before sourcing.

I don't think I'm explaining this very well (sorry) so perhaps wait for somebody else to chime in. There are a few real programmers who post here. I'm not a programmer.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Equivalent to Linux's /sys/class/backlight? vns3 OpenBSD General 2 10th November 2018 05:27 PM
tcptrack or equivalent Scripter OpenBSD Packages and Ports 16 23rd June 2018 11:53 PM
Linux kernel: Critical UFS file system bug in 4.9 and 4.11 kernels (4.8.4 and above) comet--berkeley Other BSD and UNIX/UNIX-like 1 19th June 2017 05:13 PM
FreeBSD equivalent to OpenBSD mk.conf FETCH_PACKAGES=Yes sysfu FreeBSD Ports and Packages 10 16th March 2015 11:37 AM
Linux Binary: cannot execute binary file xmorg FreeBSD General 3 25th September 2010 03:46 PM


All times are GMT. The time now is 08:40 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick