DoYouEvenHTML
DoYouEvenHTML

Reputation: 33

Insert MySQL row on server start

I have a debian based private server and am wondering, what's the best way to insert a row to database when the server boots. I am trying to show it in the notifications on my PHP-based monitoring site.

I currently am thinking of a simple script(have not decided on the language yet) running just once on start-up and terminating afterwards. Are there any better solutions out there?

EDIT: I used scripts in init.d folder to be run on different runlevels. Currently, the only one I have gotten to work, is the bash script that inserts a row about the server booting up. This is under rcS.d/.

The problem is, that when I use the same method to run a script while the runlevels are 0 or 6, for example, the script is never run. I think it might be a priority issue. Look at the picture below (The priority is the same as the kill priorities for apache, etc...). Are the scripts run in alphabetical order or could I bump all priorities up by one somehow?

The priority is the same as the kill priorities for apache, etc...

Upvotes: 1

Views: 143

Answers (1)

Trent Lloyd
Trent Lloyd

Reputation: 1892

MySQL has a built-in option to execute an SQL file on start, which sounds like what you want: https://dev.mysql.com/doc/refman/5.6/en/server-options.html#option_mysqld_init-file

The other thing you can do is just review the server uptime periodically and either compare it to a known value or just check that it recently rebooted.

Your most recent idea to use a startup script also has merit, the problem is you need to ensure it runs after mysql has started. S01 is a priority/order, so you want to put in a number bigger than MySQL.

Depending on what distribution you are using, that number may not apply though if the system is using upstart or systemd and it's a big more complex.

The crontab @reboot suggestion is also a good one.

Upvotes: 0

Related Questions