{"id":1746,"date":"2013-09-25T22:01:56","date_gmt":"2013-09-25T22:01:56","guid":{"rendered":"http:\/\/wiki.davelevy.info\/?p=1746"},"modified":"2023-12-29T01:15:30","modified_gmt":"2023-12-29T01:15:30","slug":"system-v-init-scripts","status":"publish","type":"post","link":"https:\/\/davelevy.info\/wiki\/system-v-init-scripts\/","title":{"rendered":"System V init scripts"},"content":{"rendered":"\n<p>I really like Ubuntu&#8217;s system V initialisation scripts and features. This is now based on the LSB standard. The Debian Wiki documents how to make an LSB init script <a title=\"LSB Init Scripts at the Debian Wiki\" href=\"https:\/\/wiki.debian.org\/LSBInitScripts\">here&#8230;<\/a>. This has been replaced by <a href=\"https:\/\/davelevy.info\/wiki\/systemd-ptui\/\"><em>systemd<\/em><\/a>.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>The script runs in different modes, LSB requires start, stop, restart, force-reload, and status modes.<\/p>\n\n\n\n<p>Dependency is managed using a comment block, i.e. you can determine which services are required to be running before the service managed by the script. Here&#8217;s a zabbix example,<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">### BEGIN INIT INFO\n# Provides: zbxagentd\n# Required-Start: $network $local_fs\n# Required-Stop: $network $local_fs\n# Default-Start: 2 3 4 5\n# Default-Stop: 0 1 6\n# Short-Description: starts and stops zabbix_agentd\n# Description: starts and stops zabbix_agenta, suports all LSB script methods\n### END INIT INFO<\/pre>\n\n\n\n<p>This depends on networks and disks.<\/p>\n\n\n\n<p>With Ubuntu, there are a bunch of functions, loaded by<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">. \/lib\/lsb\/init-functions<\/pre>\n\n\n\n<p>this declares helper function and a bunch of log writer scripts<\/p>\n\n\n\n<p>In the Zabbix scripts, I used the program start-stop-daemon and the log_daemon_msg and log_end_msg to write the messages.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">case \"$1\" in\n  start)\n\t# I am unsure as to which configuration creates the .pid file\n\tlog_daemon_msg \"Starting $DESC: $NAME\"\n\tstart-stop-daemon --oknodo --start --pidfile $PID \\\n\t\t--exec $DAEMON\n\tcase $? in\n\t0)\tlog_end_msg 0 ;;\n\t*)\tlog_end_msg 1 ;;\n\tesac\n\t;;<\/pre>\n\n\n\n<p>There are a couple more log write functions in the functions script.<\/p>\n\n\n\n<p>The GeekStuff writes about it <a title=\"How to Write Linux Init Scripts Based on LSB Init Standard\" href=\"https:\/\/web.archive.org\/web\/20171207171640\/http:\/\/www.thegeekstuff.com:80\/2012\/03\/lsbinit-script\/\">here&#8230;<\/a>, and I posted the whole script to the zabbix forums before I implemented the LSB standard, this is also documented in my <a title=\"using AWS\" href=\"https:\/\/davelevy.info\/wiki\/amazon-web-services\/\">AWS<\/a> post on this wiki.<\/p>\n\n\n\n<p>I have uploaded the <a title=\"the code used to start and stop the zabbix agent\" href=\"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2013\/09\/zabbix.txt\">zabbix<\/a> agent.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I really like Ubuntu&#8217;s system V initialisation scripts and features. This is now based on the LSB standard. The Debian Wiki documents how to make an LSB init script here&#8230;. This has been replaced by systemd.<\/p>\n","protected":false},"author":1,"featured_media":9915,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","_share_on_mastodon":"0"},"categories":[8,3],"tags":[499,916,569,570,911,343,163],"class_list":["post-1746","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-technology","tag-init-d","tag-linux","tag-lsb","tag-sysv","tag-technology","tag-ubuntu","tag-zabbix"],"share_on_mastodon":{"url":"","error":""},"jetpack_featured_media_url":"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2013\/09\/code-pankajpatel-unsplash-w1080.jpg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts\/1746","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/comments?post=1746"}],"version-history":[{"count":11,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts\/1746\/revisions"}],"predecessor-version":[{"id":9917,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts\/1746\/revisions\/9917"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/media\/9915"}],"wp:attachment":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/media?parent=1746"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/categories?post=1746"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/tags?post=1746"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}