Skip to main content
Topic: Connecting MYSQL/MariaDB as an openrc service (Read 1075 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Connecting MYSQL/MariaDB as an openrc service

I am running mariadb with my webserver and the AI robots are killing my server and crashing mariadb.  I had to write my own start scripts do to the integration of the two.

I am hoping to attach the start script in /etc/init to openrc as a service so it will restart when it crashes.  How do I go about doing that.


It looks like it is already a service

Quote

[ruben@www3 ~]$ rc-status
Runlevel: default
 agetty.tty2                                                                                       [  started 30 day(s) 12:16:02 (0) ]
 agetty.tty6                                                                                       [  started 30 day(s) 12:16:01 (0) ]
 agetty.tty3                                                                                       [  started 30 day(s) 12:16:01 (0) ]
 agetty.tty5                                                                                       [  started 30 day(s) 12:16:01 (0) ]
 dbus                                                                                              [  started 30 day(s) 12:16:03 (0) ]
 iptables                                                                                                                [  started  ]
 net.eth1                                                                                                                [  started  ]
 syslog-ng                                                                                         [  started 30 day(s) 12:06:39 (0) ]
 sshd                                                                                              [  started 30 day(s) 12:10:10 (0) ]
 mariadb                                                                                                                 [  started  ]
 cronie                                                                                            [  started 30 day(s) 12:16:01 (0) ]
 named                                                                                                                   [  started  ]
 net.eth0                                                                                                                [  started  ]
 agetty.tty4                                                                                       [  started 30 day(s) 12:16:01 (0) ]
 agetty.tty1                                                                                       [  started 30 day(s) 12:16:02 (0) ]
 mailman                                                                                                                 [  stopped  ]
 ntpd                                                                                              [  started 30 day(s) 12:15:58 (0) ]
Dynamic Runlevel: hotplugged
Dynamic Runlevel: needed/wanted
Dynamic Runlevel: manual

Re: Connecting MYSQL/MariaDB as an openrc service

Reply #1
The definitive solution is to somehow block the bots, perhaps anubis can help. May I also suggest you use mariadb-supervise-openrc instead of mariadb-openrc.

Re: Connecting MYSQL/MariaDB as an openrc service

Reply #2
https://www.tecmint.com/auto-restart-service-openrc/

This fellow shows how it is done with a cron script, which is not rocket science.  But I thought there was someone built into openrc that monitors child processes.

Re: Connecting MYSQL/MariaDB as an openrc service

Reply #3
The definitive solution is to somehow block the bots, perhaps anubis can help. May I also suggest you use mariadb-supervise-openrc instead of mariadb-openrc.
Anubis is a software program that adds a JavaScript-powered proof of work challenge to websites before users can access them, as a form of deterring the impacts of web scraping from bots. It has been adopted mainly by Git forges and free and open-source software projects.[3][4]

It was created by Xe Iaso in response to Amazon's web crawler overloading their Git server, as it did not respect the robots.txt exclusion protocol and would work around restrictions.[3]



I am going to look into this.  I have been /dev/null routing amazon and google cloud based bots.

I don't want to give the Webserver access to iptable, because I have seen modperl  solutions that can problem Apache and clobber abusive bots.  I can simply put an authorization password on the mailing list, but I don't want to.  There is a ton of historical postings and new articles on the list that I want to be searched by legit bots.

This is not a simple problem.  It takes a degree of intelligent coding but right now, I just want to restart mysql which seems to be the weak link.   Then I can get back to it over the weekend.

Re: Connecting MYSQL/MariaDB as an openrc service

Reply #4
Actually this is what is installed right now.  Things have slowly evolved.

Code: [Select]
world/mariadb 11.7.2-2 [installed: 11.7.2-3]

When I first migrated to artix, I wasn't happy with the mysql set up and I was moved on to mariabd.  I am friends with Monty.  So I hacked my own openrc scripts that called mysqladmin.   I've always had problems with the temp directory being created and had to make it by hand (I know I am stupid)

Now, I think things have caught up and changed, maybe

Code: [Select]
 #!/usr/bin/openrc-run
  2 # Distributed under the terms of the GNU General Public License v2
  3 echo "Hello"
  4 #extra_commands="checkconfig"
  5 #extra_started_commands="reload"
  6
  7 : ${MARIADB_CONFDIR:=/etc/mysql}
  8 : ${MARIADB_CONFIG:=${MARIADB_CONFDIR}/my.cnf}
  9 : ${MARIADB_PIDFILE:=/run/${SVCNAME}/${SVCNAME}.pid}
 10 : ${MARIADB_BINARY:=/usr/bin/mysqld}
 11 : ${MARIADB_OPTS:='user=mariadb'}
 12
 13         echo "PIDFILE ${MARIADB_PIDFILE}"
 14 depend() {
 15         use logger dns
 16         if [ "${rc_need+set}" = "set" ] ; then
 17                 : # Do nothing, the user has explicitly set rc_need
 18         else
 19                 local x warn_addr
 20                 for x in $(awk '/^ListenAddress/{ print $2 }' "$MARIADB_CONFIG" 2>/dev/null) ; do
 21                         case "${x}" in
 22                                 0.0.0.0|0.0.0.0:*) ;;
 23                                 ::|\[::\]*) ;;
 24                                 *) warn_addr="${warn_addr} ${x}" ;;
 25                         esac
 26                 done
 27                 if [ -n "${warn_addr}" ] ; then
 28                         need net
 29                         ewarn "You are binding an interface in ListenAddress statement in your mariadbd_config!"
 30                         ewarn "You must add rc_need=\"net.FOO\" to your /etc/conf.d/mariadbd"
 31                         ewarn "where FOO is the interface(s) providing the following address(es):"
 32                         ewarn "${warn_addr}"
 33                 fi
 34         fi
 35 }
 36
 37 checkconfig() {
 38         if [ ! -d /var/empty ] ; then
 39                 mkdir -p /var/empty || return 1
 40         fi
41
 42         if [ ! -e "${MARIADB_CONFIG}" ] ; then
 43                 eerror "You need an ${MARIADB_CONFIG} file to run mariadbd"
 44                 eerror "There is a sample file in /usr/share/doc/openmariadb"
 45                 return 1
 46         fi
 47
 48 }
 49
 50 start() {
 51         checkconfig || return 1
 52
 53         ebegin "Starting ${SVCNAME}"
 54         echo "PIDFILE ${MARIADB_PIDFILE}"
 55         echo "Command ${MARIADB_BINARY}  --${MARIADB_OPTS}"
 56         start-stop-daemon -vP --start --background "${MARIADB_BINARY}" --"${MARIADB_OPTS}"
 57    echo "${MARIADB_BINARY}"
 58         eend $?
 59 }
 60
 61 stop() {
 62         if [ "${RC_CMD}" = "restart" ] ; then
 63                 checkconfig || return 1
 64         fi
 65
 66         ebegin "Stopping ${SVCNAME}"
 67         start-stop-daemon --stop --exec "${MARIADB_BINARY}" \
 68             --pidfile "${MARIADB_PIDFILE}" --quiet
 69         eend $?
 70 }
 71
 72 reload() {
 73         checkconfig || return 1
 74         ebegin "Reloading ${SVCNAME}"
 75         start-stop-daemon --signal HUP \
 76             --exec "${MARIADB_BINARY}" --pidfile "${MARIADB_PIDFILE}"
 77         eend $?
 78 }



Re: Connecting MYSQL/MariaDB as an openrc service

Reply #5
https://www.tecmint.com/auto-restart-service-openrc/
This fellow shows how it is done with a cron script, which is not rocket science.
This solution is fine, but only needed with un-supervised scripts.
But I thought there was someone built into openrc that monitors child processes.
You may notice we provide 2 service scripts for mariadb. Most OpenRC scripts in our repos use the built-in service supervision (grep supervisor /etc/init.d/*). To work, daemons are launched in the foreground (or can't be supervised) and restarted if they crash or otherwise exit (the restart interval and attempts can also be controlled).