Setup Systemd Service on Ubuntu 16.04

$ sudo vim /etc/systemd/system/myservice.service
[Unit]
Description=Run the service

[Service]
User=ubuntu
# change the workspace
WorkingDirectory=/usr/local/src

#path to executable. 
#executable is a bash script which calls jar file
ExecStart=/usr/local/src/somescript

SuccessExitStatus=143
TimeoutStopSec=10
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
$ sudo vim /usr/local/src/somescript
#!/bin/sh

java -jar /some/file.jar
sudo systemctl daemon-reload
sudo systemctl enable myservice.service
sudo systemctl start myservice
sudo systemctl status myservice

 

Install MySQL on Ubuntu And Skip the Password Prompt

When you install mysql on Ubuntu (I use 16.04), it requires you to fill the admin password for the first time before finishing the installation. This prompt will wait the user input until you fill the password.

This trick is very helpful if you want to install mysql in Dockerfile, and skipping the password prompt:

$ export DEBIAN_FRONTEND=noninteractive
$ sudo -E apt-get -q -y install mysql-server

Setup Simple Ruby on Rails App On Ubuntu 16.04 From Scratch

Rails is one of the most popular ruby framework out there. And now, I want to try to run the simple app on Ubuntu 16.04 machine. it’s for testing purpose.

First, update the system and install essential dependencies:

$ sudo apt-get update
$ sudo apt-get build-essential curl sudo vim

Install nodejs:

$ curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
$ apt-get install nodejs

Create a dedicated user for the app, for example, ubuntu user. And this also make the ubuntu user with sudo privilege and run the command without password. Which is useful to run command that needs sudo privilege in the next steps.

$ useradd ubuntu -m
$ echo 'ubuntu ALL=(root) NOPASSWD: ALL' >> /etc/sudoers

swith to ubuntu user and install GPG keys for install rvm:

$ su - ubuntu
ubuntu~$ gpg --keyserver hkp://keys.gnupg.net \ --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 \ 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

Download and install rvm:

ubuntu~$ \curl -sSL https://get.rvm.io | bash -s stable

Install ruby interpreter with version 2.5.1, you might wanna change it with your preferable version:

ubuntu~$ source ~/.rvm/scripts/rvm
ubuntu~$ rvm install 2.5.1
ubuntu~$ rvm use 2.5.1 --default

Install rails with gem, and create new app without writing the Gemfile. Why? because everytime I create new app, I ended up facing errors with dependencies in Gemfile. So, it safe to setup new app without the Gemfile, we’ll create it manually later.

ubuntu~$ gem install rails
ubuntu~$ rails new app --skip-gemfile

Create the Gemfile:

ubuntu~$ touch ~/app/Gemfile
ubuntu~$ vim ~/app/Gemfile

Gemfile, fill these dependencies below into the file, save and exit:

source 'https://rubygems.org'
gem 'rails', '~> 5.2.1'
gem 'bootsnap', '~> 1.3.2'
gem 'tzinfo-data', '~> 1.2018.5'
gem 'listen', '~> 3.1.5'
gem 'sqlite3'

Now, install all the gems with bundle:

ubuntu~$ cd ~/app
ubuntu app~$ bundle install

Try run the rails:

ubuntu app~$ rails server -b 0.0.0.0

 

Linux machine Failed to hibernate, “system via logind: Sleep verb not supported”

So after using fedora 28 for a while. I tried to configure my power management using xfce power management system.

Looking at these power management settings, are very simple explanation. I set my machine to hibernate or sleep mode when inactive for 16 minutes.

Saved the settings. then I closed the laptop lid, so it started to be inactive until the next 16 minutes. Supposed to be hibernated.

But it did not, instead…

I opened up my laptop, and there is this error:

System via logind: Sleep verb not supported...

It turns out that the states of the machine are not available for hibernate. You can check them out with this simple command:

$ sudo cat /sys/power/disk
[disabled]

Now, that’s a problem. The machine cannot be hibernate, nor suspend if the output is disabled.

The solution is quite simple. Reboot the machine, then enter BIOS mode. This one is requires the BIOS setting, secure boot to be disabled.

Secure boot setting in BIOS

Switch the secure boot in BIOS setting to Disabled. Then reboot the system.

After I rebooted the system with secure boot disabled, the output of /sys/power/disk now is contains more than one, including suspend/hibernate.

$ cat /sys/power/disk 
[platform] shutdown reboot suspend test_resume

The machine’s power management system now can run the machine with hibernate mode.

Setup ftp that works with local user with vsftpd on ubuntu

This is the step-by-step installation of vsftpd that actually works. If you have website that runs wordpress, you might want to enable this to be able install/update your wordpress plugin.

Install vsftpd and start the service:

$ sudo apt-get install vsftpd -y
$ sudo systemctl start vsftpd.service
$ sudo systemctl enable vsftpd.service

Open vsftpd.conf file, and make sure these lines below are enabled:

$ sudo vim /etc/vsftpd.conf
...
...
local_enable=YES
chroot_local_user=YES
allow_writeable_chroot=YES
write_enable=yes

Restart the service:

$ sudo systemctl restart vsftpd.service

Create local user:

$ sudo useradd ftpuser -s /bin/bash -md /srv/ftpuser
$ sudo passwd ftpuser

Make sure your user format is looks like this:

$ cat /etc/passwd
ftpuser:x:1000:1000::/srv/ftpuser:/bin/bash

Test your ftp user out:

$ ftp example.com