SoBoredhttps://sobo.red
A Web Development and Consultancy CompanyThu, 06 Jun 2019 16:20:39 +0000en-US
hourly
1 https://wordpress.org/?v=5.2.3https://sobo.red/wp-content/uploads/2018/04/cropped-favicon-32x32-32x32.pngSoBoredhttps://sobo.red
3232152054799Node.js on IBM i: Easy Peasyhttps://sobo.red/2019/06/05/node-js-on-ibm-i-easy-peasy/
https://sobo.red/2019/06/05/node-js-on-ibm-i-easy-peasy/#respondWed, 05 Jun 2019 21:51:53 +0000https://sobo.red/?p=1379Node.js is on the rise in the IBM i ecosystem. People are taking notice, but there is still a misconception among some that Node.js and other open source software are difficult to install on IBM i. This article aims to show just how easy peasy it is to get Node.js installed, configured, and running fine…

]]>Node.js is on the rise in the IBM i ecosystem. People are taking notice, but there is still a misconception among some that Node.js and other open source software are difficult to install on IBM i. This article aims to show just how easy peasy it is to get Node.js installed, configured, and running fine on IBM i.

Prerequisite

This article assumes that you have yum installed and accessible on your IBM i instance. Please visit IBM i’s OpenSource Repository on BitBucket for installation instructions. Installing yum is quite simple. It’s just a few button clicks in Access Client Solutions.

Note: My BASH dotfiles will help create a friendlier command line interface when you SSH to your IBM i. Please take a look at my IBM i Dotfiles blog post to find out more.

Node.js Installation

yum install nodejs

When you run this command, you will be prompted with a Y/n question to confirm installation. Yes is default, so just press enter, or press y and enter if you want to be explicit.

It’s that easy. Node.js is now installed and ready to run on your IBM i. Now what do you do?

Hello World (Command Line)

Let’s make a really simple “Hello World” application with Node.js that will print Hello World to the console. A majority of people use Node.js to serve web applications, but keep in mind that Node.js at its core is a scripting language, and so it can be used to write simple command line scripts as well. That’s right System Administrators: you can write powerful command line scripts with Node.js, especially when combined with Db2 and IBM i Toolkit.

Note: For simplicity, I will be using command line interfaces throughout this tutorial. For example, using mkdir to create directories. Feel free to use your favorite GUI to accomplish the same tasks. For example, you could use Windows File Explorer to create the directory and VSCode to edit the file.

1. Create Node.js Project Directory

Run these commands to create the project directory and change directory to the project directory.

2. Create Script

3. Run Script

If you’re familiar with PHP, Python, and other scripting languages, this should look very familiar to you. It’s the same as php script.php and python script.py.

After running this command, you should see Hello World! printed in your console.

Hello World (Web Application)

Node.js is wonderful in that it has its own built in web server. No Apache, Nginx, etc. necessary. You define the web server in the application itself, run the application, and that’s all you need to do. There are plenty of options for serving your Node.js application in production, such as PM2, but we’ll save advanced Node.js web application topics for another time. For now, let’s get a simple Hello World web application running.

With just a few lines, we have defined a Node.js web application that will print Hello World! to the user.

2. Run app.js

Just as we did before, run the script from command line.

node app.js

This time, you should see Server started printed to your console.

Note: To stop the application, simply press ctrl and c together. This will stop any console program that you’re running at the time.

3. View Web Application

Visit the address we defined for our web application in a web browser by going to the URL http://<ibm-i-ip>:3000. You should plainly see Hello World! printed to the browser.

Summary

It’s time to peel back the misconceptions surrounding IBM i Open Source. With the delivery of Yum to the platform, we now have access to hundreds of open source software, all curated by the IBM i team. With a few keystrokes and approximately six lines of code, we have a Node.js web application up and running on IBM i.

Now that you know it’s so easy, go forth and produce beautiful Node.js applications. If you have any questions about Node.js, including help with mentoring, please reach out.

]]>https://sobo.red/2019/06/05/node-js-on-ibm-i-easy-peasy/feed/01379IBM i Dotfiles CLI RPM & SoBored RPM Repohttps://sobo.red/2018/12/28/ibm-i-dotfiles-cli-rpm-sobored-rpm-repo/
https://sobo.red/2018/12/28/ibm-i-dotfiles-cli-rpm-sobored-rpm-repo/#respondFri, 28 Dec 2018 21:12:46 +0000https://sobo.red/?p=1122Due to community feedback about the install process and usage of my IBM i Dotfiles, I have decided to create a command line interface (CLI) and an RPM to install the aforementioned CLI. Welcome the IBM i CLI RPM and SoBored RPM Repo. This was also an experiment for myself to learn how to build…

]]>Due to community feedback about the install process and usage of my IBM i Dotfiles, I have decided to create a command line interface (CLI) and an RPM to install the aforementioned CLI. Welcome the IBM i CLI RPM and SoBored RPM Repo.

This was also an experiment for myself to learn how to build RPMs and host an RPM repo. I have a feeling that I’ll be adding more RPMs over time.

Adding SoBored RPM Repo to yum

Adding the SoBored RPM Repo to yum is fairly simple. You just need to add a text file with a few lines of configuration.

Using your favorite text editor, create the file /QOpenSys/etc/yum/repos.d/sobored.repo with these contents:

]]>https://sobo.red/2018/12/28/ibm-i-dotfiles-cli-rpm-sobored-rpm-repo/feed/01122IBM i Dotfiles – How to Configure BASH on IBM ihttps://sobo.red/2018/06/08/ibm-i-dotfiles/
https://sobo.red/2018/06/08/ibm-i-dotfiles/#commentsFri, 08 Jun 2018 17:48:39 +0000https://sobo.red/?p=198Dotfiles – Hidden configuration files, usually found in one’s home directory, that are characterized by the dot at the beginning of the filename. Example: .profile If you’re like me and need to access many IBM i instances, copying your dotfile configurations and keeping them synced between instances can become cumbersome. Maybe you don’t need to…

Dotfiles – Hidden configuration files, usually found in one’s home directory, that are characterized by the dot at the beginning of the filename. Example: .profile

If you’re like me and need to access many IBM i instances, copying your dotfile configurations and keeping them synced between instances can become cumbersome. Maybe you don’t need to access multiple IBM i instances, but you have complex configurations and scripts, and would like to keep them version controlled simply for organization and backup. Whatever the reason, putting dotfiles in Github or a similar git repository host and having a script to set them up can be very handy! This article will describe how to setup a dotfile repository on Github.

Dotfiles as a Repository

It doesn’t make sense to version control the entire home directory, so how should we version control specific dotfiles? The answer is to have all the dotfiles that should be version controlled in a single project folder and symlink them to the proper path. Symlinking is the act of creating a symbolic link between one file and another file on the filesystem. As you change a file, the symlinked file will be updated and synced. Example:

In the above example, all the dotfiles we want to keep track of with Git are under the directory /home/user/Tools/dotfiles.

Symlinking all these files one by one can be as cumbersome as keeping track of these dotfiles without Git. So how do we automate the process of symlinking these files?

Script to Install Dotfiles

Keeping track of one’s dotfiles with Git is nothing new. In fact, there are dozens of examples. I picked one at random some years ago and cannot remember which script mine is based on. The bootstrap script that I copied and modified is 121 lines and can easily be modified further to fit anyone’s needs.

The way the Bootstrap script for my IBM i Dotfiles works by setting up the Git user on the system first, then it goes through the dotfiles repository and symlinks any file or folder appended with .symlink to the home directory of the user. It will even ask if you want to overwrite, backup, or skip each file before overwriting anything. Here’s how it looks:

An example of the dotfiles bootstrap running.

Getting Started Easily

The easiest way to get started would be to either use and contribute to my dotfiles, or fork my dotfiles and use them as your own. Here’s how one would clone my dotfiles and use them:

]]>https://sobo.red/2018/06/08/ibm-i-dotfiles/feed/1198Make Vi Work on IBM ihttps://sobo.red/2018/06/07/make-vi-work-on-ibm-i/
https://sobo.red/2018/06/07/make-vi-work-on-ibm-i/#respondThu, 07 Jun 2018 18:24:38 +0000https://sobo.red/?p=200Have you SSHed into your IBM i and tried to edit a file with vi only to be greeted with this? The default TERM for IBM i is currently set to xterm-256color. You can test this by typing echo $TERM: Solution To fix this, simply define your terminal to the proper value, usually just xterm.…

]]>https://sobo.red/2018/06/07/make-vi-work-on-ibm-i/feed/0200Yum for IBM ihttps://sobo.red/2018/05/30/yum-for-ibm-i/
https://sobo.red/2018/05/30/yum-for-ibm-i/#commentsWed, 30 May 2018 16:32:37 +0000https://sobo.red/?p=188The IBM i finally has Yum! So what is Yum? It’s a Package Manager for RPMs! So what are RPMs? Why should we start using Yum instead of 5733-OPS? I’ll cover these questions and more in this article. What is Yum? No more PTFs? Yum is an automatic updater and package installer/remover for rpm systems.…

]]>The IBM i finally has Yum! So what is Yum? It’s a Package Manager for RPMs! So what are RPMs? Why should we start using Yum instead of 5733-OPS? I’ll cover these questions and more in this article.

What is Yum? No more PTFs?

Yum is an automatic updater and package installer/remover for rpm systems. It automatically computes dependencies and figures out what things should occur to install packages. It makes it easier to maintain groups of machines without having to manually update each one using rpm. Yum has a plugin interface for adding simple features. Yum can also be used from other python programs via its module interface.

What does a package manager like Yum accomplish? It gives the user a convenient command line interface for installing software. In the IBM i world, that software would be software in the PASE environment.

The main feature of Yum is that it handles the software dependencies. Git has many dependencies, for example. Instead of thinking about having to remember to install libssl-dev and the other software that Git depends on, the Yum user can just run yum install git and be done.

What are RPMs?

RPM has a few definitions. In this context, we’re referring to packaged software that is bundled in the RPM format. These are files that use the .rpm extension. The RPM will install the software and its dependencies.

IBM has graciously setup a repository, a place to host IBM i PASE RPMs, for use with Yum. This repository is where Yum downloads and unpacks RPMs.

What about 5733-OPS?

IBM hasn’t officially said anything about the trajectory of 5733-OPS. Maintaining RPM software through Product installations and PTFs is unsustainable. This structure also doesn’t give System Administrators a convenient way to manage any missing dependencies.

IBM won’t be continuing with 5733-OPS, and it is my prediction that it will see it’s End of Life around the end of 2019, since the major deliverables thus far have an EOL at that time. I highly suggest people start using Yum as soon as possible to manage PASE software.

Getting Started with Yum

Jesse Gorzinski’s post does the best job describing how to install Yum. I was going to try to summarize it, but it’s short enough as it is.

Tips & Tricks

Yum and RPM are powerful tools that open up a world of software accessible via the command line. Instead of having to rely on a product, its options, and PTFs, one can now maintain software with a command line interface that is familiar to nearly any *nix user. Imagine being able to offer all the tools that fresh college students expect? BASH, yum, gcc, make, git, nodejs, nginx, all of these and more are available through the new RPM repository offered by IBM. Let’s go over a few tips and tricks that will help us tap into all these tools.

]]>https://sobo.red/2018/05/30/yum-for-ibm-i/feed/2188db2.sh: A Command Line Interface for Db2 on IBM ihttps://sobo.red/2017/10/08/db2-sh-a-command-line-interface-for-db2-on-ibm-i/
https://sobo.red/2017/10/08/db2-sh-a-command-line-interface-for-db2-on-ibm-i/#respondSun, 08 Oct 2017 00:00:00 +0000http://new.sobo.red/2017/10/08/db2-sh-a-command-line-interface-for-db2-on-ibm-i/Recently starting the IBM i BASH Tools repository has prompted me to think of some scripts that would be useful. One that I have wanted for quite awhile is a Command Line Interface (CLI) for DB2 on the IBM i. Calling DB2 from Command Line Calling DB2 from the command line is done in the…

]]>Recently starting the IBM i BASH Tools repository has prompted me to think of some scripts that would be useful. One that I have wanted for quite awhile is a Command Line Interface (CLI) for DB2 on the IBM i.

Calling DB2 from Command Line

Calling DB2 from the command line is done in the same way one would call any system command.

system -i "call QSYS/QZDFMDB2 parm('select * from sysibm.tables')"

Repeatedly Asking for User Input Until Exit

Figuring out how to read user input repeatedly until exit turned out to be a little more complex than I anticipated, but it’s still a simple while loop.

I wanted to allow the user to use the up and down arrows to cycle through the history of input. In order to do this, the input needs to be read in the while loop condition and history needs to be enabled for the input.

]]>https://sobo.red/2017/10/08/db2-sh-a-command-line-interface-for-db2-on-ibm-i/feed/051Writing Helpful BASH Scripts for IBM ihttps://sobo.red/2017/10/07/writing-helpful-bash-scripts-for-ibm-i/
https://sobo.red/2017/10/07/writing-helpful-bash-scripts-for-ibm-i/#respondSat, 07 Oct 2017 01:00:00 +0000http://new.sobo.red/2017/10/07/writing-helpful-bash-scripts-for-ibm-i/I feel like BASH is sometimes an overlooked tool these days. Writing scripts is simple, and a script can create efficient command line interfaces to achieve tasks that would normally take a lot longer. A great example of this is starting, stopping, and restarting Apache on the IBM i. For those of us not accustomed…

]]>I feel like BASH is sometimes an overlooked tool these days. Writing scripts is simple, and a script can create efficient command line interfaces to achieve tasks that would normally take a lot longer. A great example of this is starting, stopping, and restarting Apache on the IBM i. For those of us not accustomed to the green screen, there’s the HTTPAdmin Web GUI where the user can go to manage Apache servers. While HTTPAdmin is a nice tool, it can also be cumbersome, and it adds time to development when the developer has to leave the command line environment and use a GUI to restart a server.

In this article I’ll be discussing how to writeapachectl as a BASH script for the IBM i as an example of how writing BASH scripts can greatly simplify tasks.

Picking a Location for Scripts

Scripts can be placed anywhere as long as the directory they’re in is added toPATH. I suggest keeping custom scripts inside the user’s home directory and inside abin folder. So, for example, the place I would store all my custom scripts is/home/josh/bin.

To enable these scripts, add their bin to the PATH. In the.bashrc within the user’s home directory on the IBM i, just add something like this:

PATH=$PATH:~/bin

This appends the user’s home folder bin to PATH. Now any scripts within that directory will be usable no matter whatdirectory the user is in.

Writing apachectl.sh

Although one could just name the fileapachectl and use it as such, I like to keep.sh on my custom user bin scripts so it is easy to differentiate and doesn’t override any other scripts.

Create the folder and file in whatever manner is easiest. The command line way:

]]>https://sobo.red/2017/10/07/writing-helpful-bash-scripts-for-ibm-i/feed/052IBM i Open Source Toolshttps://sobo.red/2017/10/07/ibm-i-open-source-tools/
https://sobo.red/2017/10/07/ibm-i-open-source-tools/#respondSat, 07 Oct 2017 00:00:00 +0000http://new.sobo.red/2017/10/07/ibm-i-open-source-tools/IBM i Open Source Tools were originally installed via a complex process of installing packages from Perzl. I have described how to do this in past posts such as BASH on IBM i. While this was helpful in the past, it wasn’t officially supported by IBM. 5733-OPS is a new product from IBM that supports…

IBM i Open Source Tools were originally installed via a complex process of installing packages from Perzl. I have described how to do this in past posts such as BASH on IBM i. While this was helpful in the past, it wasn’t officially supported by IBM. 5733-OPS is a new product from IBM that supports Open Source Tools and can be installed on the IBM i.

5733-OPS

5733-OPS brings many open source tools to the IBM i and helps create a development environment that is familiar to a unix or linux developer. Tools such as BASH, rsync, curl, git, python, and much more are included. See the Open Source Technologies details page for more information on what is included with each option.

How to Install 5733-OPS

Kevin Adler has written a thorough and detailed article that explains exactly how to obtain 5733-OPS.

Tools

Below are quick references to the pros for some of the tools and how they development.

BASH

BASH is an enhanced version of BSH. It gives the developer some extra features. Anyone that has had to use the default shell on the IBM i has probably ran into the issue of the arrow keys and backspace virtually being unusable. Make a mistake in BSH and you might as well ctrl+c to start writing the command all over again. At least it gives you an ascii heart to make you feel a little better about the mistake.

BASH allows for arrow keys, which means up arrow for past commands. The developer will also be able to use tab completion. It even enables shortcuts likeesc + . to cycle through past parameters.

Git

Having a simple way of bringing Git to the IBM i is one of the most advantageous features of 5733-OPS. Git allows forsimple and widely accepted version control practices. Atlassian has a great tutorial that compares the different workflows of Git. GitHub also has a nice tutorial as an introduction to Git. Please keep in mind that Git and Github are not the same thing. GitHub is a cloud solution for hosting Git repositories.

Node

Bringing Node to the IBM i is helpful in many ways, and it’s not just for using Node as a web development language. Having access to Node packages such as Grunt, Gulp, and some others can be used as basic command line tools to automate tasks. Beforewhich was available on the IBM i, I could use the Node package which to find commands.

There are other tools that are included, but these are the ones I use the most. I’d love to hear what everyone else’s favorite parts of 5733-OPS are. I know it has made web development a much smoother process.

]]>https://sobo.red/2017/10/07/ibm-i-open-source-tools/feed/050Apigility RPC for IBM i Db2https://sobo.red/2017/05/15/apigility-rpc-for-ibm-i-db2/
https://sobo.red/2017/05/15/apigility-rpc-for-ibm-i-db2/#respondMon, 15 May 2017 00:00:00 +0000http://new.sobo.red/2017/05/15/apigility-rpc-for-ibm-i-db2/Apigility Setup This example assumes a setup similar to the one described in Installing and Using Apigility on IBM i. The example repository can be found on github. Create New RPC Create a new RPC through the Apigility Admin Interface like normal. This will generate a Factory and Controller for the RPC service. Once that…

Apigility Setup

Create New RPC

Create a new RPC through the Apigility Admin Interface like normal. This will generate a Factory and Controller for the RPC service. Once that is done, I like to quickly set the RPC HTTP Method to be POST.

Define Adapter in Controller

The controller needs our database adapter in order to call stored procedures. We’ll define that with a private variable and initialize it in the controller’s constructor like so:

There we are! We have a simple and repeatable way to call stored procedures with RPCs.

I made this article because I found it difficult to find an example where the developer was using the same database resource to call a stored procedure, as I haven’t found a way to bind parameters through the ZF2 IBM DB2 Statement object in a way that gives the output to the bound parameter. My solution was to get the statement resource and use it with the built in PHP DB2 functions.

]]>https://sobo.red/2017/05/15/apigility-rpc-for-ibm-i-db2/feed/054How to Add Filtering to Apigilityhttps://sobo.red/2017/05/05/how-to-add-filtering-to-apigility/
https://sobo.red/2017/05/05/how-to-add-filtering-to-apigility/#respondFri, 05 May 2017 00:00:00 +0000http://new.sobo.red/2017/05/05/how-to-add-filtering-to-apigility/Setting Up Apigility This guide will be using the same project setup during my Apigility Entity & Mapper Tips article. The related github repo has been updated with the new source in this article. Create a Filters Class I found the best way to stay organized was to create a type of Helper Class called <ServiceName>Filters.…

Create a Filters Class

I found the best way to stay organized was to create a type of Helper Class called <ServiceName>Filters. This allows all filtering where-clauses to be kept in one place and used as needed. A default one that I generate would look something like:

A basic Filters class, like above, should have adefaultFilter andidFilter. The default filter puts all fields together in a where clause withAND. The id filter simply adds a where clause for the ID, allowing one to select an individual row. For the sake of having a custom filter example, I’ve added the methodusersWithUsernameLike.

Use the Filters Class

Now that we have some filters to play around with, we need use the Filters Class in our Mapper. Anywhere you need a where clause, simply add it to Filters, and call it in the Mapper.

Here I’ve added it to the fetch all in order to have the ability to match data in columns

For the above to work, one needs to pass the$params array from the Resource to the Mapper fetchAll method.

It’s that simple, really. Just make sure to put any filter you want into thecollection_query_whitelist either through the Apigility Admin or the module config. Please see the github repo for the complete example.

Disclaimer

I’m not sure if this is the most graceful way of accomplishing this sort of filtering. I do agree that when queries get complex, one should make an RPC, but what about simple data querying? I don’t want to need to build an RPC just to sort data, for example. This is the solution I came up with after failing to find any good, in-depth examples on data filtering/querying with Apigility.