Configure Priority of Process Startup Linux

Problem

I had an application that is dependent on another, starting up at the same time as the other application. One potential solution was to add a wait/sleep timer to the startup script but this would slow up booting or add unnecessary wait time when the application needed to be restarted without server reboot.

Solution

Change the boot sequence of the application that is dependent on the other, making it start up much later than the rest. This is well explained here.

Ubuntu still uses init scripts and that are symlinked to different runlevels. Therefore:

  • Check the current boot sequence. This will give you a long list, you can filter it further to see the actual startup script you are looking for:
root@server:/home/user# ls /etc/rc*/
  • Remove the current scripts:
root@server:/home/user# update-rc.d -f source remove
Removing any system startup links for /etc/init.d/source ...
/etc/rc0.d/K20source
/etc/rc1.d/K20source
/etc/rc2.d/S20source
/etc/rc3.d/S20source
/etc/rc4.d/S20source
/etc/rc5.d/S20source
/etc/rc6.d/K20source
root@server:/home/user# update-rc.d source start 95 2 3 4 5 . stop 05 S 0 1 6 .
Adding system startup for /etc/init.d/source ...
/etc/rc0.d/K05source -> ../init.d/source
/etc/rc1.d/K05source -> ../init.d/source
/etc/rc6.d/K05source -> ../init.d/source
/etc/rcS.d/K05source -> ../init.d/source
/etc/rc2.d/S95source -> ../init.d/source
/etc/rc3.d/S95source -> ../init.d/source
/etc/rc4.d/S95source -> ../init.d/source
/etc/rc5.d/S95source -> ../init.d/source

Finally restart your server and see if this was successful.

Resources

What’s the connection between “/etc/init.d” and “/etc/rcX.d” directories in Linux?

How to Delay A Startup Service?

update-rc.d command warning

UbuntuBootupHowto

upstart Getting Started

Ubuntu’s Upstart event-based init daemon

custom service start at boot

UpstartHowtoUpstart Intro, Cookbook and Best Practises

update-rc.d ignoring my init script’s runlevels

MySQL Strip Time from Timestamp Columns

Problem

I needed a way to be able to only use the date part of a timestamp column in the WHERE clause without having to introduce another element such as formatting.

Solution 1

Solution was to use BETWEEN and then CAST the start and end dates as date as explained in this post.

For instance:

SELECT * FROM testdata WHERE current_date BETWEEN CAST(start_date as DATE) and CAST(end_date as DATE);

Side notes,

CURDATE() Returns the current date as a value in 'YYYY-MM-DD' or YYYYMMDD format, depending on whether the function is used in a string or numeric context.

Use IFNULL() to check if a returns a null and replace the null with something e.g blank:

IFNULL(personname.given_name,”) as GivenName

Update

For some reason the above did not work for me on MySQL 5.7.13. When I used the method above, data in the end date which was the last day of the month 2016-08-31 was not being included in the result. According to this explanation, it could be that BETWEEN isnt incuding the last / end date.

Solution 2

Solution was remove the CASTing and to instead concatenate the time i.e midnight 00:00:00 to the begin date and to the end date, add 23:59:59 so the query now becomes:

SELECT * FROM testdata WHERE current_date BETWEEN CONCAT(start_date' ' , '00:00:00') and CONCAT(end_date' ' , '00:00:00');

Update

Actually I noticed that Solution 1 works, the problem was the I was only CASTing the start_date and end_date parameters but not the actual database column current_date which is of data type datetime hence needs to be CAST as DATE so that the comparison works. Therefore, your query when CASTING should be:

 SELECT * FROM testdata WHERE CAST(current_date as DATE) BETWEEN CAST(start_date as DATE) and CAST(end_date as DATE); 

Resource:

SQL between dates including start and end dates

How to check if field is null or empty mysql?

How do I check if a column is empty or null in mysql

Working with NULL Values