DaemonForums  

Go Back   DaemonForums > OpenBSD > OpenBSD Packages and Ports

OpenBSD Packages and Ports Installation and upgrading of packages and ports on OpenBSD.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 7th January 2013
ershiba ershiba is offline
Loading, please wait...
 
Join Date: Dec 2012
Posts: 34
Thanked 0 Times in 0 Posts
Default Nginx - autostart & gracefully shutdown

hi friends,
right now, my nginx need to manually start using
Code:
$ sudo nginx
under my user oem account

what is the best practice or suggestion for starting it automatically and able to gracefully shutdown if it detect a power shutdown event (eg, when user press the [POWER] button on their PC)

is it by adding pkg_scripts="nginx" using /etc/rc.conf.local ?
Reply With Quote
  #2   (View Single Post)  
Old 7th January 2013
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 3,710
Thanked 214 Times in 189 Posts
Default

Just:
Code:
# echo nginx_flags="" >> /etc/rc.conf.local
Reply With Quote
  #3   (View Single Post)  
Old 7th January 2013
ocicat ocicat is offline
Administrator
 
Join Date: Apr 2008
Posts: 2,888
Thanked 190 Times in 160 Posts
Default

Quote:
Originally Posted by ershiba View Post
what is the best practice or suggestion for starting it automatically...
is it by adding pkg_scripts="nginx" using /etc/rc.conf.local ?
In addition to jggimi's comments, familiarizing yourself with the information Section 10.3 of the FAQ is in order.
Reply With Quote
  #4   (View Single Post)  
Old 7th January 2013
ershiba ershiba is offline
Loading, please wait...
 
Join Date: Dec 2012
Posts: 34
Thanked 0 Times in 0 Posts
Default

thanks to jggimi & ocicat,

i just wanna to confirm, because there is no mention about this is manual,

the rule to autostart for all application is

rc.conf.local
{whatever application name}_flags=""

and add them in pkg_scripts

if
abc_flags="-u root -p 1234567"

it would be execute as # abc -u root -p 1234567
during auto start? am i correct?

maybe i am confuse about the idea of flags & parameters,
Reply With Quote
  #5   (View Single Post)  
Old 7th January 2013
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 3,710
Thanked 214 Times in 189 Posts
Default

No. The rc.conf and rc.conf.local files contain nothing but environment variables.

The *_flags variables are only for built-in daemons -- and are used, by name, in the /etc/rc shell script. Spend a few minutes reading that script and you will see how the various *_flags variables are utilized.

the pkg_scripts variable is for the admin to name specific third party scripts, installed by pkg_add in /etc/rc.d, that he or she wants to have executed by the /etc/rc shell script at boot time.
Reply With Quote
  #6   (View Single Post)  
Old 7th January 2013
ershiba ershiba is offline
Loading, please wait...
 
Join Date: Dec 2012
Posts: 34
Thanked 0 Times in 0 Posts
Default

sorry, because English is not my native language,

thanks for the explanation jggimi,

so, pkg_scripts would call "executable" that only available & located in /etc/rc.d/

but *_flags would be base on etc/rc.conf file, if it is not there, then no need to use *_flags,

eg,
php_fpm

since there is no mentioned of php_fpm in rc.conf,
then to autostart it, we only need to pkg_scripts="php_fpm" no need php_fpm_flags=""

and since nginx_flags="" is mentioned in rc.conf,
so to use it, we must put nginx_flags="" rc.conf.local

but why mysqld_flags="" or pgsql_flags?

i am confuse, is that anything that in pkg_scripts must have equivalent *_flags="" entry?

i just tried the following,
php_fpm_flags=NO
so php stop autoboot after a reboot,

then this bring another question?

isn't it php_fpm_flags="" already sufficient to prove that i want to boot this php_fpm thing?
then pkg_scripts is duplicating, imo.

Last edited by ershiba; 7th January 2013 at 03:44 PM. Reason: update
Reply With Quote
  #7   (View Single Post)  
Old 7th January 2013
shep shep is offline
ISO Quartermaster
 
Join Date: May 2008
Location: Dry and Dusty
Posts: 593
Thanked 9 Times in 9 Posts
Default

There may be some confusion about the separation of start up tasks in rc.conf.local. In OpenBSD 5.0 rc_scripts was renamed pkg_scripts
Quote:
rc.conf 'rc_scripts' variable renamed to 'pkg_scripts': This change was introduced to make it clear that pkg_scripts should only be used to store packages(7) rc.d(8) scripts names.
At that time nginx was a separate package but it has now been added to the base.

Start up scripts for base packages are listed in /etc/rc.conf. I think the intent is to put start up scripts from added packages in pkg_scripts.

For example, my rc.conf.local
Code:
ntpd_flags="-s"         # enabled during install
xdm_flags=              # enabled during install
lpd_flags=""            # Start print daemon
apmd_flags="-C"         # AMD CPU power management
pkg_scripts="dbus_daemon avahi_daemon mpd"
ntpd, xdm, lpd and apmd are core applications listed in /etc/rc.conf.
I additionally installed dbus, avahi and mpd and on my system these are listed in /etc/rc.d/
Reply With Quote
  #8   (View Single Post)  
Old 7th January 2013
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 3,710
Thanked 214 Times in 189 Posts
Default

Starting with 5.0, *_flags variables were made generic and could include third party daemons. Prior to that point, they were never used with third party ports/packages.

With that change, if any third party script (let us call it <daemon>) in /etc/rc.d requires flags or user to be set, the admin would set <daemon>_flags or <daemon>_user variables in /etc/rc.conf.local. The <daemon> script still requires inclusion in the pkg_scripts variable, so that /etc/rc knows in what order to execute them.

Built-in daemons -- those that come with the base OS, and are not installed from the ports/packages system -- are not listed in the pkg_scripts variable. You only need to change the built-in-daemon_flags variable to something other than =NO.

Last edited by jggimi; 7th January 2013 at 04:16 PM. Reason: clarity
Reply With Quote
  #9   (View Single Post)  
Old 7th January 2013
ershiba ershiba is offline
Loading, please wait...
 
Join Date: Dec 2012
Posts: 34
Thanked 0 Times in 0 Posts
Default

thanks shep & jggimi,
base on our conversation above, so i conclude,

put *_flags="" for every application that in pkg_scripts (seems to be the desired way)

regarding pkg_scripts, if the sole idea is for maintain the order to start & shutdown,

first_flags=""
second_flags=""
third_flags=""

maybe if the rc.conf.local reader should able to parse the *_flags things in order and export pkg_scripts on its own. imo.
Reply With Quote
Old 7th January 2013
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 3,710
Thanked 214 Times in 189 Posts
Default

Quote:
put *_flags="" for every application that in pkg_scripts
No, only those that need them. Most will not. Look at shep's example. None of his third party package scripts have _flags variables set.

Last edited by jggimi; 7th January 2013 at 04:33 PM. Reason: clarity
Reply With Quote
Old 7th January 2013
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 3,710
Thanked 214 Times in 189 Posts
Default

Think about daemons procedurally:
  1. Is this a built-in daemon? If so, set the _flags variable to something other than NO to enable the daemon at boot time. Stop here.
  2. Is this a third party package I installed? If so:
    1. Add the /etc/rc.d script name to the pkg_scripts variable.
    2. Does it need any special flags? If so, create a _flags variable.
    3. Does it need to be started as a special user, other than defined in the script? If so, create a _user variable.
  3. If this is a self-installed application, not included in the ports/packages system, either I create my own rc.d script as described in FAQ 10.3, or I create startup scripting in /etc/rc.local.
Reply With Quote
Old 7th January 2013
shep shep is offline
ISO Quartermaster
 
Join Date: May 2008
Location: Dry and Dusty
Posts: 593
Thanked 9 Times in 9 Posts
Default

If nginx was not a core package and was installed via ports or pkg_add you would have an /etc/rc.conf.local that looked like this
Code:
ntpd_flags="-s"         # enabled during install
xdm_flags=              # enabled during install
lpd_flags=""            # Start print daemon
apmd_flags="-C"         # AMD CPU power management
pkg_scripts="nginx mpd"
In the above, start up options would be in /etc/nginx.conf. Since flags are now part of third party daemons you could also try nginx_flags="-u" but this does give you nested "" and a good chance of scripting error.


Now that nginx is a core package your /etc/rc.conf.local becomes
Code:
ntpd_flags="-s"        # enabled during install
xdm_flags=             # enabled during install
lpd_flags=""            # Start print daemon
apmd_flags="-C"      # AMD CPU power management
nginx_flags=""         # Start nginx web server
pkg_scripts="mpd"
If you want to disable chroot for nginx it becomes
Code:
ntpd_flags="-s"        # enabled during install
xdm_flags=             # enabled during install
lpd_flags=""            # Start print daemon
apmd_flags="-C"      # AMD CPU power management
nginx_flags="-u"         # Start nginx web server chroot disabled
pkg_scripts="mpd"

Last edited by shep; 7th January 2013 at 05:27 PM. Reason: 1st edit forgot to close last [CODE] tag 2nd edit clarity
Reply With Quote
Old 7th January 2013
ershiba ershiba is offline
Loading, please wait...
 
Join Date: Dec 2012
Posts: 34
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by jggimi View Post
Think about daemons procedurally:
  1. Is this a built-in daemon? If so, set the _flags variable to something other than NO to enable the daemon at boot time. Stop here.
  2. Is this a third party package I installed? If so:
    1. Add the /etc/rc.d script name to the pkg_scripts variable.
    2. Does it need any special flags? If so, create a _flags variable.
    3. Does it need to be started as a special user, other than defined in the script? If so, create a _user variable.
  3. If this is a self-installed application, not included in the ports/packages system, either I create my own rc.d script as described in FAQ 10.3, or I create startup scripting in /etc/rc.local.
ok, glad you post this, it certainly helps me to understand,
so, built in daemon (those that not via pkg_add) autostart = daemonname_flags=""
(stop)

daemon that get into via pkg_add, autostart = use pkg_scripts
(stop) unless we got *_flags != "", otherwise we don't need to *_flags="" since it is unnecessary.

so, base on the above idea,
Code:
mysqld_flags=""
psgsql_flags=""
php_fpm_flags=""
nginx_flags=""
are not correct, am i right?

Code:
mysqld_flags="--bind-address=127.0.0.1"
nginx_flags="-u"
are correct,

i hope i got this idea right this time. am i?
Reply With Quote
Old 8th January 2013
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 3,710
Thanked 214 Times in 189 Posts
Default

yes. that's it
Reply With Quote
Old 26th March 2013
sysfu's Avatar
sysfu sysfu is offline
Port Guard
 
Join Date: Jun 2008
Posts: 31
Thanked 0 Times in 0 Posts
Default

It appears that the /etc/rc and /etc/rc.conf files shipped with OpenBSD 5.2 release did not include the requisite nginx components.

These were not added until Revision 1.402, Sun Aug 26 19:25:19 2012 UTC.

Therefore users of the 5.2 release will need to manually launch nginx via /etc/rc.local.
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
Why do we need password to shutdown the box ? sw2wolf FreeBSD General 3 22nd May 2012 04:35 PM
shutdown message derf FreeBSD General 5 14th December 2010 04:57 PM
openbsd shutdown phill OpenBSD General 3 27th October 2009 12:27 PM
portupgrade messed up my autostart in rc.conf semtecs FreeBSD Installation and Upgrading 6 17th March 2009 05:04 PM
Autostart Xfce ninjatux FreeBSD General 8 16th June 2008 06:47 AM


All times are GMT. The time now is 12:44 PM.


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