RC_SERVICE(3)

πŸ“¦
version 0.63.2 Β· 2 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, debian trixie

πŸ’– RC_SERVICE(3) β€” the OpenRC service-querying girlies πŸ’–

okay so. bestie. this is a page from the System Manager's Manual, and it's librc's whole little toolkit for asking OpenRC services how they're doing. no cap, it's giving "group chat but for daemons". let's get into it πŸ’…


✨ NAME ✨

rc_service_add, rc_service_delete, rc_service_daemon_set, rc_service_description, rc_service_exists, rc_service_in_runlevel, rc_service_mark, rc_service_extra_commands, rc_service_plugable, rc_service_resolve, rc_service_schedule_start, rc_services_scheduled_by, rc_service_schedule_clear, rc_service_state, rc_service_started_daemon, rc_service_value_get, rc_service_value_set, rc_services_in_runlevel, rc_services_in_state, rc_services_scheduled, rc_service_daemons_crashed β€” functions to query OpenRC services πŸŽ€


πŸ“š LIBRARY πŸ“š

Run Command library (librc, -lrc) 🫢


🌸 SYNOPSIS 🌸

#include <rc.h>

bool
rc_service_add(const char *runlevel, const char *service);

bool
rc_service_delete(const char *runlevel, const char *service);

bool
rc_service_daemon_set(const char *service, const char *exec,
    const char *name, const char *pidfile, bool started);

char *
rc_service_description(const char *service, const char *option);

bool
rc_service_exists(const char *service);

bool
rc_service_in_runlevel(const char *service, const char *runlevel);

bool
rc_service_mark(const char *service, RC_SERVICE state);

RC_STRINGLIST *
rc_service_extra_commands(const char *service);

bool
rc_service_plugable(const char *service);

char * rc_service_resolve const char *service

bool
rc_service_schedule_start(const char *service,
    const char *service_to_start);

RC_STRINGLIST *
rc_services_scheduled_by(const char *service);

bool
rc_service_schedule_clear(const char *service);

RC_SERVICE
rc_service_state(const char *service);

bool
rc_service_started_daemon(const char *service, const char *exec,
    int indx);

char *
rc_service_value_get(const char *service, const char *option);

bool
rc_service_value_set(const char *service, const char *option,
    const char *value);

RC_STRINGLIST *
rc_services_in_runlevel(const char *runlevel);

RC_STRINGLIST *
rc_services_in_state(RC_SERVICE state);

RC_STRINGLIST *
rc_services_scheduled(const char *service);

bool
rc_service_daemons_crashed(const char *service);
iykyk β€” yes, rc_service_resolve and rc_service_state look a lil cursed up there in the synopsis. we are reproducing them exactly, character for character, because that's the vibe. don't come for me, come for the header file πŸ™ˆ

πŸ‘‘ DESCRIPTION πŸ‘‘

these functions are the way you ~query~ OpenRC services: find out what state each one is in, start and stop it, and do all the other lil related things. main character energy for your init system, fr fr.

most of them are exactly what they sound like β€” the name and the arguments tell you what they do and what they hand back. self-descriptive icons, we love that for them ✨

  • rc_service_add() β€” adds the service to the runlevel. πŸ’–
  • rc_service_delete() β€” deletes the service from the runlevel. bye bestie πŸ¦‹
  • rc_service_daemon_set() β€” saves the arguments in the service state data, so that rc_service_daemons_crashed() can go check whether they're still running or not. it's the receipts-keeper. 🧾
  • rc_service_description() β€” returns the description variable of the service. and if option is not null? then we return the description_$option variable instead. plot twist, but make it useful. πŸ’…
  • rc_service_exists() β€” returns true if the service exists, otherwise false. simple as.
  • rc_service_in_runlevel() β€” returns true if the service is in the runlevel, otherwise false.
  • rc_service_mark() β€” puts the service into the given state. ⚠️ and heads up: if the state is RC_SERVICE_STOPPED then all data associated with the service is lost. that's not a drill, that's data loss, so know what you're doing before you mark. 😭
  • rc_service_extra_commands() β€” returns a list of extra commands the service supports beyond the default ones. (for what the default ones are, go see openrc-run.) πŸŽ€
  • rc_service_plugable() β€” returns true if the service is allowed to be plugged by rc.conf. default is true. 🫢
  • rc_service_resolve() β€” resolves service to the full path of the service that was started, or would be started. ✨
  • the scheduling trio, besties: when service starts, it starts service_to_start afterwards as directed by rc_service_schedule_start(). rc_services_scheduled() returns a list of services that will be started when service starts. rc_service_schedule_clear() clears these scheduled services for service. it's a whole chain reaction and honestly? iconic. πŸ”₯
  • rc_service_state() β€” returns the state of service. the return value is a bitmask, so more than one state can apply at once. not either/or, it's a whole spectrum, we support that 🌈
  • rc_service_started_daemon() β€” checks to see if service started exec using start-stop-daemon. and if indx is greater than zero, then it must also be the nth daemon started by service. very specific. very demure.
  • rc_service_value_set() β€” saves the value under the name option. rc_service_value_get() returns the value of the saved option. ✨
  • rc_services_in_runlevel() β€” returns a list of services in runlevel. and if runlevel is not specified? then it returns a list of all available services. generous queen πŸ‘‘
  • rc_services_in_state() β€” returns a list of all the services in state. πŸ¦‹
little note for the completionists: rc_services_scheduled_by() shows up in the NAME list and in the SYNOPSIS, but the DESCRIPTION section lowkey never gives it its own sentence. so it's here, bestie β€” we did not lose it. πŸ™ˆ

πŸ› οΈ IMPLEMENTATION NOTES πŸ› οΈ

  • every function that returns char * returns a malloced NULL terminated string, and you should free() it when you're done. no leaking, we're better than that. πŸ’…
  • every function that returns RC_STRINGLIST * should be freed using rc_stringlist_free() when you're done. πŸŽ€
  • when a function fails it should either return false or NULL and set errno β€” unless it's specified otherwise, like, above. so check errno, bestie. it's the receipts. 🧾

πŸ—‚οΈ FILES πŸ—‚οΈ

  • /run/openrc β€” normally holds the volatile state data for services on a RAM backed disk. yes, RAM. yes, it can vanish. that's the whole point, it's a vibe. πŸ’€

πŸ”— SEE ALSO πŸ”—

errno(3), malloc(3), free(3), rc_stringlist_free(3), start-stop-daemon(8) 🌸


πŸ’œ AUTHORS πŸ’œ

Roy Marples <roy@marples.name> β€” the original main character, respect. 🫢


and that's the page, babe. this one shipped under OpenRC, dated Mar 16, 2008, and honestly it ate. go forth and query your services responsibly. periodt. πŸ’–βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from