Disable service startup – SystemD

Problem

Needed to disable tomcat8 from starting on bootup

Solution

  • Check whether the service was marked to start on server boot up:

$ sudo systemctl is-enabled tomcat8.service 
tomcat8.service is not a native service, redirecting to systemd-sysv-install
Executing /lib/systemd/systemd-sysv-install is-enabled tomcat8
enabled

  • Disable to service from starting up and confirm it was done:
$ sudo systemctl disable tomcat8.service 
tomcat8.service is not a native service, redirecting to systemd-sysv-install
Executing /lib/systemd/systemd-sysv-install disable tomcat8
insserv: script tomcat7_test: service tomcat7 already provided!
insserv: warning: current start runlevel(s) (empty) of script `tomcat8' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of script `tomcat8' overrides LSB defaults (0 1 6).
insserv: script tomcat7_test: service tomcat7 already provided!

$ sudo systemctl is-enabled tomcat8.service 
tomcat8.service is not a native service, redirecting to systemd-sysv-install
Executing /lib/systemd/systemd-sysv-install is-enabled tomcat8
disabled

NOTE:

To stop/start a service using systemd, then:


$ sudo systemctl stop tomcat8.service
$ sudo systemctl start tomcat8.service

References

How to enable or disable services?

Advertisements

Reinstalling Wireless Drivers Linux Mint

Problem

I could not connect to the Wifi Network after removing the old kernel images on linux mint 17.

Looks like the wifi drivers were messed. I could see the following on stdout as the linux images were being uninstalled:


-------- Uninstall Beginning --------
Module: bcmwl
Version: 6.30.223.271+bdcom
Kernel: 4.4.0-67-generic (x86_64)

Solution

The solution was to reinstall the wifi drivers:


$ sudo apt-get remove bcmwl-kernel-source

$ sudo apt-get install bcmwl-kernel-source

Linux Mint17 – Removing Old Kernels

Problem

I was running out of space on my root partition. I had a number of old kernel headers and images that were taking up space.

Solution

Remove the old kernel and headers. Remember to be careful with this as you may remove the current.

  • First start with removing the kernel headers. Hitting the tab key after typing in the first portion of the command (sudo apt-get purge linux-headers-4.4.0-) should list the kernel headers and then you can start deleting from the old ones which are what I have in the curly brackets :

$ sudo apt-get purge linux-headers-4.4.0-{36,38,42,43,45,47}
[sudo] password for implementer: 
Reading package lists... Done
Building dependency tree 
Reading state information... Done
The following packages will be REMOVED:
 linux-headers-4.4.0-36* linux-headers-4.4.0-36-generic* linux-headers-4.4.0-38* linux-headers-4.4.0-38-generic* linux-headers-4.4.0-42*
 linux-headers-4.4.0-42-generic* linux-headers-4.4.0-43* linux-headers-4.4.0-43-generic* linux-headers-4.4.0-45* linux-headers-4.4.0-45-generic*
 linux-headers-4.4.0-47* linux-headers-4.4.0-47-generic*
0 upgraded, 0 newly installed, 12 to remove and 0 not upgraded.
After this operation, 466 MB disk space will be freed.
Do you want to continue? [Y/n]

  • Next uninstall the kernel images. Remember to uninstall the same images as the headers above. So in this would be:

$ sudo apt-get purge linux-image-4.4.0-{36,38,42,43,45,47}

Removing of the kernel images may take abit of time so be patient.

References

How to remove unused old kernel images on Ubuntu

Windows Time Sync

Problem

Had a situation where a Windows 2008 server and a Windows XP client’s times were not being synced despite being connected to the internet.

Solution

On the Windows 2008 I created a schedules task that would used to resync the server’s time.

I got this solution from this post Make Windows synchronize time more often

The link explains the process, I just have the following screenshots that tell the same story.

On the Windows XP client:

I edited the registry value as explained in this  Adjust Internet Time Synchronization article.

  •  Start the Registry Editor
  • Go to HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ W32Time \ TimeProviders \ NtpClient \
  • Double-click the SpecialPollInterval value, and change the Base of the Value data to Decimal
  • Now change the Value data to the time interval you desire, noting that the time is given in seconds (so for 1 day the value would be 86400, while the default (7 days) is 604800
  • Close the registry editor

Sources

Make Windows synchronize time more often

Adjust Internet Time Synchronization

Changing frequency of internet time synchronisation

How to Change the Time Synchronization Interval in Windows

How to configure an authoritative time server in Windows Server

How to synchronize the time with the Windows Time service in Windows XP

Linux Mint – Slow Boot Up

Problem

I noticed that my machine would take abit of time to boot. On bootup I pressed ESC to see what was happening, and noticed one of my partitions would take a couple of seconds to be scanned and would then throw a Connection Refused message.

I initially thought that my hard disk what dying but turns out there was a non existent volume in my /etc/fstab file that was trying to be loaded.

Solution

When I checked the systemd-journal logs, I saw the error below:

disk device has failed
disk device has failed

When I searced, I got a clue from this post that this was due to a mis-configured /etc/fstab.

The above swap volume with the UUID starting with “5f1d11af” was trying to be mounted but it doesn’t exist.

check /etc/fstab if volumes listed are correct
The pointer shows the incorrect volume

Confirm the correct existing volumes, using blkid:

check correct volumes using blkid
check correct volumes

Open the /etc/fstab file and comment out this volume (the one on the last line) as shown:

Comment out the wrong volume in /etc/fstab
Comment out the wrong volume in /etc/fstab

After commenting the above, then restart your machine.

References

dev-disk-by\x2duuid.device/start timed out.

GRUB2: Timed out waiting for device (was anciently a swap partition)

Manage Log Messages Under Systemd Using Journalctl

Copy Multiple lines from a logfile

Problem

I needed to capture an error / stack trace (list of the method calls that the application was in the middle of when an Exception was thrown – explanation from stackoverflow) from a log file to another file for attaching to a bug tracker

Solution

Used this answer from unix.stackexchange that proposed using a shell function that used sed that you could enter the from,to line numbers, log file and output file as shown

In the user’s .bashrc file add:

$ tail .bashrc 
#Printing section of a Line From A logFile
printLine () 
{ 
 sed -n -e "$1p" "$2"
}

Useage:

$ printLine 2000,2250 /var/log/tomcat/catalina.out > java_error.txt

Sources

Easy way to copy lines from one file to another

What is a stack trace, and how can I use it to debug my application errors?

Merge Video and Audio into One File

Problem

I downloaded a presentation where the video file and audio files were separate and I needed to merge the video and audio into one file.

Solution

Used the solution posted on super user on this link:

Merging video and audio, with audio re-encoding:

@whiscardz ~ $ ffmpeg -i video.mp4 -i audio.wav -c:v copy -c:a aac -strict experimental output.mp4

Copying the audio without re-encoding:

@whiscardz ~ $ ffmpeg -i video.mp4 -i audio.wav -c copy output.mkv

Sources

How to merge audio and video file in ffmpeg

Install Multiple Java versions and Setup Maven to Use one – Java 1.7

Problem

I was running Java 1.8 by default but I needed to build some modules that require Java 1.7

Solution

Check the default version of Java installed as well as the version of Java that maven is using:


implementer@whiscardz ~ $ java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

implementer@whiscardz ~ $ mvn -v
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=512m; support was removed in 8.0
Apache Maven 3.3.9
Maven home: /usr/share/maven
Java version: 1.8.0_131, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-78-generic", arch: "amd64", family: "unix" 
  • Install Java 1.7 as instructed in this link.
  • Create a .mavenrc file in your home directory and then add the JAVA_HOME of Java 1.7 In my case this would be JAVA_HOME=/usr/lib/jvm/java-7-oracle/jre
implementer@whiscardz ~ $ vim .mavenrc

JAVA_HOME=/usr/lib/jvm/java-7-oracle/jre
  • Optional, Run the maven file to assign the JAVA variable on the current terminal
implementer@whiscardz ~ $ source .mavenrc
  • Check version of Java Maven is now using:
implementer@whiscardz ~ $ mvn -version
Apache Maven 3.3.9
Maven home: /usr/share/maven
Java version: 1.7.0_80, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-oracle/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-78-generic", arch: "amd64", family: "unix"

References

Create .mavenrc file

How to change maven java home

Deleting a Partition on USB Flash Disk – Linux

Problem

I would always get the error below when trying to delete a partition on a USB flash disk:

Error deleting partition /dev/sdb2: Command-line `parted --script "/dev/sdb" "rm 2"' exited with non-zero exit status 1: Warning: The driver descriptor says the physical block size is 2048 bytes, but Linux says it is 512 bytes.
(udisks-error-quark, 0) 

Solution

According this answer on askubuntu, the above “was caused by a low-level device tool (like dd) writing blocks at the wrong size directly onto the device.

There are a number of solutions offered, like using dd. The safest, maybe using fdisk as described:

user@whiscardz ~ $ sudo fdisk /dev/sdb

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): p
Disk /dev/sdb: 14.9 GiB, 15955132416 bytes, 31162368 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x60dfafa1

Device Boot Start End Sectors Size Id Type
/dev/sdb1 * 0 2156351 2156352 1G 7 HPFS/NTFS/exFAT
/dev/sdb2 2135488 2140031 4544 2.2M ef EFI (FAT-12/16/32)

Command (m for help): d
Partition number (1,2, default 2): 1

Partition 1 has been deleted.

Command (m for help): d
Selected partition 2
Partition 2 has been deleted.

Command (m for help): p
Disk /dev/sdb: 14.9 GiB, 15955132416 bytes, 31162368 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x60dfafa1

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

References

Unable to delete USB Drive partitions (Block size error)